Skip to main content
Glama
Defilan

Plausible Analytics MCP Server

by Defilan

get-aggregate-stats

Retrieve aggregated website analytics like visitors, pageviews, and bounce rate for a specified time period to monitor site performance and trends.

Instructions

Get aggregate stats for a site over a time period (visitors, pageviews, bounce rate, etc.). Use this for summary/overview questions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
site_idYesDomain of the site (e.g. 'example.com')
metricsNoMetrics to retrieve
date_rangeNoTime period. Use a preset like '30d' or a custom range ['2024-01-01', '2024-01-31']30d
filtersNoFilters array using Plausible v2 syntax, e.g. [['is', 'event:page', ['/blog*']]]

Implementation Reference

  • The handler function for the get-aggregate-stats tool that queries the client and formats the response.
    async ({ site_id, metrics, date_range, filters }) => {
      const result = await client.query({
        site_id,
        metrics,
        date_range,
        filters: filters ?? undefined,
      });
    
      // Format the aggregate result readably
      const row = result.results[0];
      const formatted: Record<string, unknown> = {};
      metrics.forEach((m, i) => {
        formatted[m] = row?.metrics[i];
      });
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              { site_id, date_range, metrics: formatted },
              null,
              2
            ),
          },
        ],
      };
    }
  • src/index.ts:103-140 (registration)
    The MCP tool registration for 'get-aggregate-stats' including input schema definitions.
    server.tool(
      "get-aggregate-stats",
      "Get aggregate stats for a site over a time period (visitors, pageviews, bounce rate, etc.). Use this for summary/overview questions.",
      {
        site_id: z.string().describe("Domain of the site (e.g. 'example.com')"),
        metrics: metricsSchema,
        date_range: dateRangeSchema,
        filters: filtersSchema,
      },
      async ({ site_id, metrics, date_range, filters }) => {
        const result = await client.query({
          site_id,
          metrics,
          date_range,
          filters: filters ?? undefined,
        });
    
        // Format the aggregate result readably
        const row = result.results[0];
        const formatted: Record<string, unknown> = {};
        metrics.forEach((m, i) => {
          formatted[m] = row?.metrics[i];
        });
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                { site_id, date_range, metrics: formatted },
                null,
                2
              ),
            },
          ],
        };
      }
    );

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/Defilan/plausible-mcp'

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