(server: McpServer, context: McpAuthContext)
| 12 | } from '../shared'; |
| 13 | |
| 14 | export function registerEventTools(server: McpServer, context: McpAuthContext) { |
| 15 | server.tool( |
| 16 | 'query_events', |
| 17 | 'Query raw analytics events with optional filters. Returns individual event records including path, device, country, referrer, and custom properties. Defaults to the last 30 days.', |
| 18 | { |
| 19 | projectId: projectIdSchema(context), |
| 20 | ...zDateRange, |
| 21 | eventNames: z |
| 22 | .array(z.string()) |
| 23 | .optional() |
| 24 | .describe( |
| 25 | 'Filter by event names (e.g. ["screen_view", "session_start"])', |
| 26 | ), |
| 27 | path: z.string().optional().describe('Filter by exact page path'), |
| 28 | country: z |
| 29 | .string() |
| 30 | .optional() |
| 31 | .describe('Filter by ISO 3166-1 alpha-2 country code (e.g. US, GB)'), |
| 32 | city: z.string().optional().describe('Filter by city name'), |
| 33 | device: z |
| 34 | .string() |
| 35 | .optional() |
| 36 | .describe('Filter by device type (e.g. desktop, mobile, tablet)'), |
| 37 | browser: z |
| 38 | .string() |
| 39 | .optional() |
| 40 | .describe('Filter by browser name (e.g. Chrome, Firefox)'), |
| 41 | os: z.string().optional().describe('Filter by OS name (e.g. Windows, macOS)'), |
| 42 | referrer: z.string().optional().describe('Filter by referrer URL'), |
| 43 | referrerName: z |
| 44 | .string() |
| 45 | .optional() |
| 46 | .describe('Filter by referrer name (e.g. Google, Twitter)'), |
| 47 | referrerType: z |
| 48 | .string() |
| 49 | .optional() |
| 50 | .describe('Filter by referrer type (e.g. search, social, email)'), |
| 51 | profileId: z |
| 52 | .string() |
| 53 | .optional() |
| 54 | .describe('Filter events for a specific user profile ID'), |
| 55 | properties: z |
| 56 | .record(z.string(), z.string()) |
| 57 | .optional() |
| 58 | .describe('Filter by custom event properties (key-value pairs)'), |
| 59 | limit: z |
| 60 | .number() |
| 61 | .min(1) |
| 62 | .max(100) |
| 63 | .default(20) |
| 64 | .optional() |
| 65 | .describe('Maximum number of events to return (1-100, default 20)'), |
| 66 | }, |
| 67 | async ({ projectId: inputProjectId, ...input }) => |
| 68 | withErrorHandling(async () => { |
| 69 | const projectId = await resolveProjectId(context, inputProjectId); |
| 70 | return queryEventsCore({ projectId, ...input }); |
| 71 | }), |
no test coverage detected