Skip to main content
Glama
aliyun

Adb MySQL MCP Server

Official
by aliyun

get_query_plan

Analyze SQL query execution plans to optimize database performance and identify potential bottlenecks in Adb MySQL databases.

Instructions

Get the query plan for a SQL query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to analyze

Implementation Reference

  • The @app.call_tool() function serves as the handler for the get_query_plan tool (among others). For get_query_plan, it retrieves the input query, prefixes it with 'EXPLAIN ', executes it using pymysql on the configured MySQL connection, fetches the results, formats them as CSV text, and returns as TextContent.
    @app.call_tool()
    async def call_tool(name: str, arguments: dict) -> list[TextContent]:
        """Execute SQL commands."""
        config = get_db_config()
    
        if name == "execute_sql":
            query = arguments.get("query")
            if not query:
                raise ValueError("Query is required")
        elif name == "get_query_plan":
            query = arguments.get("query")
            if not query:
                raise ValueError("Query is required")
            query = f"EXPLAIN {query}"
        elif name == "get_execution_plan":
            query = arguments.get("query")
            if not query:
                raise ValueError("Query is required")
            query = f"EXPLAIN ANALYZE {query}"
        else:
            raise ValueError(f"Unknown tool: {name}")
    
        conn = pymysql.connect(**config)
        conn.autocommit(True)
        cursor = conn.cursor()
    
        try:
            # Execute the query
            cursor.execute(query)
    
            columns = [desc[0] for desc in cursor.description]
            rows = cursor.fetchall()
            result = [",".join(map(str, row)) for row in rows]
            return [TextContent(type="text", text="\n".join([",".join(columns)] + result))]
        except Exception as e:
            return [TextContent(type="text", text=f"Error executing query: {str(e)}")]
        finally:
            if cursor:
                cursor.close()
            if conn.open:
                conn.close()
  • The get_query_plan tool is registered in the list_tools() function, specifying its name, description, and input schema which requires a 'query' string parameter.
    Tool(
        name="get_query_plan",
        description="Get the query plan for a SQL query",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The SQL query to analyze"
                }
            },
            "required": ["query"]
        },
    ),
Behavior2/5

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

With no annotations provided, the description carries the full burden but only states what the tool does without behavioral details. It doesn't disclose if this is a read-only operation, has side effects, requires specific permissions, or involves rate limits, which are critical for a tool analyzing SQL queries.

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, direct sentence with zero wasted words, making it highly concise and front-loaded. It efficiently communicates the core function without unnecessary elaboration.

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 no annotations, no output schema, and a tool that likely returns complex query plan data, the description is insufficient. It doesn't explain the return format, potential errors, or usage context, leaving gaps in understanding for effective tool invocation.

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, clearly documenting the 'query' parameter. The description adds no additional meaning beyond this, such as SQL dialect support or query complexity limits, so it meets the baseline for high schema coverage without extra value.

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 action ('Get') and target ('query plan for a SQL query'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get_execution_plan', which might be similar, so it misses the highest score for sibling distinction.

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 like 'execute_sql' or 'get_execution_plan'. It lacks context such as whether this is for debugging, optimization, or pre-execution analysis, leaving the agent with no usage criteria.

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/aliyun/alibabacloud-adb-mysql-mcp-server'

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