Skip to main content
Glama
voducdan

metabase-mcp

by voducdan

execute_mongodb_query

Run MongoDB native queries against a Metabase database by specifying database ID, collection, and query. Supports aggregation pipelines and optional parameters.

Instructions

Execute a MongoDB native query against a Metabase database.

Args: database_id: The ID of the MongoDB database to query. collection: The MongoDB collection name. query: The MongoDB query (aggregation pipeline array or query object). native_parameters: Optional parameters for the query.

Returns: Query execution results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYes
collectionYes
queryYes
native_parametersNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual implementation of the 'execute_mongodb_query' tool. It executes a MongoDB native query against a Metabase database by building a payload with the collection and query, converting the query to JSON if needed, then POSTing to /dataset endpoint.
    @mcp.tool
    async def execute_mongodb_query(
        database_id: int,
        collection: str,
        query: Any,
        ctx: Context,
        native_parameters: list[dict[str, Any]] | None = None
    ) -> dict[str, Any]:
        """
        Execute a MongoDB native query against a Metabase database.
    
        Args:
            database_id: The ID of the MongoDB database to query.
            collection: The MongoDB collection name.
            query: The MongoDB query (aggregation pipeline array or query object).
            native_parameters: Optional parameters for the query.
    
        Returns:
            Query execution results.
        """
        try:
            import json
    
            await ctx.info(f"Executing MongoDB query on database {database_id}, collection {collection}")
    
            # Convert query to JSON string if it's not already a string
            if isinstance(query, (list, dict)):
                query_string = json.dumps(query)
                await ctx.debug(f"Converted query object to JSON string")
            else:
                query_string = str(query)
    
            payload = {
                "database": database_id,
                "type": "native",
                "native": {
                    "query": query_string,
                    "collection": collection
                }
            }
    
            if native_parameters:
                payload["native"]["parameters"] = native_parameters
                await ctx.debug(f"Query parameters: {len(native_parameters)} parameters provided")
    
            result = await metabase_client.request("POST", "/dataset", json=payload)
    
            row_count = len(result.get("data", {}).get("rows", []))
            await ctx.info(f"MongoDB query executed successfully, returned {row_count} rows")
    
            return result
        except Exception as e:
            error_msg = f"Error executing MongoDB query: {e}"
            await ctx.error(error_msg)
            raise ToolError(error_msg) from e
  • server.py:366-367 (registration)
    The tool is registered via the @mcp.tool decorator on the execute_mongodb_query async function. This is the registration mechanism for the FastMCP framework.
    @mcp.tool
    async def execute_mongodb_query(
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description bears full responsibility for disclosing behavior. It mentions 'execute' but does not specify if write operations (insert, update, delete) are allowed or if it is read-only. No warnings about destructive potential or authentication requirements are provided.

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 concise (two sentences plus Args/Returns list) with no wasted words. The structured format (Args/Returns) improves readability for an agent.

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?

Despite having an output schema (which describes return values), the description lacks critical context such as usage guidelines and behavioral transparency. For a tool that executes arbitrary MongoDB queries, it should mention potential side effects (e.g., writes) and recommended use cases. The description is incomplete for such a powerful tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaning to all parameters beyond the schema, especially clarifying that 'query' can be an 'aggregation pipeline array or query object.' For 'native_parameters,' it explains they are optional but could be more specific (e.g., parameter binding). Given 0% schema coverage, this is a strong contribution.

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 'Execute a MongoDB native query against a Metabase database,' specifying the verb, resource, and context. It distinguishes from siblings like execute_query (SQL) and execute_card (saved card) by emphasizing native MongoDB.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternatives (e.g., execute_query, create_mongodb_card) or when not to use it (e.g., for simple queries). Prerequisites like having a MongoDB database configured are implied but not stated.

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/voducdan/matebase-mcp'

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