Skip to main content
Glama

insert_data

Execute SQL INSERT INTO queries to add data into a MySQL database table, simplifying data entry and management within the MySQL MCP Server.

Instructions

Inserts data into a table in the MySQL database.

Input Schema

NameRequiredDescriptionDefault
queryYesThe SQL INSERT INTO query to execute.

Input Schema (JSON Schema)

{ "properties": { "query": { "description": "The SQL INSERT INTO query to execute.", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • src/index.ts:122-135 (registration)
    Registration of the 'insert_data' tool in the ListTools response, 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'], }, },
  • The handler function for 'insert_data' tool: validates input, checks for INSERT query, executes on MySQL pool, returns result or error.
    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 for the 'insert_data' tool, defining the expected 'query' parameter.
    inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The SQL INSERT INTO query to execute.', }, }, required: ['query'], },
  • Helper function to validate if the query is an INSERT INTO statement.
    const isInsertQuery = (query: string): boolean => query.trim().toLowerCase().startsWith('insert into');
  • Helper function to validate SQL query arguments.
    const isValidSqlQueryArgs = (args: any): args is SqlQueryArgs => typeof args === 'object' && args !== null && typeof args.query === 'string';

Other Tools

Related 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