delete_data
Executes SQL DELETE FROM queries to remove specific data from a MySQL database, enabling efficient record deletion as part of database management 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-467 (handler)The handler function that executes the delete_data tool. Validates input, checks for DELETE FROM query, executes on MySQL pool, returns JSON result or error.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 (registration)Tool registration in the ListTools response, including name, description, and input schema requiring a 'query' parameter.{ 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:46-48 (helper)Helper function to validate if a SQL query is a DELETE FROM statement, used in delete_data handler.const isDeleteQuery = (query: string): boolean => query.trim().toLowerCase().startsWith('delete from');
- src/index.ts:153-162 (schema)Input schema for delete_data tool: object with required 'query' string property.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The SQL DELETE FROM query to execute.', }, }, required: ['query'], },