Skip to main content
Glama
dragonkhoi

mixpanel

list_saved_cohorts

Retrieve all cohorts within a Mixpanel project to identify user segments, plan targeted analyses, and extract cohort IDs for filtering in reports.

Instructions

Get all cohorts in a given project. Useful for discovering user segments, planning targeted analyses, and retrieving cohort IDs for filtering in other reports.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idNoThe Mixpanel project ID. Optional since it has a default.
workspace_idNoThe ID of the workspace if applicable

Implementation Reference

  • The handler function for the list_saved_cohorts tool. It constructs an authenticated GET request to the Mixpanel /api/query/cohorts/list endpoint using service account credentials, fetches the list of saved cohorts, and returns the JSON response or an error message.
      async ({ project_id = DEFAULT_PROJECT_ID, workspace_id }) => {
        try {
          const credentials = `${SERVICE_ACCOUNT_USER_NAME}:${SERVICE_ACCOUNT_PASSWORD}`;
          const encodedCredentials = Buffer.from(credentials).toString('base64');
          
          const queryParams = new URLSearchParams({
            project_id: project_id || ''
          });
          
          if (workspace_id) {
            queryParams.append('workspace_id', workspace_id);
          }
          
          const url = `https://mixpanel.com/api/query/cohorts/list?${queryParams.toString()}`;
          
          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 fetching Mixpanel cohorts list:", error);
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [
              {
                type: "text",
                text: `Error fetching Mixpanel cohorts list: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Zod input schema for the tool, defining optional project_id and workspace_id parameters.
    {
      project_id: z.string().describe("The Mixpanel project ID. Optional since it has a default.").optional(),
      workspace_id: z.string().optional().describe("The ID of the workspace if applicable"),
    },
  • src/index.ts:621-681 (registration)
    MCP server.tool registration for 'list_saved_cohorts', including name, description, input schema, and handler function.
      "list_saved_cohorts",
      "Get all cohorts in a given project. Useful for discovering user segments, planning targeted analyses, and retrieving cohort IDs for filtering in other reports.",
      {
        project_id: z.string().describe("The Mixpanel project ID. Optional since it has a default.").optional(),
        workspace_id: z.string().optional().describe("The ID of the workspace if applicable"),
      },
      async ({ project_id = DEFAULT_PROJECT_ID, workspace_id }) => {
        try {
          const credentials = `${SERVICE_ACCOUNT_USER_NAME}:${SERVICE_ACCOUNT_PASSWORD}`;
          const encodedCredentials = Buffer.from(credentials).toString('base64');
          
          const queryParams = new URLSearchParams({
            project_id: project_id || ''
          });
          
          if (workspace_id) {
            queryParams.append('workspace_id', workspace_id);
          }
          
          const url = `https://mixpanel.com/api/query/cohorts/list?${queryParams.toString()}`;
          
          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 fetching Mixpanel cohorts list:", error);
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [
              {
                type: "text",
                text: `Error fetching Mixpanel cohorts list: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • JSON Schema definition for the Mixpanel /query/cohorts/list API endpoint used by the tool, including input metadata (project_id required integer, optional workspace_id) and response format (array of cohort objects with id, name, count, etc.).
    declare const CohortsList: {
        readonly metadata: {
            readonly allOf: readonly [{
                readonly type: "object";
                readonly properties: {
                    readonly project_id: {
                        readonly type: "integer";
                        readonly $schema: "http://json-schema.org/draft-04/schema#";
                        readonly description: "Required if using service account to authenticate request.";
                    };
                    readonly workspace_id: {
                        readonly type: "integer";
                        readonly $schema: "http://json-schema.org/draft-04/schema#";
                        readonly description: "The id of the workspace if applicable.";
                    };
                };
                readonly required: readonly ["project_id"];
            }];
        };
        readonly response: {
            readonly "200": {
                readonly type: "array";
                readonly items: {
                    readonly type: "object";
                    readonly properties: {
                        readonly count: {
                            readonly type: "integer";
                        };
                        readonly is_visible: {
                            readonly type: "integer";
                            readonly description: "0 if not visible. 1 if visible";
                        };
                        readonly description: {
                            readonly type: "string";
                        };
                        readonly created: {
                            readonly type: "string";
                        };
                        readonly project_id: {
                            readonly type: "integer";
                        };
                        readonly id: {
                            readonly type: "integer";
                        };
                        readonly name: {
                            readonly type: "string";
                        };
                    };
                };
                readonly $schema: "http://json-schema.org/draft-04/schema#";
            };
        };
    };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool is 'useful for' certain tasks, but doesn't describe key behaviors like whether it returns all cohorts at once (pagination?), what format the output is in, or any authentication/rate limit considerations. The description adds minimal behavioral context beyond the basic purpose.

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 concise and front-loaded, starting with the core purpose in the first sentence. The second sentence adds value by explaining use cases without redundancy. It could be slightly more structured (e.g., bullet points for use cases), but overall it's efficient with minimal waste.

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 tool's moderate complexity (list operation with 2 optional parameters), no annotations, and no output schema, the description is partially complete. It covers the purpose and use cases adequately, but lacks details on output format, pagination, error handling, or behavioral constraints. For a read-only list tool, this is a minimal viable description with clear gaps.

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?

Schema description coverage is 100%, so the schema already documents both parameters ('project_id' and 'workspace_id') with descriptions. The tool description adds no parameter-specific information beyond what's in the schema, such as explaining how these IDs are obtained or their relationships. Baseline 3 is appropriate when the schema handles parameter documentation.

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 all cohorts in a given project.' It specifies the verb ('Get') and resource ('cohorts'), and distinguishes it from siblings by focusing on cohorts rather than events, funnels, or reports. However, it doesn't explicitly differentiate from similar list tools like 'list_saved_funnels' beyond the resource type.

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 through phrases like 'Useful for discovering user segments, planning targeted analyses, and retrieving cohort IDs for filtering in other reports.' This gives context for when to use it, but lacks explicit guidance on when to choose this tool over alternatives (e.g., vs. querying profiles directly) or any exclusions. No sibling-specific comparisons are made.

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