get-current-visitors
Retrieve the real-time count of active visitors on a website. Monitor live traffic for any domain to gauge current engagement.
Instructions
Get the number of people currently on a site (real-time)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site_id | Yes | Domain of the site (e.g. 'example.com') |
Implementation Reference
- src/index.ts:42-61 (registration)Registration (and handler) of the 'get-current-visitors' MCP tool using server.tool(). Defines input schema with 'site_id' string parameter and calls client.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}`, }, ], }; } ); - src/plausible-client.ts:81-99 (handler)Actual implementation of getCurrentVisitors() in PlausibleClient. Makes a GET request to Plausible's real-time visitors API endpoint and returns the visitor count as a number.
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>; }