Skip to main content
Glama
enemyrr

MCP-MySQL Server

query

Run SELECT queries on MySQL databases using SQL commands and optional parameters, enabling efficient data retrieval through the MCP-MySQL Server interface.

Instructions

Execute a SELECT query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNoAn optional array of parameters (as strings) to bind to the SQL query placeholders (e.g., ?).
sqlYesThe SQL SELECT query string to execute.

Implementation Reference

  • The handler function for the 'query' tool. Validates that the SQL is a SELECT query, executes it using executeQuery helper, and returns the results as a JSON-formatted text content.
    private async handleQuery(args: QueryArgs): Promise<QueryResult> {
      this.validateSqlInput(args.sql, ['SELECT']);
      const rows = await this.executeQuery(args.sql, args.params || []);
    
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(rows, null, 2)
        }]
      };
    }
  • Input schema definition for the 'query' tool, specifying the sql string (required) and optional params array.
    inputSchema: {
      type: 'object',
      properties: {
        sql: {
          type: 'string',
          description: 'The SQL SELECT query string to execute.',
        },
        params: {
          type: 'array',
          items: {
            type: 'string',
            description: 'A parameter value (as string) to bind to the query.'
          },
          description: 'An optional array of parameters (as strings) to bind to the SQL query placeholders (e.g., ?).',
          optional: true,
        },
      },
      required: ['sql'],
    },
  • src/index.ts:421-443 (registration)
    Registration of the 'query' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'query',
      description: 'Execute a SELECT query',
      inputSchema: {
        type: 'object',
        properties: {
          sql: {
            type: 'string',
            description: 'The SQL SELECT query string to execute.',
          },
          params: {
            type: 'array',
            items: {
              type: 'string',
              description: 'A parameter value (as string) to bind to the query.'
            },
            description: 'An optional array of parameters (as strings) to bind to the SQL query placeholders (e.g., ?).',
            optional: true,
          },
        },
        required: ['sql'],
      },
    },
  • Helper method that ensures database connection, executes the SQL query using mysql2 pool.query, handles errors, and returns the result.
    private async executeQuery<T>(sql: string, params: any[] = []): Promise<T> {
      const pool = await this.ensureConnection();
      try {
        const [result] = await pool.query(sql, params);
        return result as T;
      } catch (error) {
        this.handleDatabaseError(error);
      }
    }
  • TypeScript interfaces defining the input QueryArgs and output QueryResult for the query tool.
    interface QueryResult {
      content: Array<{
        type: 'text';
        text: string;
      }>;
    }
    
    interface QueryArgs {
      sql: string;
      params?: Array<string | number | boolean | null>;
    }
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. 'Execute a SELECT query' implies a read-only operation, but it doesn't specify critical behaviors: whether it requires an active connection, handles errors, returns results in a specific format, has rate limits, or affects database state. For a tool with zero annotation coverage, this is a significant gap in transparency.

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—'Execute a SELECT query' is front-loaded and precisely conveys the core action. Every word earns its place, making it highly concise and well-structured for quick comprehension.

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 (requires connection, error handling, result formatting) and the lack of annotations and output schema, the description is incomplete. It doesn't address prerequisites, behavioral traits, or return values, leaving the agent with insufficient context to use the tool effectively beyond basic parameter passing.

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 both parameters ('sql' and 'params'). The description adds no additional meaning beyond what's in the schema—it doesn't explain parameter interactions, syntax examples, or constraints. Baseline 3 is appropriate when the schema does all the work.

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 'Execute a SELECT query' clearly states the verb ('Execute') and resource ('SELECT query'), making the purpose unambiguous. It distinguishes from siblings like 'execute' (which might handle other SQL types) by specifying SELECT queries only. However, it doesn't explicitly differentiate from all siblings (e.g., 'describe_table' also reads data), so it's not a perfect 5.

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 like 'execute', 'list_tables', or 'describe_table'. It doesn't mention prerequisites (e.g., database connection), exclusions (e.g., non-SELECT queries), or contextual cues. This leaves the agent to infer usage from the name and schema alone.

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

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