list_saved_cohorts
Retrieve saved user cohorts from your Mixpanel project to identify existing segments and obtain cohort IDs for detailed analysis.
Instructions
List user cohorts in the project. Useful for discovering existing user segments and getting cohort IDs for analysis.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | No | The Mixpanel project ID. Optional since it has a default. |
Implementation Reference
- src/index.ts:1151-1197 (handler)The handler function that executes the list_saved_cohorts tool by calling Mixpanel API /cohorts/list endpoint to retrieve saved cohorts.async function handleListSavedCohorts(args: any, config: any) { const { project_id = config.DEFAULT_PROJECT_ID } = args; try { const credentials = `${config.SERVICE_ACCOUNT_USER_NAME}:${config.SERVICE_ACCOUNT_PASSWORD}`; const encodedCredentials = Buffer.from(credentials).toString('base64'); const url = `${config.MIXPANEL_BASE_URL}/cohorts/list?project_id=${project_id}`; 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 listing saved cohorts:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error listing saved cohorts: ${errorMessage}` } ], isError: true }; }
- src/index.ts:498-509 (schema)The input schema and tool metadata definition for list_saved_cohorts in the ListTools response.{ name: "list_saved_cohorts", description: "List user cohorts in the project. Useful for discovering existing user segments and getting cohort IDs for analysis.", inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The Mixpanel project ID. Optional since it has a default." } } }
- src/index.ts:635-636 (registration)The registration/dispatch case in the CallToolRequestSchema handler that routes to the handler function.case "list_saved_cohorts": return await handleListSavedCohorts(args, { SERVICE_ACCOUNT_USER_NAME, SERVICE_ACCOUNT_PASSWORD, DEFAULT_PROJECT_ID, MIXPANEL_BASE_URL });