Skip to main content
Glama
Defilan

Plausible Analytics MCP Server

by Defilan

get-current-visitors

Retrieve real-time visitor count for a website to monitor current traffic activity using Plausible Analytics data.

Instructions

Get the number of people currently on a site (real-time)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
site_idYesDomain of the site (e.g. 'example.com')

Implementation Reference

  • The actual implementation of fetching current visitors from the Plausible API.
    async getCurrentVisitors(siteId: string): Promise<number> {
      const response = await fetch(
        `${this.baseUrl}/api/v1/stats/realtime/visitors?site_id=${encodeURIComponent(siteId)}`,
        {
          headers: {
            Authorization: `Bearer ${this.apiKey}`,
          },
        }
      );
    
      if (!response.ok) {
        const body = await response.text();
        throw new Error(
          `Plausible API error (${response.status}): ${body}`
        );
      }
    
      return response.json() as Promise<number>;
    }
  • src/index.ts:42-61 (registration)
    Registration of the 'get-current-visitors' tool and its handler, which calls PlausibleClient.getCurrentVisitors.
    // --- Tool: get-current-visitors ---
    
    server.tool(
      "get-current-visitors",
      "Get the number of people currently on a site (real-time)",
      {
        site_id: z.string().describe("Domain of the site (e.g. 'example.com')"),
      },
      async ({ site_id }) => {
        const visitors = await client.getCurrentVisitors(site_id);
        return {
          content: [
            {
              type: "text",
              text: `Current visitors on ${site_id}: ${visitors}`,
            },
          ],
        };
      }
    );

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