update_data
Execute SQL UPDATE queries to modify records in MySQL databases. Designed for use with the MySQL MCP Server, enabling efficient data management and updates.
Instructions
Updates data in a table in the MySQL database.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL UPDATE query to execute. |
Input Schema (JSON Schema)
{
"properties": {
"query": {
"description": "The SQL UPDATE query to execute.",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/index.ts:364-414 (handler)Executes the UPDATE SQL query after validation, handles errors, and returns formatted response with transaction logging.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; } }
- src/index.ts:139-148 (schema)Input schema definition for the update_data tool, specifying a required 'query' string parameter.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The SQL UPDATE query to execute.', }, }, required: ['query'], },
- src/index.ts:136-149 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ 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)Routing in CallToolRequestHandler switch statement that calls the update_data handler.case 'update_data': return this.handleUpdateData(request, transactionId);
- src/index.ts:42-44 (helper)Helper function to validate if a query is an UPDATE statement, used in the handler.const isUpdateQuery = (query: string): boolean => query.trim().toLowerCase().startsWith('update');