Skip to main content
Glama
MikelA92

Metabase MCP Server

by MikelA92

execute_query_builder_card

Run Metabase query builder cards with custom filters and aggregations to analyze data using specific parameters.

Instructions

⚙️ [MODERATE RISK] Execute a query-builder card with specific parameters. Use this to run query builder cards with custom filters and aggregations. Risk: Moderate - executes queries that may be slow or resource-intensive.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cardIdYesThe card ID
parametersYesQuery parameters object with filters, aggregations, breakouts

Implementation Reference

  • The primary handler function that implements the core logic for the 'execute_query_builder_card' MCP tool. It validates the card ID, fetches the base card details, modifies the query builder structure with provided parameters, executes the query via Metabase's /api/dataset endpoint, and returns formatted results.
      async executeQueryBuilderCard(cardId, parameters) {
        Validators.validateCardId(cardId);
        
        this.logger.debug('Executing query builder card', { cardId, parameters });
        
        // First, get the base card to understand its structure
        const baseCard = await this.apiClient.makeRequest(`/api/card/${cardId}`);
        
        if (baseCard.dataset_query.type !== 'query') {
          throw new Error('Card is not a query-builder card');
        }
        
        // Create a modified dataset query with the provided parameters
        const modifiedQuery = {
          ...baseCard.dataset_query,
          query: {
            ...baseCard.dataset_query.query,
            ...parameters,
          },
        };
        
        // Execute the query using the dataset endpoint
        const body = {
          database: baseCard.dataset_query.database,
          type: 'query',
          query: modifiedQuery.query,
        };
    
        const results = await this.apiClient.makeRequest('/api/dataset', {
          method: 'POST',
          body: JSON.stringify(body),
        });
        
        return {
          content: [
            {
              type: 'text',
              text: `Query Builder Card Execution Results:
    Card ID: ${cardId}
    Parameters Applied:
    ${JSON.stringify(parameters, null, 2)}
    
    Results:
    ${JSON.stringify(results, null, 2)}`,
            },
          ],
        };
      }
  • The registration/dispatch logic in the MCP server's executeTool method that maps the tool name 'execute_query_builder_card' to the corresponding handler method.
    case 'execute_query_builder_card':
      return await this.cardHandlers.executeQueryBuilderCard(args.cardId, args.parameters);
  • The tool definition including name, description, and input schema (JSON Schema) for input validation in the MCP server.
      name: 'execute_query_builder_card',
      description: '⚙️ [MODERATE RISK] Execute a query-builder card with specific parameters. Use this to run query builder cards with custom filters and aggregations. Risk: Moderate - executes queries that may be slow or resource-intensive.',
      inputSchema: {
        type: 'object',
        properties: {
          cardId: {
            type: 'integer',
            description: 'The card ID',
            minimum: 1,
          },
          parameters: {
            type: 'object',
            description: 'Query parameters object with filters, aggregations, breakouts',
            additionalProperties: true,
          },
        },
        required: ['cardId', 'parameters'],
      },
    },
  • Supporting client method that performs the core API calls for executing query builder cards, mirroring the handler logic but used as a utility in other contexts.
    async executeQueryBuilderCard(cardId, parameters) {
      Validators.validateCardId(cardId);
    
      // First, get the base card to understand its structure
      const baseCard = await this.makeRequest(`/api/card/${cardId}`);
      
      if (baseCard.dataset_query.type !== 'query') {
        throw new ValidationError(
          'Card is not a query-builder card',
          'cardId',
          cardId
        );
      }
      
      // Create a modified dataset query with the provided parameters
      const modifiedQuery = {
        ...baseCard.dataset_query,
        query: {
          ...baseCard.dataset_query.query,
          ...parameters,
        },
      };
      
      // Execute the query using the dataset endpoint
      const body = {
        database: baseCard.dataset_query.database,
        type: 'query',
        query: modifiedQuery.query,
      };
    
      return await this.makeRequest('/api/dataset', {
        method: 'POST',
        body: JSON.stringify(body),
      });
    }
Behavior4/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 effectively adds context beyond the input schema by highlighting the 'MODERATE RISK' and explaining that queries 'may be slow or resource-intensive.' This warns about performance impacts, which is crucial for a tool with potential resource usage. It doesn't cover other aspects like permissions or response format, but the risk disclosure is valuable.

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 appropriately sized and front-loaded, starting with a risk emoji and key action. Both sentences earn their place: the first states the purpose, and the second elaborates on usage and risk. It avoids redundancy and is efficiently structured, though the risk note could be integrated more seamlessly.

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 complexity (2 parameters, nested objects, no output schema, and no annotations), the description is moderately complete. It covers purpose and risk but lacks details on output format, error handling, or specific behavioral traits like rate limits. The risk warning is helpful, but for a tool with potential resource impacts, more context on performance or limitations would improve completeness.

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 schema description coverage is 100%, so the input schema already documents both parameters ('cardId' and 'parameters'). The description adds marginal value by mentioning 'custom filters and aggregations,' which aligns with the 'parameters' object but doesn't provide additional syntax or format details beyond what the schema implies. This meets the baseline for high schema coverage.

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: 'Execute a query-builder card with specific parameters' and 'run query builder cards with custom filters and aggregations.' This specifies the verb (execute/run), resource (query-builder card), and scope (with parameters). However, it doesn't explicitly distinguish it from sibling tools like 'execute_card_query' or 'execute_native_query,' which likely have similar functions.

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 implies usage context by mentioning 'custom filters and aggregations,' suggesting this tool is for parameterized queries. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'execute_card_query' or 'execute_native_query,' nor does it specify prerequisites or exclusions. The risk warning hints at cautious use but lacks concrete alternatives.

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

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/MikelA92/metabase-mcp-mab'

If you have feedback or need assistance with the MCP directory API, please join our Discord server