Skip to main content
Glama
MikelA92

Metabase MCP Server

by MikelA92

execute_native_query

Run custom SQL queries directly against Metabase databases to retrieve data not available in saved cards. Execute SELECT statements for ad-hoc analysis while managing resource usage.

Instructions

⚠️ [MODERATE RISK] Execute an ad-hoc native SQL query directly against a database. Use this when you need to run custom SQL that doesn't exist as a saved card. Risk: Moderate - executes arbitrary SQL (read-only with API key, but can be slow or resource-intensive). Always validate SQL before executing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseIdYesThe ID of the database to query
queryYesThe SQL query to execute (SELECT statements only recommended)

Implementation Reference

  • The core handler function that validates inputs, constructs a native query payload, sends it to Metabase's /api/dataset endpoint via POST, and returns formatted results including the query and JSON-stringified response.
      async executeNativeQuery(databaseId, query) {
        Validators.validateDatabaseId(databaseId);
        Validators.validateQuery(query);
        
        this.logger.debug('Executing native query', { databaseId, queryLength: query.length });
        
        const body = {
          database: databaseId,
          type: 'native',
          native: {
            query: query,
          },
        };
    
        const results = await this.apiClient.makeRequest('/api/dataset', {
          method: 'POST',
          body: JSON.stringify(body),
        });
        
        return {
          content: [
            {
              type: 'text',
              text: `Query Execution Results:
    Database: ${databaseId}
    Query: ${query}
    
    Results:
    ${JSON.stringify(results, null, 2)}`,
            },
          ],
        };
      }
  • Defines the tool schema including name, description, and inputSchema specifying required integer databaseId and string query parameters with validation constraints.
    {
      name: 'execute_native_query',
      description: '⚠️ [MODERATE RISK] Execute an ad-hoc native SQL query directly against a database. Use this when you need to run custom SQL that doesn\'t exist as a saved card. Risk: Moderate - executes arbitrary SQL (read-only with API key, but can be slow or resource-intensive). Always validate SQL before executing.',
      inputSchema: {
        type: 'object',
        properties: {
          databaseId: {
            type: 'integer',
            description: 'The ID of the database to query',
            minimum: 1,
          },
          query: {
            type: 'string',
            description: 'The SQL query to execute (SELECT statements only recommended)',
            minLength: 1,
          },
        },
        required: ['databaseId', 'query'],
      },
    },
  • Registers the tool handler in the MCP server's executeTool switch statement, dispatching calls to the QueryHandlers instance's executeNativeQuery method.
    case 'execute_native_query':
      return await this.queryHandlers.executeNativeQuery(args.databaseId, args.query);
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 describes key behavioral traits: moderate risk due to arbitrary SQL execution, read-only nature (implied by 'SELECT statements only recommended'), potential performance impacts ('can be slow or resource-intensive'), and security considerations ('Always validate SQL before executing'). However, it doesn't detail response format or error handling.

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 efficiently structured with three sentences that each earn their place: risk warning, purpose and usage context, and behavioral guidance. It's front-loaded with the most critical information (risk level) and avoids unnecessary repetition.

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

Completeness4/5

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

For a 2-parameter tool with no annotations and no output schema, the description provides good contextual completeness. It covers purpose, usage guidelines, risk factors, and behavioral constraints. The main gap is the lack of information about return values or error responses, which would be helpful given the absence of an output schema.

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?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds minimal value beyond the schema by reinforcing the query parameter's purpose ('SQL query to execute') and adding the recommendation for SELECT statements, but doesn't provide significant additional semantic context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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 with specific verb ('execute') and resource ('ad-hoc native SQL query directly against a database'), and distinguishes it from sibling tools by mentioning 'when you need to run custom SQL that doesn't exist as a saved card' (differentiating from execute_card_query and execute_query_builder_card).

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('when you need to run custom SQL that doesn't exist as a saved card') and when not to use it ('Always validate SQL before executing'), with clear alternatives implied by referencing saved cards and sibling tools like execute_card_query.

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