Skip to main content
Glama

mysql_query

Execute read-only SQL queries (SELECT/SHOW/DESCRIBE/EXPLAIN) against a local WordPress database for data analysis and debugging.

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

  • The handler case for 'mysql_query' in the CallToolRequestSchema handler. It extracts the 'sql' and optional 'params' from arguments, calls mysql.executeReadOnlyQuery(), and returns the result as JSON.
    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) },
        ],
      };
    }
  • Tool registration schema for mysql_query. Defines inputSchema with required 'sql' (string) and optional 'params' (array of strings). Declares the tool as read-only (SELECT/SHOW/DESCRIBE/EXPLAIN).
    const tools: Tool[] = [
      {
        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:81-131 (registration)
    Tool is registered in the 'tools' array with name 'mysql_query' and its schema, then exposed via ListToolsRequestSchema handler.
    const tools: Tool[] = [
      {
        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'],
        },
      },
      {
        name: 'mysql_schema',
        description: 'Inspect database schema. Without args: lists tables. With table: shows columns and indexes.',
        inputSchema: {
          type: 'object',
          properties: {
            table: {
              type: 'string',
              description: 'Optional table name to inspect',
            },
          },
        },
      },
      {
        name: 'mysql_current_site',
        description:
          'Get information about the currently connected Local WordPress site, including how it was selected',
        inputSchema: {
          type: 'object',
          properties: {},
        },
      },
      {
        name: 'mysql_list_sites',
        description: 'List all available Local WordPress sites and their running status',
        inputSchema: {
          type: 'object',
          properties: {},
        },
      },
    ];
  • The executeReadOnlyQuery method on MySQLClient that performs safety checks (no multiple statements, only SELECT/SHOW/DESCRIBE/EXPLAIN allowed) before executing the query.
    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);
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Declares 'read-only', implying non-destructive behavior. Without annotations, description carries full burden; lacks details on error behavior, return format, or connection specifics.

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?

Single sentence front-loads the action and scope, no wasted words.

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?

Lacks output shape description (since no output schema), missing error behavior details. Adequate for simple query but could be more complete for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with descriptions. Description adds value by restricting sql to allowed commands (SELECT/SHOW/DESCRIBE/EXPLAIN), going beyond schema's generic 'Single read-only SQL statement'.

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?

Clear action verb 'Execute', specific object 'read-only SQL query', and context 'Local WordPress database'. Distinguishes from siblings which focus on current site, listing sites, and schema.

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

Usage Guidelines3/5

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

Explicitly lists allowed SQL commands (SELECT/SHOW/DESCRIBE/EXPLAIN) indicating read-only usage. However, no guidance on when to use this tool versus siblings like mysql_schema for schema exploration.

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