get_top_events
Retrieve the most frequent events from the last 31 days to analyze user actions, prioritize feature development, and understand platform usage patterns in Mixpanel.
Instructions
Get a list of the most common events over the last 31 days. Useful for identifying key user actions, prioritizing feature development, and understanding overall platform usage patterns.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_top_events"
}
}Input 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:155-204 (handler)The asynchronous handler function for the 'get_top_events' tool. It authenticates with Mixpanel using service account credentials, constructs a URL for the /api/query/events/names endpoint with parameters project_id, type (general/average/unique), and optional limit, performs a GET request, parses the JSON response, and returns it as tool content or an error message.
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/names?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:151-154 (schema)Zod schema defining the input parameters for the get_top_events tool: 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:147-205 (registration)The server.tool() registration call for 'get_top_events', specifying the tool name, description ('Get a list of the most common events over the last 31 days...'), input schema, and inline handler implementation.
server.tool( "get_top_events", "Get a list of the most common events over the last 31 days. Useful for identifying key user actions, prioritizing feature development, and understanding overall platform usage patterns.", { 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/names?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 }; } } )