execute
Perform INSERT, UPDATE, or DELETE operations on MySQL or MongoDB databases using SQL queries with optional parameters, enabling direct data manipulation through the MCP server.
Instructions
Execute an INSERT, UPDATE, or DELETE query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | No | Query parameters (optional) | |
| sql | Yes | SQL query (INSERT, UPDATE, DELETE) |
Input Schema (JSON Schema)
{
"properties": {
"params": {
"description": "Query parameters (optional)",
"items": {
"type": [
"string",
"number",
"boolean",
"null"
]
},
"type": "array"
},
"sql": {
"description": "SQL query (INSERT, UPDATE, DELETE)",
"type": "string"
}
},
"required": [
"sql"
],
"type": "object"
}
Implementation Reference
- src/index.ts:722-753 (handler)The core handler function that validates the input, ensures database connection, executes non-SELECT SQL queries (INSERT, UPDATE, DELETE), and returns the 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:283-298 (schema)Input schema defining the parameters for the 'execute' tool: required 'sql' string and optional 'params' array.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:280-300 (registration)Registration of the 'execute' tool in the ListTools response, including name, description, and input schema.{ 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)Dispatch registration in the CallTool request handler that routes 'execute' calls to the handleExecute method.case 'execute': return await this.handleExecute(request.params.arguments);