Skip to main content
Glama
dragonkhoi

mixpanel

query_segmentation_report

Analyze event data by segmenting and filtering based on user properties. Use this tool to compare performance across user groups, identify trends, and extract actionable insights from Mixpanel analytics.

Instructions

Get data for an event, segmented and filtered by properties. Useful for breaking down event data by user attributes, comparing performance across segments, and identifying which user groups perform specific actions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
eventYesThe event that you wish to get data for. Note: this is a single event name, not an array
formatNoCan be set to 'csv'
from_dateYesThe date in yyyy-mm-dd format to begin querying from (inclusive)
intervalNoOptional parameter in lieu of 'unit' when 'type' is not 'general'. Determines the number of days your results are bucketed into
limitNoReturn the top property values. Defaults to 60. Maximum value 10,000. This parameter does nothing if 'on' is not specified
onNoThe property expression to segment the event on
project_idNoThe Mixpanel project ID. Optional since it has a default.
to_dateYesThe date in yyyy-mm-dd format to query to (inclusive)
typeNoThe type of analysis to perform, either general, unique, or average, defaults to general
unitNoThe buckets into which the property values that you segment on are placed. Default is 'day'
whereYesAn expression to filter events by based on the grammar: <expression> ::= 'properties["' <property> '"]' | <expression> <binary op> <expression> | <unary op> <expression> | <math op> '(' <expression> ')' | <string literal> <binary op> ::= '+' | '-' | '*' | '/' | '%' | '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'and' | 'or' | <unary op> ::= '-' | 'not'
workspace_idNoThe ID of the workspace if applicable

