mysql_update
Modify existing records in MySQL database tables by specifying update conditions and new data values to maintain accurate information.
Instructions
更新表数据
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | 表名称 | |
| data | Yes | 要更新的数据 | |
| where | Yes | 更新条件 |
Implementation Reference
- src/server.ts:435-452 (handler)The main handler function for the 'mysql_update' tool. It constructs an UPDATE SQL statement from the provided 'data' (SET clause) and 'where' (condition), parameterizes it, executes the query via dbManager, 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:171-182 (schema)The input schema definition for the 'mysql_update' tool, specifying tableName, data (fields to update), and where (update condition) as required object properties.{ 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)The switch case registration that dispatches 'mysql_update' tool calls to the handleUpdate method.case 'mysql_update': return await this.handleUpdate(args as any);
- src/server.ts:226-228 (registration)The overall CallToolRequestHandler where 'mysql_update' is handled via switch on tool name.}); this.server.setRequestHandler(CallToolRequestSchema, async (request: any) => {