Skip to main content
Glama
sam2332

SQLite MCP Server

by sam2332

connect_database

Connect to a SQLite database file to enable interaction with its data, including querying, listing tables, and describing schemas for efficient database management.

Instructions

Connect to a SQLite database file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the SQLite database file
readonlyNoOpen database in read-only mode

Implementation Reference

  • The handler function that connects to the specified SQLite database file using better-sqlite3. It closes any existing connection, resolves the path, opens the DB with optional readonly mode, tests the connection by querying the SQLite version, and returns a success message.
    private async connectDatabase(args: { path: string; readonly?: boolean }): Promise<CallToolResult> { try { if (this.db) { this.db.close(); } const dbPath = resolve(args.path); this.db = new Database(dbPath, { readonly: args.readonly || false }); // Test the connection const result = this.db.prepare("SELECT sqlite_version() as version").get() as { version: string }; return { content: [ { type: "text", text: `Successfully connected to database: ${dbPath}\nSQLite version: ${result.version}`, } satisfies TextContent, ], }; } catch (error) { throw new Error(`Failed to connect to database: ${error instanceof Error ? error.message : String(error)}`); } }
  • Input schema definition for the connect_database tool, specifying an object with required 'path' (string) and optional 'readonly' (boolean) properties.
    inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the SQLite database file", }, readonly: { type: "boolean", description: "Open database in read-only mode", default: false, }, }, required: ["path"], },
  • src/index.ts:59-77 (registration)
    Tool registration in the ListToolsRequestHandler, defining name, description, and input schema for connect_database.
    { name: "connect_database", description: "Connect to a SQLite database file", inputSchema: { type: "object", properties: { path: { type: "string", description: "Path to the SQLite database file", }, readonly: { type: "boolean", description: "Open database in read-only mode", default: false, }, }, required: ["path"], }, },
  • src/index.ts:162-164 (registration)
    Dispatcher case in the CallToolRequestHandler switch statement that routes connect_database calls to the connectDatabase method.
    case "connect_database": return await this.connectDatabase(args as { path: string; readonly?: boolean });

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sam2332/mcp-quick-sqlite3'

If you have feedback or need assistance with the MCP directory API, please join our Discord server