Skip to main content
Glama
sajithrw

MCP MySQL Server

by sajithrw

mysql_query

Execute SQL queries on MySQL databases to retrieve, modify, or manage data, supporting prepared statements for secure parameter handling.

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 handler function that executes the provided SQL query (with optional parameters) on the connected MySQL database using the pool.execute method. Handles both SELECT (returns rows) and other queries (affected rows, insert ID).
    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)}`);
      }
    }
  • The input schema for the mysql_query tool, defining the expected parameters: query (required string) and optional parameters array.
    {
      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)
    The switch case that registers and dispatches calls to the mysql_query handler function within the CallToolRequestSchema handler.
    case "mysql_query":
      return await this.handleQuery(args);
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 action but lacks critical details: it does not specify whether queries are read-only or mutating, potential side effects (e.g., data modification), error handling, or performance implications (e.g., rate limits). This is inadequate for a tool that could perform destructive operations.

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 with zero waste. It is front-loaded with the core purpose and appropriately sized, making it easy for an agent to parse quickly 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 the complexity of SQL execution (potential for mutations, errors, and varied outputs) and the absence of annotations and output schema, the description is incomplete. It fails to address key contextual aspects like return formats, safety warnings, or connection requirements, leaving significant gaps for agent understanding.

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 already documents both parameters (query and parameters). The description adds no additional meaning beyond what the schema provides, such as query syntax examples or parameter usage details. The baseline score of 3 reflects adequate but minimal value addition from the description.

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 a SQL query') and target resource ('on the connected MySQL database'), providing a specific verb+resource combination. However, it does not differentiate from sibling tools like mysql_describe_table or mysql_list_tables, which also involve database operations but with different purposes.

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 does not mention prerequisites (e.g., requiring a connection via mysql_connect), exclusions (e.g., avoiding certain query types), or comparisons to siblings like mysql_list_tables for specific tasks, leaving the agent with minimal context for tool selection.

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

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