Skip to main content
Glama
alittleyellowkevin

MySQL MCP Server

execute_sql

Execute non-SELECT SQL statements like ALTER TABLE or DROP to modify MySQL database structure and data.

Instructions

执行任意非 SELECT 的 SQL 语句(如 ALTER TABLE、DROP 等)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes要执行的 SQL 语句

Implementation Reference

  • Primary handler for 'execute_sql' tool: validates input, forbids SELECT queries, executes SQL on MySQL pool, returns JSON result or error.
    private async handleExecuteSql(request: any, transactionId: string) {
      if (!isValidSqlQueryArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'SQL 查询参数无效。'
        );
      }
    
      const query = request.params.arguments.query;
    
      if (isReadOnlyQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'execute_sql 工具不允许 SELECT 查询。'
        );
      }
    
      console.error(`[${transactionId}] 执行通用 SQL: ${query}`);
    
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] SQL 执行成功`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: 'SQL 执行成功',
                result
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[${transactionId}] SQL 执行出错:`, error);
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `MySQL 错误: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • src/index.ts:172-185 (registration)
    Tool registration in ListToolsResponse: defines name, description, and inputSchema for execute_sql.
    {
      name: 'execute_sql',
      description: '执行任意非 SELECT 的 SQL 语句(如 ALTER TABLE、DROP 等)',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '要执行的 SQL 语句',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:206-207 (registration)
    Dispatch/registration in CallToolRequest handler switch statement.
    case 'execute_sql':
      return this.handleExecuteSql(request, transactionId);
  • Input schema: requires 'query' string for SQL statement.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: '要执行的 SQL 语句',
        },
      },
      required: ['query'],
    },
  • Helper function to validate SQL query arguments used in execute_sql handler.
    const isValidSqlQueryArgs = (args: any): args is SqlQueryArgs =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.query === 'string';
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. While it indicates this executes SQL statements (implying write/mutation operations), it doesn't disclose important behavioral traits like authentication requirements, transaction handling, error behavior, or whether changes are reversible. For a tool that can execute destructive operations like DROP, this is a significant gap.

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 (one sentence) and front-loaded with all essential information. Every word earns its place by specifying the tool's scope (non-SELECT SQL), providing examples, and distinguishing from alternatives. There's zero waste or redundancy.

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 tool that can execute potentially destructive SQL operations (DROP, ALTER TABLE) with no annotations and no output schema, the description is incomplete. It doesn't address critical context like what permissions are required, whether transactions are supported, what happens on errors, or what the return format looks like. The description does well on purpose and usage but misses important behavioral 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?

Schema description coverage is 100% with the single 'query' parameter well-documented in the schema. The description doesn't add any meaningful parameter semantics beyond what the schema already provides ('要执行的 SQL 语句'). The baseline score of 3 is appropriate when the schema does the heavy lifting for parameter documentation.

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 tool's purpose with specific verbs ('执行任意非 SELECT 的 SQL 语句') and resources (SQL statements like ALTER TABLE, DROP). It explicitly distinguishes from SELECT operations, which helps differentiate from sibling tools like 'run_sql_query' that likely handles SELECT queries.

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

Usage Guidelines5/5

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

The description provides explicit usage guidelines by stating '非 SELECT 的 SQL 语句' (non-SELECT SQL statements) and giving examples like ALTER TABLE and DROP. This clearly indicates when to use this tool versus alternatives like 'run_sql_query' (likely for SELECT) and other siblings that handle specific operations (create_table, delete_data, etc.).

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/alittleyellowkevin/Mysql-MCP'

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