Skip to main content
Glama
dragonkhoi

mixpanel

custom_jql

Execute custom JQL scripts on Mixpanel data to perform advanced analyses, handle complex queries, and transform data beyond standard report capabilities.

Instructions

Run a custom JQL (JSON Query Language) script against your Mixpanel data. Useful for complex custom analyses, advanced data transformations, and queries that can't be handled by standard report types.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNoA JSON string containing parameters to pass to the script (will be available as the 'params' variable)
project_idNoThe Mixpanel project ID. Optional since it has a default.
scriptYesThe JQL script to run (JavaScript code that uses Mixpanel's JQL functions)
workspace_idNoThe ID of the workspace if applicable

Implementation Reference

  • src/index.ts:782-852 (registration)
    Registration of the 'custom_jql' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool(
      "custom_jql",
      "Run a custom JQL (JSON Query Language) script against your Mixpanel data. Useful for complex custom analyses, advanced data transformations, and queries that can't be handled by standard report types.",
      {
        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"),
        script: z.string().describe("The JQL script to run (JavaScript code that uses Mixpanel's JQL functions)"),
        params: z.string().optional().describe("A JSON string containing parameters to pass to the script (will be available as the 'params' variable)")
      },
      async ({ project_id = DEFAULT_PROJECT_ID, workspace_id, script, params }) => {
        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 URL with query parameters
          const queryParams = new URLSearchParams();
          queryParams.append('project_id', project_id);
          if (workspace_id) queryParams.append('workspace_id', workspace_id);
          
          const url = `https://mixpanel.com/api/query/jql?${queryParams.toString()}`;
          
          // Prepare form data for POST request
          const formData = new URLSearchParams();
          formData.append('script', script);
          if (params) formData.append('params', params);
          
          // Set up request options
          const options = {
            method: 'POST',
            headers: {
              'accept': 'application/json',
              'authorization': `Basic ${encodedCredentials}`,
              'content-type': 'application/x-www-form-urlencoded'
            },
            body: formData
          };
          
          // Make the API request
          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 executing JQL query:", error);
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [
              {
                type: "text",
                text: `Error executing JQL query: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • The handler function for custom_jql tool. It authenticates with Mixpanel using service account credentials, constructs a POST request to the JQL endpoint with the provided script and params, fetches the data, and returns the JSON response or an error.
    async ({ project_id = DEFAULT_PROJECT_ID, workspace_id, script, params }) => {
      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 URL with query parameters
        const queryParams = new URLSearchParams();
        queryParams.append('project_id', project_id);
        if (workspace_id) queryParams.append('workspace_id', workspace_id);
        
        const url = `https://mixpanel.com/api/query/jql?${queryParams.toString()}`;
        
        // Prepare form data for POST request
        const formData = new URLSearchParams();
        formData.append('script', script);
        if (params) formData.append('params', params);
        
        // Set up request options
        const options = {
          method: 'POST',
          headers: {
            'accept': 'application/json',
            'authorization': `Basic ${encodedCredentials}`,
            'content-type': 'application/x-www-form-urlencoded'
          },
          body: formData
        };
        
        // Make the API request
        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 executing JQL query:", error);
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: "text",
              text: `Error executing JQL query: ${errorMessage}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the custom_jql tool: project_id (optional), workspace_id (optional), script (required), params (optional).
    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"),
    script: z.string().describe("The JQL script to run (JavaScript code that uses Mixpanel's JQL functions)"),
    params: z.string().optional().describe("A JSON string containing parameters to pass to the script (will be available as the 'params' variable)")
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. It mentions the tool runs scripts for 'complex custom analyses' and 'advanced data transformations,' which hints at potential computational intensity or data mutation, but doesn't specify execution limits, permissions required, error handling, or output format. For a tool that executes custom code against data with no annotation coverage, this leaves significant gaps in understanding its behavior and risks.

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

Conciseness5/5

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

The description is two sentences long, front-loaded with the core purpose and followed by usage context. Every word earns its place: the first sentence defines the tool, and the second explains its utility without redundancy. It's efficiently structured and avoids unnecessary elaboration, making it easy to parse quickly.

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

Completeness2/5

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

Given the tool's complexity (executing custom code against data), lack of annotations, and no output schema, the description is incomplete. It doesn't address critical aspects like what the output looks like (e.g., JSON structure, error responses), execution limits (e.g., timeouts, data size), or security implications (e.g., script validation). For a powerful, open-ended tool with no structured behavioral data, the description should provide more guidance to ensure safe and effective use.

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 input schema has 100% description coverage, with clear documentation for all four parameters (e.g., 'script' as 'JavaScript code that uses Mixpanel's JQL functions'). The description adds no additional parameter details beyond what the schema provides, such as examples or constraints. Given the high schema coverage, a baseline score of 3 is appropriate, as the schema adequately handles parameter semantics without extra help from the description.

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: 'Run a custom JQL (JSON Query Language) script against your Mixpanel data.' It specifies the verb ('run'), resource ('JQL script'), and target ('Mixpanel data'), making the function unambiguous. However, it doesn't explicitly differentiate this from sibling tools like 'query_funnel_report' or 'query_retention_report', which also query Mixpanel data but through standard reports rather than custom scripts.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: 'Useful for complex custom analyses, advanced data transformations, and queries that can't be handled by standard report types.' This implies it should be used instead of sibling tools like 'query_funnel_report' when standard reports are insufficient. However, it doesn't explicitly name alternatives or state when not to use it, such as for simple queries better suited to standard tools.

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