Skip to main content
Glama

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
NameRequiredDescriptionDefault
queryYesThe SQL DELETE FROM query to execute.

Implementation Reference

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

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/michael7736/mysql-mcp-server'

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