execute_query
Run SQL queries (INSERT, UPDATE, DELETE) on SQLite databases using the MCP Server to manage and manipulate data efficiently.
Instructions
Execute any SQL query (INSERT, UPDATE, DELETE, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL query to execute |
Implementation Reference
- src/index.ts:342-361 (handler)Implements the core logic for executing any SQL query (INSERT, UPDATE, DELETE, etc.) on the connected SQLite database using better-sqlite3's prepare().run(), returning the number of changes and last insert row ID.private async executeQuery(args: { query: string }): Promise<CallToolResult> { if (!this.db) { throw new Error("No database connected. Use connect_database first."); } try { const result = this.db.prepare(args.query).run(); return { content: [ { type: "text", text: `Query executed successfully. Changes: ${result.changes}, Last insert row ID: ${result.lastInsertRowid}`, } satisfies TextContent, ], }; } catch (error) { throw new Error(`Query execution failed: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:119-132 (schema)Defines the tool metadata including name, description, and input schema for 'execute_query', which requires a single 'query' string parameter.{ name: "execute_query", description: "Execute any SQL query (INSERT, UPDATE, DELETE, etc.)", inputSchema: { type: "object", properties: { query: { type: "string", description: "SQL query to execute", }, }, required: ["query"], }, },
- src/index.ts:174-175 (registration)In the CallToolRequest handler's switch statement, routes calls to the 'execute_query' tool to the executeQuery method.case "execute_query": return await this.executeQuery(args as { query: string });