Skip to main content
Glama
sussa3007

MySql MCP Server

query

Execute SQL queries on MySQL databases directly using prepared statements. Manage data retrieval and enhance AI capabilities with structured database access.

Instructions

Execute an SQL query on the connected database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNoParameters for prepared statements
sqlYesSQL query to execute

Implementation Reference

  • The handler for the 'query' tool. It extracts SQL and parameters from the request, calls executeQuery to run the query (with validation), and returns the results as JSON text content or an error.
    case "query": {
      try {
        const sql = request.params.arguments?.sql as string;
        const params = (request.params.arguments?.params as any[]) || [];
    
        // Execute query with validation
        const rows = await executeQuery(sql, params);
    
        return {
          content: [{ type: "text", text: JSON.stringify(rows, null, 2) }],
          isError: false
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text:
                error instanceof Error
                  ? error.message
                  : "Unknown error occurred"
            }
          ],
          isError: true
        };
      }
    }
  • The input schema for the 'query' tool, defining the expected parameters: sql (required string) and optional params (array of strings).
    inputSchema: {
      type: "object",
      properties: {
        sql: { type: "string", description: "SQL query to execute" },
        params: {
          type: "array",
          description: "Parameters for prepared statements",
          items: { type: "string" }
        }
      },
      required: ["sql"]
    }
  • src/index.ts:187-202 (registration)
    The registration of the 'query' tool in the ListTools response, including name, description, and input schema.
    {
      name: "query",
      description: "Execute an SQL query on the connected database.",
      inputSchema: {
        type: "object",
        properties: {
          sql: { type: "string", description: "SQL query to execute" },
          params: {
            type: "array",
            description: "Parameters for prepared statements",
            items: { type: "string" }
          }
        },
        required: ["sql"]
      }
    },
  • Helper function executeQuery that performs the actual database query execution, including read-only mode checks using getQueryType and isWriteOperation.
    async function executeQuery(sql: string, params: any[] = []): Promise<any> {
      const conn = await getConnection();
    
      // Check if in readonly mode and validate query type
      if (connectionConfig.readonly) {
        const queryType = getQueryType(sql);
        if (isWriteOperation(queryType)) {
          throw new Error(
            "Server is in read-only mode. Write operations are not allowed."
          );
        }
      }
    
      // Execute the query
      const [rows] = await conn.query(sql, params);
      return rows;
    }
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. It states the tool executes SQL queries but doesn't mention critical behaviors: whether it's read-only or can mutate data, what permissions are required, potential side effects (e.g., data modification), error handling, or result format. For a database query tool with zero annotation coverage, this is a significant gap.

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 states the core functionality without unnecessary words. It's appropriately sized for a tool with clear parameters in the schema, and every word earns its place by conveying essential information about the tool's 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 this is a database query tool with no annotations, no output schema, and siblings that perform related operations, the description is incomplete. It doesn't address critical context: whether queries can modify data, what happens with different SQL statements, how results are returned, or how this differs from metadata-focused siblings. The agent lacks sufficient information for safe and effective use.

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 ('sql' and 'params') adequately. The description doesn't add any meaningful parameter semantics beyond what the schema provides - it mentions 'SQL query' which aligns with the 'sql' parameter but offers no additional context about parameter usage, constraints, or examples.

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 ('SQL query on the connected database'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate this from sibling tools like 'describe_table' or 'list_tables' which might also involve database queries, leaving some ambiguity about when to use this versus those alternatives.

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 prerequisites (e.g., needing to connect first), exclusions (e.g., not for schema operations), or comparisons to siblings like 'describe_table' for metadata queries. This leaves the agent without 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

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

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