get_user_presences
Retrieve user presence data within a specified date range, aggregating daily and calculating totals for time tracking and project management insights.
Instructions
Get user presences within a date range with daily aggregation and total calculations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endDate | Yes | End date in ISO 8601 format (YYYY-MM-DD) | |
| startDate | Yes | Start date in ISO 8601 format (YYYY-MM-DD) |
Implementation Reference
- src/tools/userPresencesTools.ts:28-58 (handler)The main handler function for the get_user_presences tool. Validates input dates, fetches presences from Moco API, aggregates them daily, formats summary with statistics, and handles errors.handler: async (params: z.infer<typeof GetUserPresencesSchema>): Promise<string> => { const { startDate, endDate } = 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 presences = await apiService.getUserPresences(startDate, endDate); if (presences.length === 0) { return createEmptyResultMessage({ type: 'presences', startDate, endDate }); } const summary = aggregatePresences(presences, startDate, endDate); return formatPresencesSummary(summary); } catch (error) { return `Error retrieving presences: ${error instanceof Error ? error.message : 'Unknown error'}`; } }
- Zod schema defining input parameters for the get_user_presences tool: startDate and endDate as ISO date strings.// Schema for get_user_presences tool const GetUserPresencesSchema = 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)') });
- src/index.ts:34-42 (registration)Registration of the getUserPresencesTool 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/index.ts:24-24 (registration)Import statement bringing the getUserPresencesTool into the main index file for registration.import { getUserPresencesTool } from './tools/userPresencesTools.js';
- src/services/mocoApi.ts:360-365 (helper)API service method that fetches user presences from MoCo API endpoint '/users/presences' with date range parameters, handling pagination.async getUserPresences(startDate: string, endDate: string): Promise<UserPresence[]> { return this.fetchAllPages<UserPresence>('/users/presences', { from: startDate, to: endDate }); }