Skip to main content
Glama
kevinbin

MCP MySQL Server

by kevinbin

query

Run SELECT queries on MySQL databases using SQL statements and optional parameters via the MCP MySQL Server, enabling data retrieval and interaction with database systems.

Instructions

Execute a SELECT query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNoQuery parameters (optional)
sqlYesSQL SELECT query

Implementation Reference

  • The main handler function for the 'query' tool that validates the SQL is a SELECT statement, executes the query using the private executeQuery method, 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)
        }]
      };
    }
  • src/index.ts:375-395 (registration)
    Registration of the 'query' tool in the ListTools response, defining its name, description, and input schema.
    {
      name: 'query',
      description: 'Execute a SELECT query',
      inputSchema: {
        type: 'object',
        properties: {
          sql: {
            type: 'string',
            description: 'SQL SELECT query',
          },
          params: {
            type: 'array',
            items: {
              type: ['string', 'number', 'boolean', 'null'],
            },
            description: 'Query parameters (optional)',
          },
        },
        required: ['sql'],
      },
    },
  • TypeScript interfaces defining the input arguments (QueryArgs: sql and optional params) and output structure (QueryResult: text content) for the query tool.
    interface QueryResult {
      content: Array<{
        type: 'text';
        text: string;
      }>;
    }
    
    interface QueryArgs {
      sql: string;
      params?: Array<string | number | boolean | null>;
    }
  • Core helper method that performs the actual database query execution after ensuring connection, handling MySQL pool query and errors.
    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);
      }
    }
  • src/index.ts:521-522 (registration)
    Dispatch case in the CallToolRequest handler that routes 'query' tool calls to the handleQuery method.
    case 'query':
      return await this.handleQuery(request.params.arguments as unknown as QueryArgs);
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. 'Execute a SELECT query' implies a read-only operation, but doesn't specify important behavioral aspects like authentication requirements, rate limits, result format, error handling, or whether it modifies database state. The description provides minimal behavioral context beyond the basic operation.

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 at just three words, with zero wasted language. It's front-loaded with the essential information and every word earns its place. This represents optimal conciseness for a simple tool.

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?

For a database query tool with no annotations and no output schema, the description is insufficiently complete. It doesn't address critical context like return format, error conditions, security implications, or performance considerations. Given the complexity of SQL execution and the lack of structured metadata, the description should provide more operational 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?

With 100% schema description coverage, the schema already documents both parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain SQL syntax requirements, parameter binding conventions, or query limitations. This meets the baseline for high schema coverage.

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 action (execute) and resource (SELECT query), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'execute' or 'describe_table' which might also involve query execution or database operations.

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. With siblings like 'execute' and 'describe_table' that likely perform related database operations, there's no indication of when this specific SELECT query tool is appropriate versus other options.

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

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