query_insights_report
Access pre-configured Insights reports to retrieve saved analyses, standardized metrics, and complex visualizations for your Mixpanel project data.
Instructions
Get data from your Insights reports. Useful for accessing saved analyses, sharing standardized metrics across teams, and retrieving complex pre-configured visualizations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bookmark_id | Yes | The ID of your Insights report | |
| project_id | No | The Mixpanel project ID. Optional since it has a default. | |
| workspace_id | No | The ID of the workspace if applicable |
Implementation Reference
- src/index.ts:417-480 (handler)Full implementation of the 'query_insights_report' MCP tool, including registration, input schema validation with Zod, and the handler function that authenticates with Mixpanel service account credentials and fetches Insights report data via the /api/query/insights endpoint using the provided bookmark_id.server.tool( "query_insights_report", "Get data from your Insights reports. Useful for accessing saved analyses, sharing standardized metrics across teams, and retrieving complex pre-configured visualizations.", { 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"), bookmark_id: z.string().describe("The ID of your Insights report"), }, async ({ project_id = DEFAULT_PROJECT_ID, workspace_id, bookmark_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 || '', bookmark_id: bookmark_id }); if (workspace_id) { queryParams.append('workspace_id', workspace_id); } const url = `https://mixpanel.com/api/query/insights?${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 insights:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error fetching Mixpanel insights: ${errorMessage}` } ], isError: true }; } } );
- src/index.ts:420-424 (schema)Zod schema defining the input parameters for the query_insights_report tool: project_id (optional), workspace_id (optional), bookmark_id (required).{ 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"), bookmark_id: z.string().describe("The ID of your Insights report"), },
- src/index.ts:417-480 (registration)Registration of the 'query_insights_report' tool on the MCP server using server.tool(), including name, description, schema, and handler.server.tool( "query_insights_report", "Get data from your Insights reports. Useful for accessing saved analyses, sharing standardized metrics across teams, and retrieving complex pre-configured visualizations.", { 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"), bookmark_id: z.string().describe("The ID of your Insights report"), }, async ({ project_id = DEFAULT_PROJECT_ID, workspace_id, bookmark_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 || '', bookmark_id: bookmark_id }); if (workspace_id) { queryParams.append('workspace_id', workspace_id); } const url = `https://mixpanel.com/api/query/insights?${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 insights:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error fetching Mixpanel insights: ${errorMessage}` } ], isError: true }; } } );