execute
Execute INSERT, UPDATE, or DELETE queries to modify data in MySQL or MongoDB databases through a standardized interface.
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:722-753 (handler)The handler function that executes INSERT, UPDATE, or DELETE SQL queries on a MySQL database connection. Ensures connection, validates non-SELECT query, executes with optional parameters, and returns JSON result.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:280-300 (schema)The input schema for the 'execute' tool, defining required 'sql' string for non-SELECT queries 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:541-542 (registration)Registration in the CallToolRequestHandler switch statement that routes 'execute' tool calls to the handleExecute method.case 'execute': return await this.handleExecute(request.params.arguments);