Skip to main content
Glama
mackenly

MCP Fathom Analytics

by mackenly

list-events

Retrieve all events for a Fathom Analytics site, automatically handling pagination to simplify data access.

Instructions

List all events for a Fathom Analytics site (automatically handles pagination)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
site_idYesID of the site to retrieve events for
limitNoOptional limit on the number of events to return

Implementation Reference

  • The handler function for the 'list-events' tool. It fetches all events for a given Fathom Analytics site_id (with optional limit), handles pagination internally via fathomClient.api.getAllEvents, formats the events as text, and returns them in the MCP response format. Includes error handling.
    async ({ site_id, limit }) => {
        try {
            const events = await fathomClient.api.getAllEvents(site_id, limit);
            
            if (events.length === 0) {
                return {
                    content: [
                        {
                            type: "text",
                            text: `No events found for site ${site_id}.`,
                        },
                    ],
                };
            }
    
            const eventsText = events.map(event => 
                `ID: ${event.id}\nName: ${event.name}\nCreated: ${event.created_at}\n`
            ).join("\n---\n\n");
            
            return {
                content: [
                    {
                        type: "text",
                        text: `All events for site ${site_id} (${events.length}):\n\n${eventsText}`,
                    },
                ],
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Failed to retrieve events: ${error instanceof FathomApiError ? `${error.status}: ${error.error}` : String(error)}`,
                    },
                ],
            };
        }
    },
  • Input schema for the 'list-events' tool using Zod: requires site_id (string), optional limit (positive number). Descriptions provided.
    {
        site_id: z.string().describe("ID of the site to retrieve events for"),
        limit: z.number().positive().optional().describe("Optional limit on the number of events to return")
    },
  • Registration of the 'list-events' tool via server.tool() call inside the registerEventsTool function, including name, description, schema, and handler.
    server.tool(
        "list-events",
        "List all events for a Fathom Analytics site (automatically handles pagination)",
        {
            site_id: z.string().describe("ID of the site to retrieve events for"),
            limit: z.number().positive().optional().describe("Optional limit on the number of events to return")
        },
        async ({ site_id, limit }) => {
            try {
                const events = await fathomClient.api.getAllEvents(site_id, limit);
                
                if (events.length === 0) {
                    return {
                        content: [
                            {
                                type: "text",
                                text: `No events found for site ${site_id}.`,
                            },
                        ],
                    };
                }
    
                const eventsText = events.map(event => 
                    `ID: ${event.id}\nName: ${event.name}\nCreated: ${event.created_at}\n`
                ).join("\n---\n\n");
                
                return {
                    content: [
                        {
                            type: "text",
                            text: `All events for site ${site_id} (${events.length}):\n\n${eventsText}`,
                        },
                    ],
                };
            } catch (error) {
                return {
                    content: [
                        {
                            type: "text",
                            text: `Failed to retrieve events: ${error instanceof FathomApiError ? `${error.status}: ${error.error}` : String(error)}`,
                        },
                    ],
                };
            }
        },
    );

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/mackenly/mcp-fathom-analytics'

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