test_execute
Test SQL queries for execution feasibility in MySQL databases with automatic rollback to verify query validity without data changes.
Instructions
Checks if an SQL query can be executed and rolls back afterward.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes |
Implementation Reference
- src/index.ts:98-115 (handler)The switch case that implements the test_execute tool logic: starts a transaction, attempts to execute the SQL query, rolls back in finally, returns error if failed or success message if successful.case "test_execute": { const sql = request.params.arguments?.sql as string; await connection.query('START TRANSACTION'); try { await connection.query(sql); } catch (error) { return { content: [{ type: "text", text: `Failed to execute SQL. error: ${error}` }], isError: true, }; } finally { await connection.query('ROLLBACK'); } return { content: [{ type: "text", text: "The update SQL query can be executed." }], isError: false, }; }
- src/index.ts:53-59 (schema)Input schema definition for the test_execute tool, requiring a 'sql' string.inputSchema: { type: "object", properties: { sql: { type: "string" }, }, required: ["sql"], },
- src/index.ts:50-60 (registration)Registration of the test_execute tool in the ListTools handler response, including name, description, and input schema.{ name: "test_execute", description: "Checks if an SQL query can be executed and rolls back afterward.", inputSchema: { type: "object", properties: { sql: { type: "string" }, }, required: ["sql"], }, },