Skip to main content
Glama

insert_data

Execute SQL INSERT queries to add new records into MySQL database tables, enabling data population and storage operations.

Instructions

Inserts data into a table in the MySQL database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL INSERT INTO query to execute.

Implementation Reference

  • The primary handler function for the 'insert_data' tool. It validates the input arguments, checks that the SQL query starts with 'INSERT INTO', executes the query using the MySQL connection pool, logs the transaction, and returns a success response with the query result or an error message.
    private async handleInsertData(request: any, transactionId: string) {
      if (!isValidSqlQueryArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid SQL query arguments.'
        );
      }
    
      const query = request.params.arguments.query;
      
      if (!isInsertQuery(query)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Only INSERT INTO queries are allowed with insert_data tool.'
        );
      }
    
      console.error(`[${transactionId}] Executing INSERT query: ${query}`);
      
      try {
        const [result] = await this.pool.query(query);
        console.error(`[${transactionId}] Data inserted successfully`);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                message: 'Data inserted successfully',
                result
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[${transactionId}] Query error:`, error);
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `MySQL error: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • Input schema definition for the 'insert_data' tool, specifying an object with a required 'query' property of type string for the INSERT SQL statement.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'The SQL INSERT INTO query to execute.',
        },
      },
      required: ['query'],
    },
  • src/index.ts:122-135 (registration)
    Registration of the 'insert_data' tool in the tools list returned by ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: 'insert_data',
      description: 'Inserts data into a table in the MySQL database.',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'The SQL INSERT INTO query to execute.',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:191-192 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that routes calls to 'insert_data' to the handleInsertData method.
    case 'insert_data':
      return this.handleInsertData(request, transactionId);
  • Helper function used by the handler to validate that the provided query is an INSERT INTO statement.
    // Check if query is for inserting data
    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. While 'inserts data' implies a write/mutation operation, it doesn't address critical aspects like required permissions, whether the operation is idempotent, transaction handling, error behavior, or what happens on success/failure. For a database mutation tool, this leaves significant gaps in understanding how it behaves.

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 with zero wasted words. It's appropriately sized for a simple tool and front-loads the essential information (action + target) immediately.

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 and no output schema, the description is incomplete. It doesn't explain what happens after insertion (e.g., returns inserted row count, error messages, or confirmation), nor does it address behavioral aspects like transaction safety or permission requirements. The combination of mutation nature and lack of structured metadata demands more descriptive 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 the single parameter 'query' fully documented in the schema. The description adds no additional parameter information beyond what the schema provides, such as query format examples or constraints. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

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 ('inserts data') and target resource ('into a table in the MySQL database'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from sibling tools like 'execute_sql' or 'run_sql_query' which might also handle INSERT operations, leaving some ambiguity about specialization.

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 'execute_sql', 'update_data', or 'create_table'. It doesn't mention prerequisites, exclusions, or specific contexts where this tool is preferred, leaving the agent to guess based on tool names alone.

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/michael7736/mysql-mcp-server'

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