Skip to main content
Glama
pickstar-2002

MySQL MCP Server

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
NameRequiredDescriptionDefault
tableNameYes表名称
dataYes要更新的数据
whereYes更新条件

Implementation Reference

  • 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} 行数据`, }, ], }; }
  • 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) => {

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/pickstar-2002/mysql-mcp'

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