get_content_site_hits
Retrieve daily visitor hit counts for a content site to track performance and analyze traffic patterns on the Kapiti CMS platform.
Instructions
Get daily hits for a content site
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contentSiteId | Yes | Content site ID |
Implementation Reference
- src/index.ts:1927-1949 (handler)The handler function that performs the core logic: sends a GET request to the Headlesshost API endpoint `/tools/content-sites/${contentSiteId}/hits` to retrieve daily hits data, formats the successful response as JSON text, and returns an error response using the shared handleApiError helper if the API call fails.async ({ contentSiteId }) => { try { const response: AxiosResponse<ApiResponse<any[]>> = await apiClient.get(`/tools/content-sites/${contentSiteId}/hits`); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: handleApiError(error), }, ], isError: true, }; }
- src/index.ts:1923-1925 (schema)Input schema definition using Zod: requires a 'contentSiteId' string parameter describing the ID of the content site for which to fetch hits.inputSchema: { contentSiteId: z.string().describe("Content site ID"), },
- src/index.ts:1918-1951 (registration)Tool registration call to McpServer.registerTool with the name 'get_content_site_hits', metadata (title, description), input schema, and handler function.server.registerTool( "get_content_site_hits", { title: "Get ContentSite Hits", description: "Get daily hits for a content site", inputSchema: { contentSiteId: z.string().describe("Content site ID"), }, }, async ({ contentSiteId }) => { try { const response: AxiosResponse<ApiResponse<any[]>> = await apiClient.get(`/tools/content-sites/${contentSiteId}/hits`); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: handleApiError(error), }, ], isError: true, }; } } );
- src/index.ts:158-166 (helper)Shared helper function used by the tool handler (and many others) to format API error responses into a user-friendly string message.function handleApiError(error: any): string { if (error.response) { return `API Error ${error.response.status}: ${error.response.data?.message || error.response.statusText}`; } else if (error.request) { return "Network Error: Unable to reach API server"; } else { return `Error: ${error.message}`; } }