get_today_top_events
Retrieve today's most active events in Mixpanel to monitor real-time user activity, identify trends, and analyze engagement. Supports filtering by event type and limiting results.
Instructions
Get today's top events from Mixpanel. Useful for quickly identifying the most active events happening today, spotting trends, and monitoring real-time user activity.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of events to return | |
| project_id | No | The Mixpanel project ID. Optional since it has a default. | |
| type | No | The type of events to fetch, either general, average, or unique, defaults to general |
Implementation Reference
- src/index.ts:29-78 (handler)The handler function that executes the tool: authenticates with Mixpanel service account, fetches today's top events via API (`/api/query/events/top`), handles errors, and returns JSON data.async ({ project_id = DEFAULT_PROJECT_ID, type = "general", limit = 10 }) => { try { // Create authorization header using base64 encoding of credentials const credentials = `${SERVICE_ACCOUNT_USER_NAME}:${SERVICE_ACCOUNT_PASSWORD}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); // Construct URL with query parameters const url = `https://mixpanel.com/api/query/events/top?project_id=${project_id}&type=${type}${limit ? `&limit=${limit}` : ''}`; // Set up request options const options = { method: 'GET', headers: { 'accept': 'application/json', 'authorization': `Basic ${encodedCredentials}` } }; // Make the API request 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 Mixpanel events:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error fetching Mixpanel events: ${errorMessage}` } ], isError: true }; } }
- src/index.ts:24-28 (schema)Zod input schema defining parameters: project_id (optional string), type (optional enum: general/average/unique), limit (optional number).{ project_id: z.string().describe("The Mixpanel project ID. Optional since it has a default.").optional(), type: z.enum(["general", "average", "unique"]).describe("The type of events to fetch, either general, average, or unique, defaults to general").optional(), limit: z.number().optional().describe("Maximum number of events to return"), },
- src/index.ts:21-79 (registration)MCP server.tool() registration of the 'get_today_top_events' tool with name, description, input schema, and handler function.server.tool( "get_today_top_events", "Get today's top events from Mixpanel. Useful for quickly identifying the most active events happening today, spotting trends, and monitoring real-time user activity.", { project_id: z.string().describe("The Mixpanel project ID. Optional since it has a default.").optional(), type: z.enum(["general", "average", "unique"]).describe("The type of events to fetch, either general, average, or unique, defaults to general").optional(), limit: z.number().optional().describe("Maximum number of events to return"), }, async ({ project_id = DEFAULT_PROJECT_ID, type = "general", limit = 10 }) => { try { // Create authorization header using base64 encoding of credentials const credentials = `${SERVICE_ACCOUNT_USER_NAME}:${SERVICE_ACCOUNT_PASSWORD}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); // Construct URL with query parameters const url = `https://mixpanel.com/api/query/events/top?project_id=${project_id}&type=${type}${limit ? `&limit=${limit}` : ''}`; // Set up request options const options = { method: 'GET', headers: { 'accept': 'application/json', 'authorization': `Basic ${encodedCredentials}` } }; // Make the API request 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 Mixpanel events:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error fetching Mixpanel events: ${errorMessage}` } ], isError: true }; } } )