Skip to main content
Glama
alittleyellowkevin

MySQL MCP Server

delete_data

Remove records from MySQL database tables using SQL DELETE statements to manage data cleanup and maintenance.

Instructions

从 MySQL 数据库表中删除数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes要执行的 SQL DELETE FROM 语句

Implementation Reference

  • Implements the core logic for the 'delete_data' tool: validates input arguments, checks if the SQL query starts with 'DELETE FROM', executes the query on the MySQL connection pool, logs the transaction, handles errors, and returns a structured success or error response.
    private async handleDeleteData(request: any, transactionId: string) {
      if (!isValidSqlQueryArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'SQL 查询参数无效。'
        );
      }
    
      const query = request.params.arguments.query;
    
      if (!isDeleteQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'delete_data 工具仅允许 DELETE FROM 查询。'
        );
      }
    
      console.error(`[${transactionId}] 执行 DELETE 查询: ${query}`);
    
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] 数据删除成功`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: '数据删除成功',
                result
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[${transactionId}] 查询出错:`, error);
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `MySQL 错误: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • Defines the metadata (name, description) and input schema (object with required 'query' string field) for the 'delete_data' tool, returned in response to list_tools requests.
    {
      name: 'delete_data',
      description: '从 MySQL 数据库表中删除数据',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '要执行的 SQL DELETE FROM 语句',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:204-205 (registration)
    Registers the dispatching of 'delete_data' tool calls to the specific handleDeleteData handler function within the CallToolRequestSchema request handler switch statement.
    case 'delete_data':
      return this.handleDeleteData(request, transactionId);
  • Helper function specifically used by the delete_data handler to validate that the provided SQL query is a DELETE FROM statement.
    const isDeleteQuery = (query: string): boolean =>
      query.trim().toLowerCase().startsWith('delete from');
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. While '删除数据' clearly indicates a destructive operation, it doesn't specify permissions required, whether deletions are reversible, transaction behavior, error handling, or what happens on success/failure. For a destructive tool with zero annotation coverage, this is inadequate.

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, efficient Chinese sentence that directly states the tool's purpose with zero wasted words. It's appropriately sized for a simple tool with one parameter and gets straight to the point.

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 destructive database operation with no annotations and no output schema, the description is insufficient. It doesn't explain what happens after deletion, return values, error conditions, or safety considerations. Given the high-risk nature of data deletion and lack of structured metadata, more contextual information is needed.

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%, so the schema already documents the single 'query' parameter as a SQL DELETE FROM statement. The description adds no additional parameter semantics beyond what's in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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 clearly states the action ('删除数据' - delete data) and target resource ('从 MySQL 数据库表中' - from MySQL database table). It distinguishes from siblings like insert_data and update_data by specifying deletion. However, it doesn't explicitly differentiate from execute_sql or run_sql_query which could also perform deletions.

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 like execute_sql or run_sql_query. It doesn't mention prerequisites, when-not-to-use scenarios, or compare functionality with sibling tools. The agent must infer usage from the tool name alone.

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