aggregate_event_counts
Analyze event volume trends by retrieving aggregated counts over specified time periods to identify patterns in user activity.
Instructions
Get event counts over time periods. Useful for analyzing event volume trends and identifying patterns in user activity over time.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | No | The Mixpanel project ID. Optional since it has a default. | |
| event | Yes | The event name to get counts for | |
| from_date | Yes | The date in yyyy-mm-dd format to begin querying from (inclusive) | |
| to_date | Yes | The date in yyyy-mm-dd format to query to (inclusive) | |
| unit | No | The time unit for aggregation, defaults to day |
Implementation Reference
- src/index.ts:820-867 (handler)The handler function that implements the core logic for the aggregate_event_counts tool, making an authenticated GET request to Mixpanel's /events endpoint to retrieve aggregated event counts over the specified time period.async function handleAggregateEventCounts(args: any, config: any) { const { project_id = config.DEFAULT_PROJECT_ID, event, from_date, to_date, unit = "day" } = args; try { const credentials = `${config.SERVICE_ACCOUNT_USER_NAME}:${config.SERVICE_ACCOUNT_PASSWORD}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); const url = `${config.MIXPANEL_BASE_URL}/events?project_id=${project_id}&event=${encodeURIComponent(event)}&from_date=${from_date}&to_date=${to_date}&unit=${unit}`; const options = { method: 'GET', headers: { 'accept': 'application/json', 'authorization': `Basic ${encodedCredentials}` } }; const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error(`HTTP error! status: ${response.status} - ${errorText}`); } const data = await response.json(); return { content: [ { type: "text", text: JSON.stringify(data) } ] }; } catch (error: unknown) { console.error("Error fetching event counts:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error fetching event counts: ${errorMessage}` } ], isError: true }; } }
- src/index.ts:282-308 (schema)Input schema defining the parameters for the aggregate_event_counts tool, including required fields event, from_date, to_date, and optional project_id and unit.inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The Mixpanel project ID. Optional since it has a default." }, event: { type: "string", description: "The event name to get counts for" }, from_date: { type: "string", description: "The date in yyyy-mm-dd format to begin querying from (inclusive)" }, to_date: { type: "string", description: "The date in yyyy-mm-dd format to query to (inclusive)" }, unit: { type: "string", enum: ["hour", "day", "week", "month"], description: "The time unit for aggregation, defaults to day" } }, required: ["event", "from_date", "to_date"] }
- src/index.ts:279-309 (registration)Tool registration in the ListTools handler response, defining the name, description, and input schema for aggregate_event_counts.{ name: "aggregate_event_counts", description: "Get event counts over time periods. Useful for analyzing event volume trends and identifying patterns in user activity over time.", inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The Mixpanel project ID. Optional since it has a default." }, event: { type: "string", description: "The event name to get counts for" }, from_date: { type: "string", description: "The date in yyyy-mm-dd format to begin querying from (inclusive)" }, to_date: { type: "string", description: "The date in yyyy-mm-dd format to query to (inclusive)" }, unit: { type: "string", enum: ["hour", "day", "week", "month"], description: "The time unit for aggregation, defaults to day" } }, required: ["event", "from_date", "to_date"] } },
- src/index.ts:612-613 (registration)Dispatcher case in the CallToolRequestSchema handler that routes calls to the aggregate_event_counts handler function.case "aggregate_event_counts": return await handleAggregateEventCounts(args, { SERVICE_ACCOUNT_USER_NAME, SERVICE_ACCOUNT_PASSWORD, DEFAULT_PROJECT_ID, MIXPANEL_BASE_URL });