Skip to main content
Glama
MikelA92

Metabase MCP Server

by MikelA92

execute_card_query

Execute saved Metabase card queries to retrieve data results. Use this tool to run pre-defined queries with optional parameters for filtering.

Instructions

▶️ [MODERATE RISK] Execute a saved card query and return results. Use this to get actual data from a card. May take time for complex queries. Risk: Moderate - executes queries that may be slow or resource-intensive. Does not modify data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cardIdYesThe ID of the card to execute
parametersNoQuery parameters (e.g., date filters, IDs)

Implementation Reference

  • The core handler function that implements the execute_card_query tool. It validates the cardId, constructs query parameters, makes a POST request to Metabase's /api/card/{cardId}/query endpoint, and formats the results as MCP content.
      async executeCardQuery(cardId, parameters = {}) {
        Validators.validateCardId(cardId);
        
        this.logger.debug('Executing card query', { cardId, parameters });
        
        const queryParams = new URLSearchParams();
        Object.entries(parameters).forEach(([key, value]) => {
          queryParams.append(key, value);
        });
    
        const results = await this.apiClient.makeRequest(`/api/card/${cardId}/query?${queryParams}`, {
          method: 'POST',
        });
        
        return {
          content: [
            {
              type: 'text',
              text: `Query Results for Card ${cardId}:
    ${JSON.stringify(results, null, 2)}`,
            },
          ],
        };
      }
  • The JSON schema definition for the execute_card_query tool, specifying input validation for cardId (required integer) and optional parameters object. Used for tool listing and validation.
    {
      name: 'execute_card_query',
      description: '▶️ [MODERATE RISK] Execute a saved card query and return results. Use this to get actual data from a card. May take time for complex queries. Risk: Moderate - executes queries that may be slow or resource-intensive. Does not modify data.',
      inputSchema: {
        type: 'object',
        properties: {
          cardId: {
            type: 'integer',
            description: 'The ID of the card to execute',
            minimum: 1,
          },
          parameters: {
            type: 'object',
            description: 'Query parameters (e.g., date filters, IDs)',
            additionalProperties: true,
          },
        },
        required: ['cardId'],
      },
    },
  • Registration of the execute_card_query tool in the server's executeTool switch statement, which dispatches tool calls to the appropriate handler method.
    case 'execute_card_query':
      return await this.cardHandlers.executeCardQuery(args.cardId, args.parameters);

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