get_total_visitors
Retrieve total visitor counts for a specified date range from Clicky analytics to monitor website traffic performance and analyze audience engagement patterns.
Instructions
Get total visitors for a date range from Clicky analytics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | End date in YYYY-MM-DD format | |
| start_date | Yes | Start date in YYYY-MM-DD format |
Implementation Reference
- src/tools/get-total-visitors.ts:25-56 (handler)The handleGetTotalVisitors function implements the core logic of the get_total_visitors tool: it constructs a DateRange from input arguments, fetches data using ClickyClient, and returns formatted JSON response or error.export async function handleGetTotalVisitors( args: { start_date: string; end_date: string }, clickyClient: ClickyClient ) { try { const dateRange: DateRange = { startDate: args.start_date, endDate: args.end_date }; const data = await clickyClient.getTotalVisitors(dateRange); return { content: [ { type: 'text', text: JSON.stringify(data, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching total visitors: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } }
- src/tools/get-total-visitors.ts:4-23 (schema)Tool definition for 'get_total_visitors' including name, description, and input schema requiring start_date and end_date in YYYY-MM-DD format.export const getTotalVisitorsTool: Tool = { name: 'get_total_visitors', description: 'Get total visitors for a date range from Clicky analytics', inputSchema: { type: 'object', properties: { start_date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$', description: 'Start date in YYYY-MM-DD format' }, end_date: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}$', description: 'End date in YYYY-MM-DD format' } }, required: ['start_date', 'end_date'] } };
- src/index.ts:91-99 (registration)Registers the getTotalVisitorsTool in the MCP server's listTools request handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ getTotalVisitorsTool, getDomainVisitorsTool, getTopPagesTool, getTrafficSourcesTool, getPageTrafficTool, ], }));
- src/index.ts:105-107 (registration)Dispatches calls to 'get_total_visitors' by invoking the handleGetTotalVisitors function in the CallToolRequestSchema handler.switch (name) { case 'get_total_visitors': return await handleGetTotalVisitors(args as any, this.clickyClient);
- src/clicky-client.ts:44-58 (helper)ClickyClient.getTotalVisitors method performs the actual API request to Clicky for total visitors data within the specified date range.async getTotalVisitors(dateRange: DateRange): Promise<any> { this.validateDateRange(dateRange); const response = await this.client.get('', { params: { site_id: this.siteId, sitekey: this.siteKey, type: 'visitors', date: `${dateRange.startDate},${dateRange.endDate}`, output: 'json' } }); return response.data; }