listProjects
Retrieve all projects for the authenticated user using the tool integrated with Clockify MCP, enabling efficient project management and organization.
Instructions
List all projects for the authenticated user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/handlers.ts:169-181 (handler)The handler for the 'listProjects' tool. It fetches the list of projects from the Clockify API using the user's active workspace ID and returns them as a JSON-formatted text response.case "listProjects": { const projects = await clockifyFetch( `/workspaces/${workspaceId}/projects`, ); return { content: [ { type: "text", text: JSON.stringify(projects, null, 2), }, ], }; }
- src/handlers.ts:38-42 (schema)Tool schema definition including name, description, and empty input schema (no parameters required).{ name: "listProjects", description: "List all projects for the authenticated user.", inputSchema: { type: "object", properties: {}, required: [] }, },
- src/index.ts:43-43 (registration)Registers the listToolsHandler which exposes the listProjects tool among others.server.setRequestHandler(ListToolsRequestSchema, listToolsHandler);
- src/handlers.ts:13-32 (helper)Helper function used by the listProjects handler to make authenticated API calls to Clockify.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(); }
- src/handlers.ts:4-10 (helper)Helper function to retrieve the Clockify API key from environment, used indirectly by listProjects via clockifyFetch.function getApiKey(): string { const apiKey = process.env.CLOCKIFY_API_KEY; if (!apiKey) { throw new Error("CLOCKIFY_API_KEY is not set in MCP config."); } return apiKey; }