get_qr_analytics
Retrieve comprehensive QR code analytics: total scans, daily trends, device, browser, country, and referer breakdowns with percentages, plus recent scan events with parsed user-agent and geo data.
Instructions
Get enriched scan analytics for a QR code. Returns total scans, daily trends, device/browser/country/referer breakdowns with percentages, and recent scan events with parsed user-agent and geo data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| short_id | Yes | The short ID of the QR code to get analytics for. | |
| period | No | Time period for aggregations. Default: 30d. | 30d |
Implementation Reference
- packages/mcp/src/tools.ts:193-206 (handler)Core tool definition for get_qr_analytics. Defines description, inputSchema (short_id + period), and handler which calls apiRequest to GET /api/analytics/{short_id} with period query param.
get_qr_analytics: { description: "Get enriched scan analytics for a QR code. Returns total scans, daily trends, device/browser/country/referer breakdowns with percentages, and recent scan events with parsed user-agent and geo data.", inputSchema: z.object({ short_id: z.string().describe("The short ID of the QR code to get analytics for."), period: z .enum(["7d", "30d", "90d", "all"]) .default("30d") .describe("Time period for aggregations. Default: 30d."), }), handler: async (input: { short_id: string; period: string }) => { return apiRequest(`/api/analytics/${input.short_id}`, { query: { period: input.period } }); }, }, - packages/mcp/src/api-client.ts:13-40 (helper)apiRequest helper function used by the handler. Sends HTTP requests with X-API-Key header to BASE_URL, supporting query params and JSON body.
export async function apiRequest(path: string, options: RequestOptions = {}) { const { method = "GET", body, query } = options; let url = `${BASE_URL}${path}`; if (query) { const params = new URLSearchParams(); for (const [key, value] of Object.entries(query)) { params.set(key, String(value)); } url += `?${params.toString()}`; } const headers: Record<string, string> = { "X-API-Key": API_KEY, }; if (body) { headers["Content-Type"] = "application/json"; } const res = await fetch(url, { method, headers, body: body ? JSON.stringify(body) : undefined, }); return res.json(); } - packages/mcp/src/server.ts:20-54 (registration)Tool registration loop. Iterates over exported tools object and registers each (including get_qr_analytics) with the McpServer instance via server.tool().
// Register each tool from our definitions for (const [name, tool] of Object.entries(tools)) { server.tool( name, tool.description, tool.inputSchema.shape, async (input: Record<string, unknown>) => { try { const result = await tool.handler(input as any); return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [ { type: "text" as const, text: JSON.stringify({ error: message, hint: "Check the input parameters and try again. Use list_qr_codes to verify available QR codes.", }), }, ], isError: true, }; } } ); }