Skip to main content
Glama
aliyun

Adb MySQL MCP Server

Official
by aliyun

execute_sql

Execute SQL queries in Adb MySQL Cluster to retrieve data, update records, or perform database operations through the MCP server interface.

Instructions

Execute a SQL query in the Adb MySQL Cluster

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to execute

Implementation Reference

  • The @app.call_tool() handler implements the logic for 'execute_sql' by extracting the query from arguments, connecting to the MySQL database using get_db_config(), executing the query, formatting results as CSV text content, and handling errors.
    @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 input schema definition for the 'execute_sql' tool, specifying a required 'query' string property.
    Tool(
        name="execute_sql",
        description="Execute a SQL query in the Adb MySQL Cluster",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The SQL query to execute"
                }
            },
            "required": ["query"]
        },
    ),
  • Registration of the 'execute_sql' tool (among others) via the @app.list_tools() decorator, which returns the list of available tools with their schemas.
    @app.list_tools()
    async def list_tools() -> list[Tool]:
        return [
            Tool(
                name="execute_sql",
                description="Execute a SQL query in the Adb MySQL Cluster",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "query": {
                            "type": "string",
                            "description": "The SQL query to execute"
                        }
                    },
                    "required": ["query"]
                },
            ),
            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"]
                },
            ),
            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"]
                }
            )
        ]
  • Helper function to retrieve MySQL database configuration from environment variables, used by the tool handler.
    def get_db_config():
        config = {
            "host": os.getenv("ADB_MYSQL_HOST", "localhost"),
            "port": int(os.getenv("ADB_MYSQL_PORT", 3306)),
            "user": os.getenv("ADB_MYSQL_USER"),
            "password": os.getenv("ADB_MYSQL_PASSWORD"),
            "database": os.getenv("ADB_MYSQL_DATABASE"),
        }
    
        if not all([config["user"], config["password"], config["database"]]):
            raise ValueError("Missing required database configuration")
    
        return config
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but provides minimal information. It states what the tool does but doesn't disclose important behavioral traits like whether this is a read-only or write operation, what permissions are required, whether there are query size or complexity limits, what happens with malformed queries, or what the response format will be. The description adds almost no behavioral context beyond the basic action.

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 extremely concise - a single sentence that directly states the tool's purpose without any wasted words. It's front-loaded with the essential information and appropriately sized for what it communicates.

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 that this is a SQL execution tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what kind of SQL queries are supported, what database/schema context is used, whether transactions are supported, what the return format will be, or any error handling behavior. For a tool that could potentially execute destructive operations, this level of documentation is inadequate.

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 'query' parameter clearly documented. The description doesn't add any meaningful parameter semantics beyond what the schema already provides - it doesn't specify query syntax requirements, supported SQL dialects, parameter binding methods, or any constraints on the query content. With complete 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 action ('Execute') and target resource ('a SQL query in the Adb MySQL Cluster'), providing specific verb+resource pairing. However, it doesn't explicitly differentiate from sibling tools like get_execution_plan or get_query_plan, which appear to be related query analysis tools rather than execution tools.

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 doesn't mention sibling tools, suggest appropriate query types, warn about limitations, or provide any context about when this execution tool should be preferred over the analysis-focused sibling tools.

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