get_activities
Retrieve and summarize activities by date, project, and task within a specified range. Filter results by project ID to focus on specific work data in MoCo MCP Server.
Instructions
Get all activities within a date range with automatic summation by date, project, and task. Optionally filter by project ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | End date in ISO 8601 format (YYYY-MM-DD) | |
| projectId | No | Optional project ID to filter activities for a specific project | |
| startDate | Yes | Start date in ISO 8601 format (YYYY-MM-DD) |
Implementation Reference
- src/tools/activitiesTools.ts:31-67 (handler)The main handler for the get_activities tool. Fetches activities via MocoApiService, aggregates them by date, project, and task using helper functions, handles validation and errors, and returns a formatted summary string.export const getActivitiesTool = { name: 'get_activities', description: 'Get all activities within a date range with automatic summation by date, project, and task. Optionally filter by project ID.', inputSchema: zodToJsonSchema(GetActivitiesSchema), handler: async (params: z.infer<typeof GetActivitiesSchema>): Promise<string> => { const { startDate, endDate, projectId } = params; // Validate date format and range if (!validateDateRange(startDate, endDate)) { return createValidationErrorMessage({ field: 'dateRange', value: `${startDate} to ${endDate}`, reason: 'invalid_date_range' }); } try { const apiService = new MocoApiService(); const activities = await apiService.getActivities(startDate, endDate, projectId); if (activities.length === 0) { return createEmptyResultMessage({ type: 'activities', startDate, endDate, projectId }); } const summary = aggregateActivities(activities, startDate, endDate); return formatActivitiesSummary(summary, projectId); } catch (error) { return `Error retrieving activities: ${error instanceof Error ? error.message : 'Unknown error'}`; } } };
- src/tools/activitiesTools.ts:21-25 (schema)Zod schema defining input parameters for the get_activities tool: required startDate and endDate as strings, optional positive projectId number.const GetActivitiesSchema = z.object({ startDate: z.string().describe('Start date in ISO 8601 format (YYYY-MM-DD)'), endDate: z.string().describe('End date in ISO 8601 format (YYYY-MM-DD)'), projectId: z.number().positive().optional().describe('Optional project ID to filter activities for a specific project') });
- src/index.ts:34-42 (registration)Registration of the getActivitiesTool in the AVAILABLE_TOOLS array, which is used by the MCP server for tool listing and execution dispatching.const AVAILABLE_TOOLS = [ getActivitiesTool, getUserProjectsTool, getUserProjectTasksTool, getUserHolidaysTool, getUserPresencesTool, getUserSickDaysTool, getPublicHolidaysTool ];
- src/services/mocoApi.ts:143-154 (helper)Helper method in MocoApiService that fetches raw activities data from the MoCo API endpoint '/activities' with date range and optional project filter, handling pagination.async getActivities(startDate: string, endDate: string, projectId?: number): Promise<Activity[]> { const params: Record<string, string | number> = { from: startDate, to: endDate }; if (projectId) { params.project_id = projectId; } return this.fetchAllPages<Activity>('/activities', params); }