getUserTimeEntries
Retrieve and list time entries for a specific user on Clockify MCP by specifying user ID and optional date range (ISO8601). Simplify time tracking and management.
Instructions
List time entries for a specified user. Optional: start, end (ISO8601).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | End date (ISO8601, optional) | |
| start | No | Start date (ISO8601, optional) | |
| userId | Yes | User ID |
Implementation Reference
- src/handlers.ts:240-265 (handler)The main execution logic for the 'getUserTimeEntries' tool. Fetches time entries for a given userId from the Clockify API, supporting optional start and end date filters.case "getUserTimeEntries": { const { userId: targetUserId, start, end, } = request.params.arguments || {}; if (!targetUserId) { throw new Error("userId is required"); } let url = `/workspaces/${workspaceId}/user/${targetUserId}/time-entries`; const params = []; if (typeof start === "string" && start) params.push(`start=${encodeURIComponent(start)}`); if (typeof end === "string" && end) params.push(`end=${encodeURIComponent(end)}`); if (params.length) url += `?${params.join("&")}`; const entries = await clockifyFetch(url); return { content: [ { type: "text", text: JSON.stringify(entries, null, 2), }, ], }; }
- src/handlers.ts:84-103 (schema)Input schema for the 'getUserTimeEntries' tool, defining parameters: required userId and optional start/end dates.{ name: "getUserTimeEntries", description: "List time entries for a specified user. Optional: start, end (ISO8601).", inputSchema: { type: "object", properties: { userId: { type: "string", description: "User ID" }, start: { type: "string", description: "Start date (ISO8601, optional)", }, end: { type: "string", description: "End date (ISO8601, optional)", }, }, required: ["userId"], }, },
- src/index.ts:43-43 (registration)Registers the listToolsHandler, which includes the schema and description for the 'getUserTimeEntries' tool in the MCP tools list.server.setRequestHandler(ListToolsRequestSchema, listToolsHandler);
- src/index.ts:49-49 (registration)Registers the callToolHandler, which contains the switch case to execute the 'getUserTimeEntries' tool.server.setRequestHandler(CallToolRequestSchema, callToolHandler);
- src/handlers.ts:13-32 (helper)Utility function to perform authenticated fetches to the Clockify API, directly used by the getUserTimeEntries handler.async function clockifyFetch(endpoint: string, options: RequestInit = {}) { const apiKey = getApiKey(); const baseUrl = "https://api.clockify.me/api/v1"; const url = endpoint.startsWith("http") ? endpoint : `${baseUrl}${endpoint}`; const headers = { "X-Api-Key": apiKey, "Content-Type": "application/json", ...(options.headers || {}), }; const response = await fetch(url, { ...options, headers }); if (!response.ok) { const text = await response.text(); console.error( `[Error] Clockify API ${url} failed: ${response.status} ${text}`, ); throw new Error(`Clockify API error: ${response.status} ${text}`); } return response.json(); }