Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

execute

Execute INSERT, UPDATE, DELETE or other modifying SQL queries in MySQL databases and return affected rows count for data manipulation operations.

Instructions

Execute an INSERT, UPDATE, DELETE or other modifying query. Returns affected rows count.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesSQL query to execute
paramsNoQuery parameters for prepared statement

Implementation Reference

  • The main handler logic for the 'execute' tool. It retrieves the database pool, checks SQL permissions, executes the modifying SQL query (INSERT/UPDATE/DELETE), and returns structured output with affected rows, insert ID, and changed rows.
    async ({ sql, params }) => { const p = await getPool(); // Check if the operation is allowed checkSqlPermission(sql); const [result] = await p.execute<ResultSetHeader>(sql, params || []); const output = { affectedRows: result.affectedRows, insertId: result.insertId, changedRows: result.changedRows, }; return { content: [ { type: "text" as const, text: JSON.stringify(output, null, 2), }, ], structuredContent: output, }; }
  • Zod schema defining the input parameters for the 'execute' tool: sql (required string) and optional params array.
    { sql: z.string().describe("SQL query to execute"), params: z.array(z.unknown()).optional().describe("Query parameters for prepared statement"), },
  • src/index.ts:175-206 (registration)
    Registration of the 'execute' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool( "execute", "Execute an INSERT, UPDATE, DELETE or other modifying query. Returns affected rows count.", { sql: z.string().describe("SQL query to execute"), params: z.array(z.unknown()).optional().describe("Query parameters for prepared statement"), }, async ({ sql, params }) => { const p = await getPool(); // Check if the operation is allowed checkSqlPermission(sql); const [result] = await p.execute<ResultSetHeader>(sql, params || []); const output = { affectedRows: result.affectedRows, insertId: result.insertId, changedRows: result.changedRows, }; return { content: [ { type: "text" as const, text: JSON.stringify(output, null, 2), }, ], structuredContent: output, }; } );

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

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