Implementation Reference

  • src/index.ts:1144-1230 (registration)
    Registration and complete implementation of the 'query_segmentation_report' tool, including schema validation with Zod and the async handler function that queries the Mixpanel segmentation API.
      "query_segmentation_report",
      "Get data for an event, segmented and filtered by properties. Useful for breaking down event data by user attributes, comparing performance across segments, and identifying which user groups perform specific actions.",
      {
        project_id: z.string().describe("The Mixpanel project ID. Optional since it has a default.").optional(),
        workspace_id: z.string().describe("The ID of the workspace if applicable").optional(),
        event: z.string().describe("The event that you wish to get data for. Note: this is a single event name, not an array"),
        from_date: z.string().describe("The date in yyyy-mm-dd format to begin querying from (inclusive)"),
        to_date: z.string().describe("The date in yyyy-mm-dd format to query to (inclusive)"),
        on: z.string().describe("The property expression to segment the event on").optional(),
        unit: z.enum(["minute", "hour", "day", "month"]).describe("The buckets into which the property values that you segment on are placed. Default is 'day'").optional(),
        interval: z.number().describe("Optional parameter in lieu of 'unit' when 'type' is not 'general'. Determines the number of days your results are bucketed into").optional(),
        where: z.string().describe(`An expression to filter events by based on the grammar: <expression> ::= 'properties["' <property> '"]'
                    | <expression> <binary op> <expression>
                    | <unary op> <expression>
                    | <math op> '(' <expression> ')'
                    | <string literal>
       <binary op> ::= '+' | '-' | '*' | '/' | '%' | '==' | '!=' |
                      '>' | '>=' | '<' | '<=' | 'in' | 'and' | 'or'
                    | <unary op> ::= '-' | 'not'`),
        limit: z.number().describe("Return the top property values. Defaults to 60. Maximum value 10,000. This parameter does nothing if 'on' is not specified").optional(),
        type: z.enum(["general", "unique", "average"]).describe("The type of analysis to perform, either general, unique, or average, defaults to general").optional(),
        format: z.enum(["csv"]).describe("Can be set to 'csv'").optional(),
      },
      async ({ 
        project_id = DEFAULT_PROJECT_ID, 
        workspace_id, 
        event, 
        from_date, 
        to_date, 
        on, 
        unit, 
        interval, 
        where, 
        limit, 
        type, 
        format 
      }) => {
        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 base URL with required parameters
          let url = `https://mixpanel.com/api/query/segmentation?project_id=${project_id}&event=${encodeURIComponent(event)}&from_date=${from_date}&to_date=${to_date}`;
          
          // Add optional parameters if they exist
          if (workspace_id) url += `&workspace_id=${workspace_id}`;
          if (on) url += `&on=${encodeURIComponent(on)}`;
          if (unit) url += `&unit=${unit}`;
          if (interval !== undefined) url += `&interval=${interval}`;
          if (where) url += `&where=${encodeURIComponent(where)}`;
          if (limit !== undefined) url += `&limit=${limit}`;
          if (type) url += `&type=${type}`;
          if (format) url += `&format=${format}`;
          
          // 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(`API request failed with status ${response.status}: ${errorText}`);
          }
          
          const data = await response.json();
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(data)
              }
            ]
          };
        } catch (error) {
          console.error('Error querying segmentation report:', error);
          throw error;
        }
      }
    );
  • The async handler function that constructs the Mixpanel API request to /query/segmentation, handles authentication, parameters, fetches data, and returns JSON response.
    async ({ 
      project_id = DEFAULT_PROJECT_ID, 
      workspace_id, 
      event, 
      from_date, 
      to_date, 
      on, 
      unit, 
      interval, 
      where, 
      limit, 
      type, 
      format 
    }) => {
      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 base URL with required parameters
        let url = `https://mixpanel.com/api/query/segmentation?project_id=${project_id}&event=${encodeURIComponent(event)}&from_date=${from_date}&to_date=${to_date}`;
        
        // Add optional parameters if they exist
        if (workspace_id) url += `&workspace_id=${workspace_id}`;
        if (on) url += `&on=${encodeURIComponent(on)}`;
        if (unit) url += `&unit=${unit}`;
        if (interval !== undefined) url += `&interval=${interval}`;
        if (where) url += `&where=${encodeURIComponent(where)}`;
        if (limit !== undefined) url += `&limit=${limit}`;
        if (type) url += `&type=${type}`;
        if (format) url += `&format=${format}`;
        
        // 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(`API request failed with status ${response.status}: ${errorText}`);
        }
        
        const data = await response.json();
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(data)
            }
          ]
        };
      } catch (error) {
        console.error('Error querying segmentation report:', error);
        throw error;
      }
    }
  • Zod schema defining input parameters for the query_segmentation_report tool, including descriptions and types.
    {
      project_id: z.string().describe("The Mixpanel project ID. Optional since it has a default.").optional(),
      workspace_id: z.string().describe("The ID of the workspace if applicable").optional(),
      event: z.string().describe("The event that you wish to get data for. Note: this is a single event name, not an array"),
      from_date: z.string().describe("The date in yyyy-mm-dd format to begin querying from (inclusive)"),
      to_date: z.string().describe("The date in yyyy-mm-dd format to query to (inclusive)"),
      on: z.string().describe("The property expression to segment the event on").optional(),
      unit: z.enum(["minute", "hour", "day", "month"]).describe("The buckets into which the property values that you segment on are placed. Default is 'day'").optional(),
      interval: z.number().describe("Optional parameter in lieu of 'unit' when 'type' is not 'general'. Determines the number of days your results are bucketed into").optional(),
      where: z.string().describe(`An expression to filter events by based on the grammar: <expression> ::= 'properties["' <property> '"]'
                  | <expression> <binary op> <expression>
                  | <unary op> <expression>
                  | <math op> '(' <expression> ')'
                  | <string literal>
     <binary op> ::= '+' | '-' | '*' | '/' | '%' | '==' | '!=' |
                    '>' | '>=' | '<' | '<=' | 'in' | 'and' | 'or'
                  | <unary op> ::= '-' | 'not'`),
      limit: z.number().describe("Return the top property values. Defaults to 60. Maximum value 10,000. This parameter does nothing if 'on' is not specified").optional(),
      type: z.enum(["general", "unique", "average"]).describe("The type of analysis to perform, either general, unique, or average, defaults to general").optional(),
      format: z.enum(["csv"]).describe("Can be set to 'csv'").optional(),
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions the tool's utility for segmentation and filtering, it doesn't describe important behavioral aspects such as: whether this is a read-only operation, what format the data returns in (beyond the optional 'csv' parameter), whether there are rate limits, authentication requirements, or what happens with large datasets. The description adds some context about use cases but lacks critical operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in two sentences. The first sentence clearly states the core functionality, and the second sentence provides useful context about applications. There's no wasted verbiage or redundancy, though it could be slightly more front-loaded with explicit differentiation from sibling tools.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (12 parameters, 4 required), lack of annotations, and no output schema, the description is moderately complete. It explains what the tool does and suggests use cases, but it doesn't address behavioral aspects like data format, performance characteristics, or error handling. For a tool with this many parameters and no structured safety hints, the description should provide more operational guidance to be fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description doesn't mention any specific parameters, but the input schema has 100% description coverage with detailed parameter documentation. The baseline score of 3 is appropriate since the schema does the heavy lifting of explaining parameters like 'event', 'on', 'where', 'type', etc. The description's mention of 'segmented and filtered by properties' loosely maps to parameters like 'on' and 'where' but adds minimal semantic value beyond what's already in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get data for an event, segmented and filtered by properties.' It specifies the verb ('Get'), resource ('data for an event'), and key operations ('segmented and filtered by properties'). However, it doesn't explicitly differentiate from sibling tools like query_segmentation_average or query_segmentation_sum, which appear to be related segmentation tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage context with phrases like 'Useful for breaking down event data by user attributes, comparing performance across segments, and identifying which user groups perform specific actions.' This suggests when the tool might be valuable, but it doesn't explicitly state when to use this tool versus alternatives like query_segmentation_average or query_frequency_report, nor does it mention any prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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