Skip to main content
Glama
smith-nathanh

Oracle MCP Server

explain_query

Analyze SQL query performance by generating execution plans to identify optimization opportunities in Oracle databases.

Instructions

Get the execution plan for a SQL query to analyze performance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL query to explain

Implementation Reference

  • The QueryExecutor.explain_query method implements the core tool logic: connects to Oracle DB, generates a unique statement ID, executes EXPLAIN PLAN, retrieves the hierarchical execution plan from plan_table with indentation, collects plan steps (operation, object, cost, cardinality, bytes), cleans up plan_table, and returns the structured execution plan.
    async def explain_query(self, sql: str) -> Dict[str, Any]:
        """Get execution plan for a query"""
        conn = await self.connection_manager.get_connection()
        try:
            cursor = conn.cursor()
    
            # Generate unique statement ID
            statement_id = f"MCP_EXPLAIN_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
    
            # Explain the plan
            explain_sql = f"EXPLAIN PLAN SET STATEMENT_ID = '{statement_id}' FOR {sql}"
            cursor.execute(explain_sql)
    
            # Fetch the execution plan
            plan_query = """
                SELECT 
                    LPAD(' ', 2 * (LEVEL - 1)) || operation || ' ' || options AS operation,
                    object_name,
                    cost,
                    cardinality,
                    bytes
                FROM plan_table
                WHERE statement_id = :statement_id
                START WITH id = 0
                CONNECT BY PRIOR id = parent_id AND statement_id = :statement_id
                ORDER BY id
            """
    
            cursor.execute(plan_query, [statement_id, statement_id])
    
            plan_rows = []
            for row in cursor:
                plan_rows.append(
                    {
                        "operation": row[0],
                        "object_name": row[1],
                        "cost": row[2],
                        "cardinality": row[3],
                        "bytes": row[4],
                    }
                )
    
            # Clean up
            cursor.execute(
                "DELETE FROM plan_table WHERE statement_id = :statement_id",
                [statement_id],
            )
            conn.commit()
    
            return {"execution_plan": plan_rows, "statement_id": statement_id}
    
        finally:
            conn.close()
  • Registration of the explain_query tool in the MCP server's list_tools handler. Defines the tool name, description, and input schema requiring a 'sql' string parameter.
    Tool(
        name="explain_query",
        description="Get the execution plan for a SQL query to analyze performance",
        inputSchema={
            "type": "object",
            "properties": {
                "sql": {
                    "type": "string",
                    "description": "SQL query to explain",
                }
            },
            "required": ["sql"],
        },
    ),
  • Input schema definition for the explain_query tool, specifying an object with a required 'sql' string property.
    inputSchema={
        "type": "object",
        "properties": {
            "sql": {
                "type": "string",
                "description": "SQL query to explain",
            }
        },
        "required": ["sql"],
    },
  • Dispatch logic in the MCP server's call_tool handler that extracts 'sql' argument, calls the executor.explain_query, formats result as JSON text content, and returns it.
    elif name == "explain_query":
        sql = arguments.get("sql")
        result = await self.executor.explain_query(sql)
    
        return [
            TextContent(
                type="text", text=json.dumps(result, indent=2, default=str)
            )
        ]
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 states the tool returns an execution plan for performance analysis, but lacks details on what the output includes (e.g., cost estimates, steps), whether it requires specific permissions, if it executes the query, or any rate limits. This leaves significant gaps in understanding how the tool behaves.

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 a single, efficient sentence: 'Get the execution plan for a SQL query to analyze performance.' It is front-loaded with the core action and resource, with no wasted words, 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 lack of annotations and output schema, the description is incomplete. It explains the basic purpose but fails to address key contextual aspects such as what the execution plan output entails, any prerequisites (e.g., database permissions), or how it differs from sibling tools. For a tool with no structured behavioral data, this leaves too many unknowns.

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 the 'sql' parameter clearly documented as 'SQL query to explain.' The description adds no additional meaning beyond this, as it only reiterates the general purpose without specifying parameter details like format or constraints. Given the high schema coverage, the baseline score of 3 is appropriate.

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: 'Get the execution plan for a SQL query to analyze performance.' It specifies the verb ('Get'), resource ('execution plan'), and context ('SQL query'), making it easy to understand. However, it doesn't explicitly differentiate from siblings like 'execute_query' or 'describe_table', which might also involve query analysis, so it falls short of a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It mentions analyzing performance, but doesn't specify scenarios (e.g., debugging slow queries) or contrast with siblings like 'execute_query' (for running queries) or 'describe_table' (for schema details). Without such context, users may struggle to select the right tool.

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/smith-nathanh/oracle-mcp-server'

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