Skip to main content
Glama
alittleyellowkevin

MySQL MCP Server

insert_data

Insert data into MySQL database tables using SQL INSERT INTO statements to add records and populate tables with new information.

Instructions

向 MySQL 数据库表插入数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes要执行的 SQL INSERT INTO 语句

Implementation Reference

  • The main handler function for the insert_data tool. It validates the input arguments and ensures the query is an INSERT INTO statement, executes the query using the MySQL connection pool, logs the transaction, and returns a JSON-formatted response with the result or an error message.
    private async handleInsertData(request: any, transactionId: string) {
      if (!isValidSqlQueryArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'SQL 查询参数无效。'
        );
      }
    
      const query = request.params.arguments.query;
    
      if (!isInsertQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'insert_data 工具仅允许 INSERT INTO 查询。'
        );
      }
    
      console.error(`[${transactionId}] 执行 INSERT 查询: ${query}`);
    
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] 数据插入成功`);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: '数据插入成功',
                result
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[${transactionId}] 查询出错:`, error);
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `MySQL 错误: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • Input schema for the insert_data tool, defining a required 'query' property of type string for the SQL INSERT INTO statement.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: '要执行的 SQL INSERT INTO 语句',
        },
      },
      required: ['query'],
    },
  • src/index.ts:130-143 (registration)
    Registration of the insert_data tool in the ListTools response, including name, description, and input schema.
    {
      name: 'insert_data',
      description: '向 MySQL 数据库表插入数据',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '要执行的 SQL INSERT INTO 语句',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:200-201 (registration)
    Dispatch registration in the CallToolRequest handler switch statement, routing 'insert_data' calls to the handleInsertData method.
    case 'insert_data':
      return this.handleInsertData(request, transactionId);
  • Helper function that checks if a given SQL query starts with 'insert into' (case-insensitive, trimmed), used for validation in the handler.
    const isInsertQuery = (query: string): boolean =>
      query.trim().toLowerCase().startsWith('insert into');
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. It states this is an insert operation but reveals nothing about permissions required, whether it's idempotent, what happens on constraint violations, transaction behavior, or what the response contains. For a database mutation tool with zero annotation coverage, this leaves critical behavioral aspects unspecified.

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 sentence that states the core purpose without unnecessary words. It's appropriately sized for a simple tool and front-loads the essential information. Every word earns its place in conveying the tool's function.

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?

For a database mutation tool with no annotations, no output schema, and multiple similar siblings, the description is incomplete. It doesn't address critical context like error handling, return values, transaction boundaries, or differentiation from other SQL tools. The agent lacks sufficient information to use this tool effectively in complex scenarios.

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 the single parameter 'query' documented as '要执行的 SQL INSERT INTO 语句' (SQL INSERT INTO statement to execute). The description adds no additional parameter context beyond what the schema already provides. With high schema coverage, the baseline score of 3 is appropriate - the description doesn't enhance parameter understanding but doesn't need to compensate for schema gaps.

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 clearly states the action ('插入数据' - insert data) and target resource ('向 MySQL 数据库表' - to MySQL database table), making the purpose immediately understandable. It doesn't explicitly distinguish from siblings like 'update_data' or 'delete_data', but the verb 'insert' provides inherent differentiation. This is better than vague but lacks explicit sibling comparison.

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 like 'update_data', 'delete_data', or 'execute_sql'. There's no mention of prerequisites, appropriate contexts, or exclusions. The agent must infer usage from the tool name alone, which is insufficient given multiple SQL-related siblings.

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/alittleyellowkevin/Mysql-MCP'

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