Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_query

Execute SQL queries to retrieve, insert, update, or delete data in MySQL databases. Supports parameterized queries for secure database operations.

Instructions

执行 SQL 查询

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL 查询语句
paramsNo参数化查询的参数(可选)

Implementation Reference

  • Input schema definition for the 'mysql_query' tool, including name, description, and input parameters (sql and optional params).
    {
      name: 'mysql_query',
      description: '执行 SQL 查询',
      inputSchema: {
        type: 'object',
        properties: {
          sql: { type: 'string', description: 'SQL 查询语句' },
          params: { 
            type: 'array', 
            description: '参数化查询的参数(可选)',
            items: { type: 'string' }
          },
        },
        required: ['sql'],
      },
    },
  • src/server.ts:251-252 (registration)
    Dispatches the 'mysql_query' tool call to the handleQuery method.
    case 'mysql_query':
      return await this.handleQuery(args as any);
  • Executes the mysql_query tool: validates SQL, runs query via DatabaseManager, formats and returns the result as MCP content.
    private async handleQuery(args: { sql: string; params?: any[] }): Promise<any> {
      validateSQL(args.sql);
      const result = await this.dbManager.query(args.sql, args.params);
      
      return {
        content: [
          {
            type: 'text',
            text: `${formatQueryResult(result)}\n\n查询结果:\n${JSON.stringify(result.rows, null, 2)}`,
          },
        ],
      };
    }
  • Core query execution method in DatabaseManager using mysql2 pool.execute, handles both SELECT and mutations.
    async query(sql: string, params?: any[]): Promise<QueryResult> {
      if (!this.pool) {
        throw new Error('数据库未连接,请先调用 connect() 方法');
      }
    
      try {
        const [rows, fields] = await this.pool.execute(sql, params);
        
        if (Array.isArray(rows)) {
          return {
            rows: rows as any[],
            fields: fields as any[]
          };
        } else {
          // 对于 INSERT, UPDATE, DELETE 等操作
          const result = rows as mysql.ResultSetHeader;
          return {
            rows: [],
            fields: [],
            affectedRows: result.affectedRows,
            insertId: result.insertId
          };
        }
      } catch (error) {
        throw new Error(`SQL 执行失败: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool executes SQL queries but doesn't describe what happens (e.g., returns results for SELECT, affects rows for DML, may require authentication, could have side effects like data modification, or potential error handling). For a tool with no annotations and potential write operations, 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 extremely concise with a single phrase ('执行 SQL 查询'), which is front-loaded and wastes no words. It efficiently conveys the core action without unnecessary elaboration, making it easy to parse quickly.

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 (which can include read/write operations, error cases, and result formats), no annotations, no output schema, and a vague description, the description is incomplete. It doesn't explain return values, error behavior, or safety considerations, leaving significant gaps for an AI agent to understand how to use the tool effectively.

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%, with clear descriptions for both parameters ('sql' as SQL query statement and 'params' as optional parameters for parameterized queries). The description adds no additional meaning beyond what the schema provides, such as examples or constraints on SQL syntax. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

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

Purpose3/5

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

The description '执行 SQL 查询' (Execute SQL query) states a clear verb ('execute') and resource ('SQL query'), but it's vague about what types of queries are supported (e.g., SELECT, INSERT, UPDATE, DELETE) and doesn't distinguish this from sibling tools like mysql_insert or mysql_update. It provides basic purpose but lacks specificity.

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 offers no guidance on when to use this tool versus alternatives. It doesn't mention that this is a general-purpose query tool compared to more specific siblings like mysql_insert or mysql_update, nor does it provide any context about prerequisites (e.g., connection status) or exclusions. There's no usage advice beyond the basic action.

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/pickstar-2002/mysql-mcp'

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