Skip to main content
Glama

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
NameRequiredDescriptionDefault
contentSiteIdYesContent site ID

Implementation Reference

  • 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,
        };
      }
  • 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,
          };
        }
      }
    );
  • 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}`;
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Headlesshost/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server