Skip to main content
Glama
Darkstar326

MCP MySQL Server

by Darkstar326

mysql_query

Execute SQL queries on MySQL databases to retrieve, update, or manage data through the MCP MySQL Server.

Instructions

Execute a SQL query on the connected MySQL database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSQL query to execute
parametersNoParameters for prepared statement (optional)

Implementation Reference

  • The primary handler function for the 'mysql_query' tool. It validates input, executes the SQL query using the MySQL pool with optional parameters, handles SELECT (returns rows) and other queries (returns affected rows/insert ID), and returns formatted results or errors.
    private async handleQuery(args: any) {
      if (!this.pool) {
        throw new Error("Not connected to MySQL. Use mysql_connect first.");
      }
    
      const { query, parameters = [] } = args;
      
      if (!query || typeof query !== "string") {
        throw new Error("Query is required and must be a string");
      }
    
      try {
        const [results, fields] = await this.pool.execute(query, parameters);
        
        // Handle different types of results
        if (Array.isArray(results)) {
          return {
            content: [
              {
                type: "text",
                text: `Query executed successfully. ${results.length} rows affected.\n\nResults:\n${JSON.stringify(results, null, 2)}`,
              },
            ],
          };
        } else {
          const resultInfo = results as mysql.ResultSetHeader;
          return {
            content: [
              {
                type: "text",
                text: `Query executed successfully.\nAffected rows: ${resultInfo.affectedRows}\nInserted ID: ${resultInfo.insertId || "N/A"}`,
              },
            ],
          };
        }
      } catch (error) {
        throw new Error(`Query execution failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Defines the JSON Schema for input validation of the mysql_query tool, specifying the required 'query' string and optional 'parameters' array of strings.
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "SQL query to execute",
        },
        parameters: {
          type: "array",
          description: "Parameters for prepared statement (optional)",
          items: {
            type: "string",
          },
        },
      },
      required: ["query"],
    },
  • src/index.ts:136-156 (registration)
    Registration of the mysql_query tool in the ListTools handler response, including name, description, and input schema.
    {
      name: "mysql_query",
      description: "Execute a SQL query on the connected MySQL database",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "SQL query to execute",
          },
          parameters: {
            type: "array",
            description: "Parameters for prepared statement (optional)",
            items: {
              type: "string",
            },
          },
        },
        required: ["query"],
      },
    },
  • src/index.ts:251-252 (registration)
    Switch case in the CallToolRequest handler that routes mysql_query invocations to the handleQuery method.
    case "mysql_query":
      return await this.handleQuery(args);
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 of behavioral disclosure. It states the action ('execute a SQL query') but omits critical traits such as whether it supports read/write operations, potential side effects (e.g., data modification), error handling, or performance implications (e.g., query timeouts). This leaves significant gaps for a tool that could perform destructive actions.

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 that directly states the tool's function without unnecessary words. It is front-loaded with the core action, making it easy to parse, and every part of the sentence contributes to understanding the purpose.

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 complexity of executing SQL queries (which can range from safe reads to destructive writes), the lack of annotations and output schema makes the description incomplete. It fails to address behavioral risks, return formats, or error conditions, which are crucial for an agent to use this tool safely and effectively in a database context.

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?

Schema description coverage is 100%, so the schema fully documents the 'query' and 'parameters' fields. The description adds no additional meaning beyond what the schema provides, such as query syntax examples or parameter usage details, but this is acceptable given the high schema coverage, resulting in a baseline score.

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 verb ('execute') and resource ('SQL query on the connected MySQL database'), making the purpose immediately understandable. However, it does not explicitly differentiate from siblings like mysql_describe_table or mysql_list_tables, which also involve database operations but with different intents.

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 lacks context on prerequisites (e.g., requiring mysql_connect first), exclusions (e.g., not for schema changes), or comparisons to siblings like mysql_get_table_stats for specific query types, leaving the agent to infer usage.

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/Darkstar326/mcp-mysql'

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