get_today_top_events
Retrieve today's most active events from Mixpanel to identify trending user activities, monitor real-time engagement, and spot emerging patterns in your analytics data.
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:655-706 (handler)The handler function that executes the get_today_top_events tool. It makes an authenticated GET request to Mixpanel's /events/top endpoint with parameters project_id, type, and limit to retrieve today's top events.async function handleGetTodayTopEvents(args: any, config: any) { const { project_id = config.DEFAULT_PROJECT_ID, type = "general", limit = 10 } = args; try { // Create authorization header using base64 encoding of credentials const credentials = `${config.SERVICE_ACCOUNT_USER_NAME}:${config.SERVICE_ACCOUNT_PASSWORD}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); // Construct URL with query parameters const url = `${config.MIXPANEL_BASE_URL}/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:235-256 (registration)The tool specification registered in the ListToolsRequestSchema handler, including name, description, and input schema definition.{ name: "get_today_top_events", description: "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.", inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The Mixpanel project ID. Optional since it has a default." }, type: { type: "string", enum: ["general", "average", "unique"], description: "The type of events to fetch, either general, average, or unique, defaults to general" }, limit: { type: "number", description: "Maximum number of events to return" } } } },
- src/index.ts:238-255 (schema)The input schema defining the parameters for the get_today_top_events tool: project_id (optional string), type (enum: general/average/unique), limit (number).inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The Mixpanel project ID. Optional since it has a default." }, type: { type: "string", enum: ["general", "average", "unique"], description: "The type of events to fetch, either general, average, or unique, defaults to general" }, limit: { type: "number", description: "Maximum number of events to return" } } }
- src/index.ts:606-607 (registration)The switch case in CallToolRequestSchema handler that registers and dispatches the tool call to its handler function.case "get_today_top_events": return await handleGetTodayTopEvents(args, { SERVICE_ACCOUNT_USER_NAME, SERVICE_ACCOUNT_PASSWORD, DEFAULT_PROJECT_ID, MIXPANEL_BASE_URL });