delete_data
Remove records from MySQL database tables using SQL DELETE queries to manage data cleanup, compliance, or maintenance tasks.
Instructions
Deletes data from a table in the MySQL database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL DELETE FROM query to execute. |
Implementation Reference
- src/index.ts:417-466 (handler)The primary handler for the 'delete_data' tool. It validates the SQL query arguments, ensures it's a DELETE FROM query using isDeleteQuery helper, executes the query on the MySQL connection pool, logs the transaction, and returns a structured response with success/error details including the MySQL result.private async handleDeleteData(request: any, transactionId: string) { if (!isValidSqlQueryArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid SQL query arguments.' ); } const query = request.params.arguments.query; if (!isDeleteQuery(query)) { throw new McpError( ErrorCode.InvalidParams, 'Only DELETE FROM queries are allowed with delete_data tool.' ); } console.error(`[${transactionId}] Executing DELETE query: ${query}`); try { const [result] = await this.pool.query(query); console.error(`[${transactionId}] Data deleted successfully`); return { content: [ { type: 'text', text: JSON.stringify({ success: true, message: 'Data deleted successfully', result }, null, 2), }, ], }; } catch (error) { console.error(`[${transactionId}] Query error:`, error); if (error instanceof Error) { return { content: [ { type: 'text', text: `MySQL error: ${error.message}`, }, ], isError: true, }; } throw error; }
- src/index.ts:150-163 (schema)The JSON schema definition for the 'delete_data' tool, including name, description, and input schema expecting a 'query' string parameter. This is returned in the ListTools response.{ name: 'delete_data', description: 'Deletes data from a table in the MySQL database.', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The SQL DELETE FROM query to execute.', }, }, required: ['query'], }, },
- src/index.ts:195-196 (registration)Registration of the 'delete_data' tool handler within the CallToolRequestSchema request handler switch statement, dispatching tool calls to the handleDeleteData method.case 'delete_data': return this.handleDeleteData(request, transactionId);
- src/index.ts:46-48 (helper)Helper function used by the delete_data handler to validate that the provided SQL query starts with 'DELETE FROM' (case-insensitive).const isDeleteQuery = (query: string): boolean => query.trim().toLowerCase().startsWith('delete from');