Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_insert

Insert data into MySQL tables using a structured JSON input. Specify the table name and data array to execute the operation efficiently. Part of the MySQL MCP Server for database management.

Instructions

插入数据到表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes要插入的数据数组
tableNameYes表名称

Implementation Reference

  • The `handleInsert` method that executes the mysql_insert tool. Constructs parameterized INSERT SQL statements based on the table name and data array, performs batch inserts using dbManager.query, accumulates affected rows, and returns a success message.
    private async handleInsert(args: { tableName: string; data: any[] }): Promise<any> { if (!Array.isArray(args.data) || args.data.length === 0) { throw new Error('数据必须是非空数组'); } const columns = Object.keys(args.data[0]); const placeholders = columns.map(() => '?').join(', '); const values = args.data.map(row => columns.map(col => row[col])); let affectedRows = 0; for (const rowValues of values) { const sql = `INSERT INTO \`${args.tableName}\` (\`${columns.join('`, `')}\`) VALUES (${placeholders})`; const result = await this.dbManager.query(sql, rowValues); affectedRows += result.affectedRows || 0; } return { content: [ { type: 'text', text: `成功插入 ${affectedRows} 行数据到表 ${args.tableName}`, }, ], }; }
  • Input schema definition for the mysql_insert tool in the ListTools response, specifying required tableName (string) and data (array of objects).
    { name: 'mysql_insert', description: '插入数据到表', inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: '表名称' }, data: { type: 'array', description: '要插入的数据数组', items: { type: 'object' } }, }, required: ['tableName', 'data'], }, },
  • src/server.ts:253-254 (registration)
    Dispatches calls to the mysql_insert tool to the handleInsert method in the CallToolRequestSchema switch statement.
    case 'mysql_insert': return await this.handleInsert(args as 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