get_user_projects
Retrieve all projects assigned to the current user or filter by name/description using a search query. Designed for use with the MoCo MCP Server to access project management data.
Instructions
Get all projects assigned to the current user or search within assigned projects by name/description. If no query is provided, returns all assigned projects.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Optional search query to find projects by name or description (case-insensitive) |
Implementation Reference
- src/tools/userProjectsTools.ts:30-61 (handler)The handler function for the get_user_projects tool. It fetches user-assigned projects (or searches by query) using MocoApiService, handles empty results and errors, and formats the output using helper functions.handler: async (params: z.infer<typeof GetProjectsSchema>): Promise<string> => { const { query } = params; try { const apiService = new MocoApiService(); // If query is provided and not empty, search; otherwise list all if (query && query.trim()) { const projects = await apiService.searchProjects(query.trim()); if (projects.length === 0) { return createEmptyResultMessage({ type: 'projects', query: query.trim() }); } return formatProjectsSearchResults(projects, query.trim()); } else { const projects = await apiService.getProjects(); if (projects.length === 0) { return createEmptyResultMessage({ type: 'projects' }); } return formatProjectsList(projects); } } catch (error) { return `Error retrieving projects: ${error instanceof Error ? error.message : 'Unknown error'}`; } }
- src/tools/userProjectsTools.ts:13-15 (schema)Zod schema defining the input for the get_user_projects tool: an optional query string for searching projects.const GetProjectsSchema = z.object({ query: z.string().optional().describe('Optional search query to find projects by name or description (case-insensitive)') });
- src/index.ts:34-42 (registration)Registration of the getUserProjectsTool in the AVAILABLE_TOOLS array, which is used by the MCP server to list and dispatch tool calls.const AVAILABLE_TOOLS = [ getActivitiesTool, getUserProjectsTool, getUserProjectTasksTool, getUserHolidaysTool, getUserPresencesTool, getUserSickDaysTool, getPublicHolidaysTool ];
- Helper function to format the list of all assigned projects into a readable string format used by the handler.function formatProjectsList(projects: Project[]): string { const lines: string[] = []; lines.push(`Assigned projects (${projects.length}):\n`); projects.forEach(project => { lines.push(`ID: ${project.id}`); lines.push(`Name: ${project.name}`); if (project.description) { lines.push(`Description: ${project.description}`); } lines.push(`Status: ${project.active ? 'Active' : 'Inactive'}`); if (project.customer) { lines.push(`Customer: ${project.customer.name}`); } if (project.leader) { lines.push(`Leader: ${project.leader.firstname} ${project.leader.lastname}`); } if (project.budget) { lines.push(`Budget: ${project.budget} ${project.currency}`); } lines.push(''); // Empty line between projects }); return lines.join('\\n'); }
- Helper function to format search results for projects, highlighting the search query in names and descriptions.function formatProjectsSearchResults(projects: Project[], query: string): string { const lines: string[] = []; lines.push(`Search results for "${query}" (${projects.length} found):\n`); projects.forEach(project => { lines.push(`ID: ${project.id}`); lines.push(`Name: ${highlightSearchTerm(project.name, query)}`); if (project.description) { lines.push(`Description: ${highlightSearchTerm(project.description, query)}`); } lines.push(`Status: ${project.active ? 'Active' : 'Inactive'}`); if (project.customer) { lines.push(`Customer: ${project.customer.name}`); } lines.push(''); // Empty line between projects }); return lines.join('\\n'); }