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
| Name | Required | Description | Default |
|---|---|---|---|
| site_id | Yes | Domain of the site (e.g. 'example.com') |
Implementation Reference
- src/plausible-client.ts:81-99 (handler)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}`, }, ], }; } );