mysql_update
Update MySQL table data using specific conditions and values. Simplifies modifying database records through structured input for efficient data management in MySQL MCP Server.
Instructions
更新表数据
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | 要更新的数据 | |
| tableName | Yes | 表名称 | |
| where | Yes | 更新条件 |
Input Schema (JSON Schema)
{
"properties": {
"data": {
"description": "要更新的数据",
"type": "object"
},
"tableName": {
"description": "表名称",
"type": "string"
},
"where": {
"description": "更新条件",
"type": "object"
}
},
"required": [
"tableName",
"data",
"where"
],
"type": "object"
}
Implementation Reference
- src/server.ts:435-452 (handler)The handler function that implements the mysql_update tool. It constructs an UPDATE SQL statement from the provided data and where conditions, executes it using the DatabaseManager, and returns the number of affected rows.private async handleUpdate(args: { tableName: string; data: any; where: any }): Promise<any> { const setClause = Object.keys(args.data).map(key => `\`${key}\` = ?`).join(', '); const whereClause = Object.keys(args.where).map(key => `\`${key}\` = ?`).join(' AND '); const sql = `UPDATE \`${args.tableName}\` SET ${setClause} WHERE ${whereClause}`; const params = [...Object.values(args.data), ...Object.values(args.where)]; const result = await this.dbManager.query(sql, params); return { content: [ { type: 'text', text: `成功更新 ${result.affectedRows} 行数据`, }, ], }; }
- src/server.ts:174-182 (schema)Input schema for the mysql_update tool, defining parameters: tableName (string), data (object), where (object).inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: '表名称' }, data: { type: 'object', description: '要更新的数据' }, where: { type: 'object', description: '更新条件' }, }, required: ['tableName', 'data', 'where'], },
- src/server.ts:171-183 (registration)Registration of the mysql_update tool in the ListTools response, including name, description, and input schema.{ name: 'mysql_update', description: '更新表数据', inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: '表名称' }, data: { type: 'object', description: '要更新的数据' }, where: { type: 'object', description: '更新条件' }, }, required: ['tableName', 'data', 'where'], }, },
- src/server.ts:255-256 (registration)Dispatch case in the CallToolRequestSchema handler that routes mysql_update calls to the handleUpdate method.case 'mysql_update': return await this.handleUpdate(args as any);