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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. '插入数据到表' implies a write/mutation operation, but it doesn't disclose critical traits: whether it requires specific permissions, if it's idempotent, what happens on duplicate keys, error handling, or return values. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient phrase ('插入数据到表') with zero wasted words. It's appropriately sized for a simple tool and front-loads the core action. Every element earns its place, making it highly concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation operation with no annotations and no output schema), the description is incomplete. It doesn't cover behavioral aspects like side effects, error cases, or what to expect upon success. For a database insert tool, this leaves the agent under-informed about critical usage context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters (tableName and data) clearly documented in the schema. The description adds no additional meaning beyond the schema—it doesn't explain parameter relationships, data format examples, or constraints. Baseline 3 is appropriate when the schema does all the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '插入数据到表' (Insert data into table) clearly states the verb ('插入' - insert) and resource ('表' - table), making the purpose immediately understandable. It distinguishes from siblings like mysql_update (modify existing data) and mysql_delete (remove data). However, it doesn't specify what kind of data or table, making it slightly less specific than a perfect 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an established connection via mysql_connect), when to choose insert over update/delete, or any constraints (e.g., table must exist). This leaves the agent with minimal context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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