Skip to main content
Glama
Defilan

Plausible Analytics MCP Server

by Defilan

get-aggregate-stats

Retrieve aggregate site statistics like visitors, pageviews, bounce rate, and visit duration over a specified time period, enabling quick overview and summary analysis.

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 MCP server.tool registration and handler for 'get-aggregate-stats'. The handler calls client.query() with site_id, metrics, date_range, and optional filters, then formats the aggregate result into a readable JSON response.
    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
              ),
            },
          ],
        };
      }
    );
  • Shared zod schema for date_range used by get-aggregate-stats. Supports preset strings ('30d', 'month', etc.) or custom [start, end] tuples.
    const dateRangeSchema = z
      .union([
        z.enum(["day", "7d", "30d", "month", "6mo", "12mo", "year", "all"]),
        z.tuple([z.string(), z.string()]).describe("Custom range: [start, end] in YYYY-MM-DD format"),
      ])
      .describe("Time period. Use a preset like '30d' or a custom range ['2024-01-01', '2024-01-31']")
      .default("30d");
  • Shared zod schema for metrics array used by get-aggregate-stats. Enumerates valid Plausible metrics (visitors, pageviews, bounce_rate, etc.).
    const metricsSchema = z
      .array(
        z.enum([
          "visitors",
          "visits",
          "pageviews",
          "views_per_visit",
          "bounce_rate",
          "visit_duration",
          "events",
          "scroll_depth",
          "percentage",
          "conversion_rate",
          "group_conversion_rate",
          "average_revenue",
          "total_revenue",
          "time_on_page",
        ])
      )
      .describe("Metrics to retrieve")
      .default(["visitors", "pageviews", "bounce_rate", "visit_duration"]);
  • Shared zod schema for filters used by get-aggregate-stats. Uses z.any() for the Plausible v2 filter syntax.
    const filtersSchema = z
      .array(z.any())
      .optional()
      .describe(
        "Filters array using Plausible v2 syntax, e.g. [['is', 'event:page', ['/blog*']]]"
      );
  • The query() method on PlausibleClient that the get-aggregate-stats handler calls. It POSTs to /api/v2/query with the provided params.
    async query(params: PlausibleQueryParams): Promise<PlausibleQueryResult> {
      const response = await fetch(`${this.baseUrl}/api/v2/query`, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${this.apiKey}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify(params),
      });
    
      if (!response.ok) {
        const body = await response.text();
        throw new Error(
          `Plausible API error (${response.status}): ${body}`
        );
      }
    
      return response.json() as Promise<PlausibleQueryResult>;
    }
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It only states the basic function and usage, with no mention of read-only nature, side effects, rate limits, or authentication needs. As a 'get' tool, it's likely safe, but transparency is minimal.

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?

Two sentences, no fluff. The first sentence front-loads the verb and resource, the second gives usage guidance. Every word earns its place.

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

Completeness4/5

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

Given no output schema, the description could explain return values, but the tool is straightforward and the schema covers parameters. The filters parameter is complex but schema describes it. The description is adequate for a summary tool, though adding output structure would improve completeness.

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?

Schema description coverage is 100%, so the schema already documents all parameters. The description adds no extra meaning beyond listing example metrics; it does not clarify filter syntax or default behaviors beyond what the schema provides. Baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the verb 'Get', resource 'aggregate stats', and scope 'over a time period', mentioning example metrics like visitors, pageviews, bounce rate. It also distinguishes from siblings by saying 'Use this for summary/overview questions', which contrasts with breakdown or timeseries tools.

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

Usage Guidelines4/5

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

The description explicitly says 'Use this for summary/overview questions', providing a clear usage context. However, it does not explicitly state when not to use it or mention alternatives like 'get-breakdown' for detailed breakdowns, though the sibling names imply differentiation.

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

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