query_profiles
Filter and retrieve user profiles based on specific properties to analyze user segments and identify target audiences within Mixpanel.
Instructions
Query user profiles with filtering. Useful for finding users based on profile properties and analyzing user segments.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | No | The Mixpanel project ID. Optional since it has a default. | |
| where | No | JSON string representing the filter conditions for profiles | |
| select | No | JSON array string of properties to return. If not specified, returns all properties | |
| limit | No | Maximum number of profiles to return |
Implementation Reference
- src/index.ts:918-974 (handler)The handler function that implements the core logic of the 'query_profiles' tool. It constructs a request to Mixpanel's /engage endpoint using provided parameters (project_id, where, select, limit), authenticates with service account credentials, fetches user profiles, and returns the JSON data or an error.async function handleQueryProfiles(args: any, config: any) { const { project_id = config.DEFAULT_PROJECT_ID, where, select, limit = 100 } = 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}/engage?project_id=${project_id}`; if (where) { url += `&where=${encodeURIComponent(where)}`; } if (select) { url += `&select=${encodeURIComponent(select)}`; } if (limit) { url += `&limit=${limit}`; } 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 profiles:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error querying profiles: ${errorMessage}` } ], isError: true }; }
- src/index.ts:377-399 (schema)The tool definition including name, description, and inputSchema for validating parameters (project_id, where, select, limit) when listing or calling the tool.name: "query_profiles", description: "Query user profiles with filtering. Useful for finding users based on profile properties and analyzing user segments.", inputSchema: { type: "object", properties: { project_id: { type: "string", description: "The Mixpanel project ID. Optional since it has a default." }, where: { type: "string", description: "JSON string representing the filter conditions for profiles" }, select: { type: "string", description: "JSON array string of properties to return. If not specified, returns all properties" }, limit: { type: "number", description: "Maximum number of profiles to return" } } }
- src/index.ts:622-623 (registration)The switch case in the CallToolRequestHandler that registers and dispatches calls to the 'query_profiles' handler function.case "query_profiles": return await handleQueryProfiles(args, { SERVICE_ACCOUNT_USER_NAME, SERVICE_ACCOUNT_PASSWORD, DEFAULT_PROJECT_ID, MIXPANEL_BASE_URL });