Skip to main content
Glama
mendeel
by mendeel

query_segmentation_report

Analyze how different user segments behave by breaking down event data by specific properties. Compare event patterns across user groups to identify behavioral differences and trends over time.

Instructions

Segment events by properties. Useful for analyzing how different user segments behave and comparing event patterns across groups.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
eventYesThe event to segment
from_dateYesThe date in yyyy-mm-dd format to begin querying from (inclusive)
onYesThe property to segment by
project_idNoThe Mixpanel project ID. Optional since it has a default.
to_dateYesThe date in yyyy-mm-dd format to query to (inclusive)
unitNoThe time unit for segmentation, defaults to day
whereNoJSON string representing additional filters

Implementation Reference

  • The handler function that executes the tool's core logic: authenticates with Mixpanel using service account credentials, constructs the segmentation API URL with event, date range, segmentation property ('on'), optional filters and unit, performs a GET request, parses JSON response, and returns formatted content or error.
    async function handleQuerySegmentationReport(args: any, config: any) { const { project_id = config.DEFAULT_PROJECT_ID, event, from_date, to_date, on, where, unit = "day" } = args; try { const credentials = `${config.SERVICE_ACCOUNT_USER_NAME}:${config.SERVICE_ACCOUNT_PASSWORD}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); let url = `${config.MIXPANEL_BASE_URL}/segmentation?project_id=${project_id}&event=${encodeURIComponent(event)}&from_date=${from_date}&to_date=${to_date}&on=${encodeURIComponent(on)}&unit=${unit}`; if (where) { url += `&where=${encodeURIComponent(where)}`; } 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 querying segmentation report:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error querying segmentation report: ${errorMessage}` } ], isError: true }; } }
  • JSON Schema defining the input parameters for the tool, including required fields (event, from_date, to_date, on) and optional fields (project_id, where, unit with enum). Used for validation in MCP tool calls.
    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 to segment" }, 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)" }, on: { type: "string", description: "The property to segment by" }, where: { type: "string", description: "JSON string representing additional filters" }, unit: { type: "string", enum: ["hour", "day", "week", "month"], description: "The time unit for segmentation, defaults to day" } }, required: ["event", "from_date", "to_date", "on"]
  • src/index.ts:531-569 (registration)
    Tool registration in the MCP tools list array provided to the ListToolsRequestHandler. Specifies the tool name, description, and input schema.
    { name: "query_segmentation_report", description: "Segment events by properties. Useful for analyzing how different user segments behave and comparing event patterns across groups.", 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 to segment" }, 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)" }, on: { type: "string", description: "The property to segment by" }, where: { type: "string", description: "JSON string representing additional filters" }, unit: { type: "string", enum: ["hour", "day", "week", "month"], description: "The time unit for segmentation, defaults to day" } }, required: ["event", "from_date", "to_date", "on"] } },
  • src/index.ts:642-644 (registration)
    Dispatch registration in the switch statement of the CallToolRequestHandler, mapping the tool name to its handler function call.
    case "query_segmentation_report": return await handleQuerySegmentationReport(args, { SERVICE_ACCOUNT_USER_NAME, SERVICE_ACCOUNT_PASSWORD, DEFAULT_PROJECT_ID, MIXPANEL_BASE_URL });

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/mendeel/mixpanel-mcp'

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