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');

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