Skip to main content
Glama
aliyun

Adb MySQL MCP Server

Official
by aliyun

get_execution_plan

Analyze SQL query performance by retrieving actual execution plans with runtime statistics to identify optimization opportunities.

Instructions

Get the actual execution plan with runtime statistics for a SQL query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to analyze

Implementation Reference

  • Handler dispatch for 'get_execution_plan': extracts query argument and modifies it to 'EXPLAIN ANALYZE {query}' for execution.
    elif name == "get_execution_plan":
        query = arguments.get("query")
        if not query:
            raise ValueError("Query is required")
        query = f"EXPLAIN ANALYZE {query}"
  • Registration of the 'get_execution_plan' tool in list_tools(), including its description and input schema.
    Tool(
        name="get_execution_plan",
        description="Get the actual execution plan with runtime statistics for a SQL query",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The SQL query to analyze"
                }
            },
            "required": ["query"]
        }
    )
  • Shared database execution helper: connects to MySQL using config, executes the query (EXPLAIN ANALYZE), fetches results, formats as CSV text content, handles exceptions.
    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()
  • Pydantic input schema validation for the tool: requires a single 'query' string property.
    inputSchema={
        "type": "object",
        "properties": {
            "query": {
                "type": "string",
                "description": "The SQL query to analyze"
            }
        },
        "required": ["query"]
    }
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