Skip to main content
Glama

mysql_query

Execute read-only SQL queries against a local WordPress database to retrieve posts, users, options, and other data for development and analysis.

Instructions

Execute a read-only SQL query against the Local WordPress database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSingle read-only SQL statement (SELECT/SHOW/DESCRIBE/EXPLAIN).
paramsNoOptional parameter values for placeholders (?).

Implementation Reference

  • MCP server handler for the 'mysql_query' tool call. Parses arguments and delegates to MySQLClient.executeReadOnlyQuery.
    case 'mysql_query': {
      const sql = String(args.sql);
      const params = Array.isArray(args.params) ? args.params : undefined;
      debugLog('Executing mysql_query');
      const result = await mysql.executeReadOnlyQuery(sql, params);
      return {
        content: [
          { type: 'text', text: JSON.stringify(result, null, 2) },
        ],
      };
    }
  • Core helper function implementing the read-only SQL query execution with safety checks for single statement and read-only operations.
    async executeReadOnlyQuery(sql: string, params?: any[]): Promise<any[]> {
      const trimmed = sql.trim();
      if (!trimmed) {
        throw new Error('SQL is empty');
      }
    
      // Disallow multiple statements entirely for safety
      if (trimmed.includes(';')) {
        // Allow a trailing semicolon only
        const statements = trimmed.split(';').filter(s => s.trim().length > 0);
        if (statements.length > 1) {
          throw new Error('Multiple statements are not allowed. Submit a single read-only query.');
        }
      }
    
      const firstToken = trimmed
        .replace(/^\/\*[\s\S]*?\*\//g, '') // strip block comments
        .replace(/^--.*$/gm, '') // strip line comments
        .trim()
        .toLowerCase()
        .split(/\s+/)[0];
    
      const allowed = new Set(['select', 'show', 'describe', 'desc', 'explain']);
      if (!allowed.has(firstToken)) {
        throw new Error('Only read-only queries are permitted (SELECT/SHOW/DESCRIBE/EXPLAIN).');
      }
    
      return await this.query(sql, params);
    }
  • Input schema definition for the mysql_query tool, specifying sql and optional params.
    {
      name: 'mysql_query',
      description: 'Execute a read-only SQL query against the Local WordPress database',
      inputSchema: {
        type: 'object',
        properties: {
          sql: {
            type: 'string',
            description: 'Single read-only SQL statement (SELECT/SHOW/DESCRIBE/EXPLAIN).',
          },
          params: {
            type: 'array',
            description: 'Optional parameter values for placeholders (?).',
            items: { type: 'string' },
          },
        },
        required: ['sql'],
      },
    },
  • src/index.ts:97-101 (registration)
    Registration of the listTools handler, which returns the tools array including mysql_query.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools,
      };
    });
  • Underlying query execution method used by executeReadOnlyQuery.
    async query<T = any>(sql: string, params?: any[]): Promise<T[]> {
      if (!this.connection) {
        throw new Error('Not connected to database');
      }
    
      try {
        const [rows] = await this.connection.execute(sql, params);
        return rows as T[];
      } catch (error: any) {
        throw new Error(`Query failed: ${error.message}`);
      }
    }
Behavior4/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 successfully communicates key behavioral traits: the read-only nature (preventing data modification), the database target (Local WordPress), and the supported SQL statement types. It doesn't mention performance characteristics, error handling, or result formatting, but provides sufficient core behavioral information for safe usage.

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, well-structured sentence that efficiently communicates the tool's purpose, constraints, and target without any wasted words. It's front-loaded with the core functionality and includes essential qualifiers in a natural flow, making every word earn its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (SQL execution with 2 parameters), no annotations, and no output schema, the description provides adequate but minimal information. It covers the core purpose and constraints but doesn't explain what the tool returns (query results format), error conditions, or connection details. For a database query tool without output schema, more return value information would be beneficial.

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?

The schema description coverage is 100%, so both parameters (sql and params) are fully documented in the schema. The description doesn't add any parameter-specific information beyond what's already in the schema descriptions, such as examples or additional constraints. This meets the baseline expectation when schema documentation is comprehensive.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Execute a read-only SQL query') and target resource ('against the Local WordPress database'), distinguishing it from the sibling tool mysql_schema which likely handles schema operations rather than query execution. It uses precise terminology that leaves no ambiguity about the tool's function.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context by specifying 'read-only SQL query' and listing allowed statement types (SELECT/SHOW/DESCRIBE/EXPLAIN), which implicitly guides when to use this tool. However, it doesn't explicitly state when NOT to use it or mention alternatives like the mysql_schema sibling tool for schema-related operations, which would be needed for a perfect score.

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/verygoodplugins/mcp-local-wp'

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