Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_insert

Add data to MySQL database tables by specifying the table name and data array. This tool enables inserting records into MySQL databases through structured data input.

Instructions

插入数据到表

Input Schema

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

Implementation Reference

  • The handler function that implements the 'mysql_insert' tool logic. It dynamically generates INSERT SQL from the table name and data array, executes batched inserts using parameterized queries via DatabaseManager, and returns the number of affected rows.
    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}`, }, ], }; }
  • The schema definition for the 'mysql_insert' tool, including input schema specifying tableName (string) and data (array of objects). This is part of the tools list returned by ListToolsRequest.
    { 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)
    Registration of the 'mysql_insert' tool handler in the switch statement within the CallToolRequestSchema handler, dispatching to the handleInsert method.
    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