Skip to main content
Glama

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of events to return
project_idNoThe Mixpanel project ID. Optional since it has a default.
typeNoThe type of events to fetch, either general, average, or unique, defaults to general

Implementation Reference

  • 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 }; } }
  • 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 }; } } )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dragonkhoi/mixpanel-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server