execute_query
Execute SQL queries (INSERT, UPDATE, DELETE) to interact with SQLite databases, enabling data manipulation and management operations.
Instructions
Execute any SQL query (INSERT, UPDATE, DELETE, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL query to execute |
Implementation Reference
- src/index.ts:342-361 (handler)The main handler function that executes the provided SQL query using better-sqlite3's .run() method and returns 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:122-131 (schema)Input schema definition for the execute_query tool, specifying an object with a required 'query' string property.
inputSchema: { type: "object", properties: { query: { type: "string", description: "SQL query to execute", }, }, required: ["query"], }, - src/index.ts:119-132 (registration)Tool registration in the listTools response, defining name, description, and input schema.
{ 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)Dispatch case in the CallToolRequest handler that routes calls to execute_query to the executeQuery method.
case "execute_query": return await this.executeQuery(args as { query: string });