Skip to main content
Glama
mackenly

MCP Fathom Analytics

by mackenly

get-aggregation

Retrieve aggregated analytics data from Fathom Analytics to analyze website performance, track user behavior, and generate custom reports with flexible filtering and grouping options.

Instructions

Get aggregated analytics data from Fathom

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityYesThe entity to aggregate (pageview or event)
entity_idYesID of the entity (site ID or event ID)
aggregatesYesComma-separated list of aggregates to include (visits,uniques,pageviews,avg_duration,bounce_rate,conversions,unique_conversions,value)
date_groupingNoOptional date grouping
field_groupingNoComma-separated fields to group by (e.g., hostname,pathname)
sort_byNoField to sort by (e.g., pageviews:desc)
timezoneNoTimezone for date calculations (default: UTC)
date_fromYesStart date (e.g., 2025-01-01 00:00:00 or 2025-01-01)
date_toYesEnd date (e.g., 2025-12-31 23:59:59 or 2025-12-31)
limitNoLimit on number of results
filtersNoArray of filter objects

Implementation Reference

  • The handler function that executes the get-aggregation tool: calls Fathom API for aggregation data, formats results into readable text, handles empty data and errors.
    async (params: AggregationParams) => {
        try {
            const aggregationData = await fathomClient.api.reports.aggregation(params);
            
            // Check if data exists and is a proper array
            if (!aggregationData || !Array.isArray(aggregationData)) {
                return {
                    content: [
                        {
                            type: "text",
                            text: "No aggregation data found for the given parameters.",
                        },
                    ],
                };
            }
            
            if (aggregationData.length === 0) {
                return {
                    content: [
                        {
                            type: "text",
                            text: "No aggregation data found for the given parameters.",
                        },
                    ],
                };
            }
    
            // Format the aggregation results in a readable way
            let resultText = `Aggregation Results (${aggregationData.length} entries):\n\n`;
            
            // Get all possible keys from all data entries
            const allKeys = new Set<string>();
            aggregationData.forEach(item => {
                if (item) {
                    Object.keys(item).forEach(key => allKeys.add(key));
                }
            });
            
            // Format each data entry
            aggregationData.forEach((item, index) => {
                if (!item) return;
                resultText += `Entry ${index + 1}:\n`;
                
                Array.from(allKeys).sort().forEach(key => {
                    if (item[key] !== undefined) {
                        resultText += `${key}: ${item[key]}\n`;
                    }
                });
                
                resultText += "---\n\n";
            });
            
            return {
                content: [
                    {
                        type: "text",
                        text: resultText,
                    },
                ],
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Failed to retrieve aggregation data: ${error instanceof FathomApiError ? `${error.status}: ${error.message}` : String(error)}`,
                    },
                ],
            };
        }
    },
  • Zod schema defining parameters for the get-aggregation tool, including entity, aggregates, dates, filters, etc.
    {
        entity: z.enum(["pageview", "event"]).describe("The entity to aggregate (pageview or event)"),
        entity_id: z.string().describe("ID of the entity (site ID or event ID)"),
        aggregates: z.string().describe("Comma-separated list of aggregates to include (visits,uniques,pageviews,avg_duration,bounce_rate,conversions,unique_conversions,value)"),
        date_grouping: z.enum(["hour", "day", "month", "year"]).optional().describe("Optional date grouping"),
        field_grouping: z.string().optional().describe("Comma-separated fields to group by (e.g., hostname,pathname)"),
        sort_by: z.string().optional().describe("Field to sort by (e.g., pageviews:desc)"),
        timezone: z.string().optional().describe("Timezone for date calculations (default: UTC)"),
        date_from: z.string().describe("Start date (e.g., 2025-01-01 00:00:00 or 2025-01-01)"),
        date_to: z.string().describe("End date (e.g., 2025-12-31 23:59:59 or 2025-12-31)"),
        limit: z.number().positive().optional().describe("Limit on number of results"),
        filters: z.array(
            z.object({
                property: z.string(),
                operator: z.enum(["is", "is not", "is like", "is not like"]),
                value: z.string(),
            })
        ).optional().describe("Array of filter objects"),
    },
  • Registration function that sets up the get-aggregation tool on the MCP server using server.tool().
    export function registerAggregationTool(server: McpServer, fathomClient: FathomApi): void {
        server.tool(
            "get-aggregation",
            "Get aggregated analytics data from Fathom",
            {
                entity: z.enum(["pageview", "event"]).describe("The entity to aggregate (pageview or event)"),
                entity_id: z.string().describe("ID of the entity (site ID or event ID)"),
                aggregates: z.string().describe("Comma-separated list of aggregates to include (visits,uniques,pageviews,avg_duration,bounce_rate,conversions,unique_conversions,value)"),
                date_grouping: z.enum(["hour", "day", "month", "year"]).optional().describe("Optional date grouping"),
                field_grouping: z.string().optional().describe("Comma-separated fields to group by (e.g., hostname,pathname)"),
                sort_by: z.string().optional().describe("Field to sort by (e.g., pageviews:desc)"),
                timezone: z.string().optional().describe("Timezone for date calculations (default: UTC)"),
                date_from: z.string().describe("Start date (e.g., 2025-01-01 00:00:00 or 2025-01-01)"),
                date_to: z.string().describe("End date (e.g., 2025-12-31 23:59:59 or 2025-12-31)"),
                limit: z.number().positive().optional().describe("Limit on number of results"),
                filters: z.array(
                    z.object({
                        property: z.string(),
                        operator: z.enum(["is", "is not", "is like", "is not like"]),
                        value: z.string(),
                    })
                ).optional().describe("Array of filter objects"),
            },
            async (params: AggregationParams) => {
                try {
                    const aggregationData = await fathomClient.api.reports.aggregation(params);
                    
                    // Check if data exists and is a proper array
                    if (!aggregationData || !Array.isArray(aggregationData)) {
                        return {
                            content: [
                                {
                                    type: "text",
                                    text: "No aggregation data found for the given parameters.",
                                },
                            ],
                        };
                    }
                    
                    if (aggregationData.length === 0) {
                        return {
                            content: [
                                {
                                    type: "text",
                                    text: "No aggregation data found for the given parameters.",
                                },
                            ],
                        };
                    }
    
                    // Format the aggregation results in a readable way
                    let resultText = `Aggregation Results (${aggregationData.length} entries):\n\n`;
                    
                    // Get all possible keys from all data entries
                    const allKeys = new Set<string>();
                    aggregationData.forEach(item => {
                        if (item) {
                            Object.keys(item).forEach(key => allKeys.add(key));
                        }
                    });
                    
                    // Format each data entry
                    aggregationData.forEach((item, index) => {
                        if (!item) return;
                        resultText += `Entry ${index + 1}:\n`;
                        
                        Array.from(allKeys).sort().forEach(key => {
                            if (item[key] !== undefined) {
                                resultText += `${key}: ${item[key]}\n`;
                            }
                        });
                        
                        resultText += "---\n\n";
                    });
                    
                    return {
                        content: [
                            {
                                type: "text",
                                text: resultText,
                            },
                        ],
                    };
                } catch (error) {
                    return {
                        content: [
                            {
                                type: "text",
                                text: `Failed to retrieve aggregation data: ${error instanceof FathomApiError ? `${error.status}: ${error.message}` : String(error)}`,
                            },
                        ],
                    };
                }
            },
        );
    }
  • src/index.ts:36-36 (registration)
    Call to register the get-aggregation tool during server initialization.
    registerAggregationTool(server, fathomClient);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'gets' data, implying a read-only operation, but doesn't mention any behavioral traits such as rate limits, authentication requirements, data freshness, or potential side effects. For a tool with 11 parameters and no annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and appropriately sized, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (11 parameters, no output schema, and no annotations), the description is insufficient. It doesn't explain what the aggregated data looks like, how results are formatted, or any constraints on usage. For a data retrieval tool with many parameters, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, meaning all parameters are documented in the input schema. The description adds no additional meaning or context beyond what's already in the schema, such as explaining relationships between parameters or providing usage examples. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get aggregated analytics data') and the source ('from Fathom'), which is specific and unambiguous. However, it doesn't differentiate this tool from its siblings (like 'list-events' or 'list-sites'), which might also retrieve analytics data, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'list-events' or 'list-sites'. It lacks explicit instructions on context, prerequisites, or exclusions, leaving the agent to infer usage based on the tool name and parameters alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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