Skip to main content
Glama

update_data

Modify existing records in MySQL database tables using SQL UPDATE queries to change data values.

Instructions

Updates data in a table in the MySQL database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL UPDATE query to execute.

Implementation Reference

  • src/index.ts:136-149 (registration)
    Tool registration in the listTools response, defining name, description, and input schema for 'update_data'.
    {
      name: 'update_data',
      description: 'Updates data in a table in the MySQL database.',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'The SQL UPDATE query to execute.',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:193-194 (registration)
    Dispatch registration in the CallToolRequest handler switch statement, routing 'update_data' to its handler.
    case 'update_data':
      return this.handleUpdateData(request, transactionId);
  • Core handler implementation for 'update_data': validates arguments and query type, executes UPDATE on MySQL pool, returns formatted success/error response.
    private async handleUpdateData(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 (!isUpdateQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Only UPDATE queries are allowed with update_data tool.'
        );
      }
    
      console.error(`[${transactionId}] Executing UPDATE query: ${query}`);
      
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] Data updated successfully`);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: 'Data updated 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;
      }
    }
  • Helper function used by update_data handler to validate if the provided query starts with 'update'.
    const isUpdateQuery = (query: string): boolean => 
      query.trim().toLowerCase().startsWith('update');

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