execute
Execute INSERT, UPDATE, or DELETE queries to modify data in MySQL databases through the MCP MySQL Server.
Instructions
Execute an INSERT, UPDATE, or DELETE query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query (INSERT, UPDATE, DELETE) | |
| params | No | Query parameters (optional) |
Implementation Reference
- src/index.ts:285-316 (handler)Implements the core logic for the 'execute' tool: validates input, ensures DB connection, executes non-SELECT SQL queries (INSERT/UPDATE/DELETE), and returns JSON-stringified results.private async handleExecute(args: any) { await this.ensureConnection(); if (!args.sql) { throw new McpError(ErrorCode.InvalidParams, 'SQL query is required'); } const sql = args.sql.trim().toUpperCase(); if (sql.startsWith('SELECT')) { throw new McpError( ErrorCode.InvalidParams, 'Use query tool for SELECT statements' ); } try { const [result] = await this.connection!.query(args.sql, args.params || []); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Query execution failed: ${getErrorMessage(error)}` ); } }
- src/index.ts:146-166 (schema)Schema definition for the 'execute' tool, including name, description, and input schema specifying required 'sql' string and optional 'params' array.{ name: 'execute', description: 'Execute an INSERT, UPDATE, or DELETE query', inputSchema: { type: 'object', properties: { sql: { type: 'string', description: 'SQL query (INSERT, UPDATE, DELETE)', }, params: { type: 'array', items: { type: ['string', 'number', 'boolean', 'null'], }, description: 'Query parameters (optional)', }, }, required: ['sql'], }, },
- src/index.ts:199-200 (registration)Registers the 'execute' tool handler in the CallToolRequestSchema switch statement, routing calls to handleExecute.case 'execute': return await this.handleExecute(request.params.arguments);