execute
Run INSERT, UPDATE, or DELETE queries on MySQL databases via the MCP server, enabling direct database modifications with optional parameters for precise command execution.
Instructions
Execute an INSERT, UPDATE, or DELETE query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | No | Query parameters (optional) | |
| sql | Yes | SQL query (INSERT, UPDATE, DELETE) |
Implementation Reference
- src/index.ts:575-584 (handler)The primary handler for the 'execute' tool. Validates SQL type, executes the query via executeQuery helper, and formats the result as JSON text content.private async handleExecute(args: QueryArgs): Promise<QueryResult> { this.validateSqlInput(args.sql, ['INSERT', 'UPDATE', 'DELETE']); const result = await this.executeQuery(args.sql, args.params || []); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
- src/index.ts:396-415 (registration)Tool registration entry in the ListTools handler, specifying name, description, and input schema for the 'execute' tool.{ 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:65-68 (schema)TypeScript interface defining the input arguments for the 'execute' tool (shared with 'query' tool).interface QueryArgs { sql: string; params?: Array<string | number | boolean | null>; }
- src/index.ts:243-250 (helper)Core helper function that executes SQL queries using the MySQL connection pool and handles database errors.private async executeQuery<T>(sql: string, params: any[] = []): Promise<T> { const pool = await this.ensureConnection(); try { const [result] = await pool.query(sql, params); return result as T; } catch (error) { this.handleDatabaseError(error); }
- src/index.ts:523-524 (registration)Dispatch case in the CallTool request handler that routes 'execute' tool calls to the handleExecute method.case 'execute': return await this.handleExecute(request.params.arguments as unknown as QueryArgs);