### Install and build mcp-server-sqlite Source: https://github.com/ofershap/mcp-server-sqlite/blob/main/README.md Standard npm commands for installing dependencies, checking types, building the project, running tests, formatting code, and linting. ```bash npm install npm run typecheck npm run build npm test npm run format npm run lint ``` -------------------------------- ### Install and Run mcp-sqlite-server with npx Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Run the mcp-sqlite-server directly using npx without requiring a global installation. Alternatively, install it globally using npm. ```bash npx mcp-sqlite-server ``` ```bash npm install -g mcp-sqlite-server ``` -------------------------------- ### Run mcp-sqlite-server Source: https://github.com/ofershap/mcp-server-sqlite/blob/main/README.md Execute this command to start the mcp-sqlite-server. It works with various MCP clients and reads local .db files without authentication. ```bash npx mcp-sqlite-server ``` -------------------------------- ### Explain SQL Query Plan with MCP Tool Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `explain` tool to get the query plan for a given SQL statement. This helps in identifying performance bottlenecks like full table scans or missing indexes. The output is a formatted string detailing the execution steps. ```jsonc // MCP tool call { "tool": "explain", "arguments": { "db": "./data/app.db", "sql": "SELECT u.name, COUNT(o.id) FROM users u JOIN orders o ON o.user_id = u.id GROUP BY u.id" } } // Expected response text: // Query plan: // 2 | 0 | SCAN orders // 3 | 0 | SEARCH users USING INTEGER PRIMARY KEY (rowid=?) // 1 | 0 | USE TEMP B-TREE FOR GROUP BY // Add an index and re-explain to compare plans: // CREATE INDEX idx_orders_user ON orders(user_id); // → 2 | 0 | SEARCH orders USING INDEX idx_orders_user (user_id=?) ``` -------------------------------- ### Development Commands for MCP Server SQLite Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Standard development commands for the MCP Server SQLite project, including dependency installation, type checking, building, testing, and code formatting/linting. ```bash npm install # install dependencies npm run typecheck # TypeScript strict check (no emit) npm run build # compile with tsup → dist/ npm test # run vitest test suite npm run format # prettier write npm run lint # eslint + prettier check ``` -------------------------------- ### Explain SQL Query Plan with TypeScript API Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `explain` function from the core TypeScript API to get the query plan for a SQL statement. This is useful for performance analysis, similar to the MCP tool. The output is a string representing the execution plan. ```typescript import { explain } from "./src/sqlite.js"; const plan: string = explain("./app.db", "SELECT * FROM orders WHERE user_id = 1"); console.log(plan); // "2 | 0 | SCAN orders" (no index) // After adding index: "2 | 0 | SEARCH orders USING INDEX idx_orders_user (user_id=?)" ``` -------------------------------- ### Retrieve Full Database Schema Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the 'schema' tool to get a comprehensive overview of all tables in a SQLite database, including column details and row counts. This is useful for initial database exploration. ```jsonc // MCP tool call { "tool": "schema", "arguments": { "db": "./data/app.db" } } // Expected response text: // Schema: 3 table(s) // // ### orders (1042 rows) // - id (INTEGER) PK // - user_id (INTEGER) NOT NULL // - total (REAL) NOT NULL DEFAULT 0.0 // - created_at (TEXT) // // ### products (58 rows) // - id (INTEGER) PK // - name (TEXT) NOT NULL // - price (REAL) NOT NULL // // ### users (312 rows) // - id (INTEGER) PK // - name (TEXT) // - email (TEXT) // - active (INTEGER) DEFAULT 1 ``` -------------------------------- ### Get Table Information with TypeScript API Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `tableInfo` function to get specific details about a table within a SQLite database. It returns the row count and an array of column definitions, including name, type, and constraints like primary key or not null. ```typescript import { tableInfo, type TableInfo } from "./src/sqlite.js"; const tbl: TableInfo = tableInfo("./app.db", "users"); console.log(tbl.rowCount); // 312 tbl.columns.forEach(c => console.log(`${c.name}: ${c.type}${c.pk ? " PK" : ""}${c.notnull ? " NOT NULL" : ""}`) ); // id: INTEGER PK // name: TEXT // email: TEXT ``` -------------------------------- ### Get Database Schema Information with TypeScript API Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `schema` function to retrieve detailed schema information for a SQLite database. This includes the total number of tables, and for each table, its name, row count, and column definitions. ```typescript import { schema, type SchemaInfo } from "./src/sqlite.js"; const info: SchemaInfo = schema("./app.db"); console.log(info.totalTables); // 3 console.log(info.tables[0].name); // "orders" console.log(info.tables[0].rowCount); // 1042 console.log(info.tables[0].columns[0]); // { name: "id", type: "INTEGER", notnull: false, pk: true, defaultValue: null } ``` -------------------------------- ### explain Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Runs `EXPLAIN QUERY PLAN` on a SQL statement and returns the plan as a formatted string. ```APIDOC ## explain ### Description Runs `EXPLAIN QUERY PLAN` on a SQL statement and returns the plan as a formatted string. This is useful for identifying performance bottlenecks like full table scans or missing indexes. ### Signature `explain(dbPath: string, sql: string): string` ### Parameters - **dbPath** (string) - Required - The path to the SQLite database file. - **sql** (string) - Required - The SQL statement to analyze. ### Returns - **string** - A formatted string representing the query plan. ### Request Example ```typescript import { explain } from "./src/sqlite.js"; const plan = explain("./app.db", "SELECT * FROM orders WHERE user_id = 1"); console.log(plan); ``` ### Response Example ``` 2 | 0 | SCAN orders ``` ### Usage Notes Comparing query plans before and after adding indexes can help optimize database performance. ``` -------------------------------- ### List SQLite Databases with MCP Tool Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `list_databases` tool to scan a directory for SQLite database files with extensions `.db`, `.sqlite`, or `.sqlite3`. It returns sorted absolute paths, useful for discovering databases. You can specify a directory or default to the current working directory. ```jsonc // MCP tool call — scan current directory { "tool": "list_databases", "arguments": { "directory": "." } } // Expected response text (databases found): // Found 3 database(s): // // - /home/user/project/cache.db // - /home/user/project/data/app.db // - /home/user/project/data/test.sqlite3 // Expected response text (no databases found): // No .db, .sqlite, or .sqlite3 files found in /home/user/project // Scan a specific subdirectory { "tool": "list_databases", "arguments": { "directory": "./data" } } ``` -------------------------------- ### Configure Cursor for mcp-sqlite-server Source: https://github.com/ofershap/mcp-server-sqlite/blob/main/README.md Add this configuration to your `.cursor/mcp.json` file to integrate mcp-sqlite-server with Cursor. ```json { "mcpServers": { "sqlite": { "command": "npx", "args": ["mcp-sqlite-server"] } } } ``` -------------------------------- ### Execute SQL Query (Read-Only) Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the 'query' tool to execute read-only SQL statements like SELECT, PRAGMA, EXPLAIN, and WITH. The 'readonly' argument defaults to true and can be omitted. ```jsonc // MCP tool call — read-only SELECT { "tool": "query", "arguments": { "db": "./data/app.db", "sql": "SELECT id, name, email FROM users WHERE active = 1 ORDER BY name LIMIT 5", "readonly": true // default; omit or set to false for writes } } // Expected response text: // Rows: 5 // // id | name | email // ---+---------+--------------------- // 3 | Alice | alice@example.com // 7 | Bob | bob@example.com // ... ``` -------------------------------- ### listDatabases Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Scans a specified directory for SQLite database files. ```APIDOC ## listDatabases ### Description Scans a specified directory for SQLite database files with extensions `.db`, `.sqlite`, or `.sqlite3`. Returns sorted absolute paths to the found databases. ### Signature `listDatabases(directory: string): string[]` ### Parameters - **directory** (string) - Required - The path to the directory to scan. ### Returns - **string[]** - An array of absolute paths to the discovered SQLite database files. ### Request Example ```typescript import { listDatabases } from "./src/sqlite.js"; const dbs = listDatabases("./data"); console.log(dbs); ``` ### Response Example ```json [ "/home/user/project/data/app.db", "/home/user/project/data/cache.sqlite3" ] ``` ### Usage Notes If no database files are found, an empty array is returned. ``` -------------------------------- ### query Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Executes a SQL query against a specified SQLite database file. Supports both read and write operations. ```APIDOC ## query ### Description Executes a SQL query against a specified SQLite database file. Supports both read and write operations. ### Signature `query(dbPath: string, sql: string, readonly?: boolean): QueryResult` ### Parameters - **dbPath** (string) - Required - The path to the SQLite database file. - **sql** (string) - Required - The SQL statement to execute. - **readonly** (boolean) - Optional - If `false`, allows write operations. Defaults to `true`. ### Returns - **QueryResult** - An object containing the query results, including `columns`, `rows`, and `rowCount`. ### Request Example ```typescript import { query } from "./src/sqlite.js"; const result = query("./app.db", "SELECT * FROM users LIMIT 3"); console.log(result.rowCount); console.log(result.columns); console.log(result.rows[0]); // Example of a write operation query("./app.db", "DELETE FROM sessions WHERE expires_at < datetime('now')", false); ``` ### Response Example ```json { "columns": ["id", "name", "email"], "rows": [ { "id": 1, "name": "Alice", "email": "alice@example.com" } ], "rowCount": 3 } ``` ``` -------------------------------- ### schema Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Retrieves the schema information for a given SQLite database file. ```APIDOC ## schema ### Description Retrieves the schema information for a given SQLite database file, including total table count and details for each table. ### Signature `schema(dbPath: string): SchemaInfo` ### Parameters - **dbPath** (string) - Required - The path to the SQLite database file. ### Returns - **SchemaInfo** - An object containing schema details, including `totalTables` and an array of `tables`. - **tables** (Array) - An array of table objects, each with `name`, `rowCount`, and `columns`. - **columns** (Array) - An array of column objects, each with `name`, `type`, `notnull`, `pk`, and `defaultValue`. ### Request Example ```typescript import { schema } from "./src/sqlite.js"; const info = schema("./app.db"); console.log(info.totalTables); console.log(info.tables[0].name); console.log(info.tables[0].rowCount); console.log(info.tables[0].columns[0]); ``` ### Response Example ```json { "totalTables": 3, "tables": [ { "name": "orders", "rowCount": 1042, "columns": [ { "name": "id", "type": "INTEGER", "notnull": false, "pk": true, "defaultValue": null }, { "name": "user_id", "type": "INTEGER", "notnull": true, "pk": false, "defaultValue": null }, { "name": "amount", "type": "REAL", "notnull": false, "pk": false, "defaultValue": null } ] } ] } ``` ``` -------------------------------- ### Retrieve Table Information Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the 'table_info' tool to fetch detailed metadata for a specific table, including column types, constraints, and row count. This is ideal for focused inspection of a single table. ```jsonc // MCP tool call { "tool": "table_info", "arguments": { "db": "./data/app.db", "table": "orders" } } // Expected response text: // ### orders (1042 rows) // // - id (INTEGER) PK // - user_id (INTEGER) NOT NULL // - total (REAL) NOT NULL DEFAULT 0.0 // - created_at (TEXT) // Error case — table does not exist: // Error: Table "nonexistent" not found ``` -------------------------------- ### Execute SQL Query (Write Operation) Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Enable write operations (INSERT, UPDATE, DELETE, DDL) by setting the 'readonly' argument to false in the 'query' tool call. Responses for write operations indicate the number of rows affected or that no columns were returned for DDL. ```jsonc // MCP tool call — write operation (opt-in) { "tool": "query", "arguments": { "db": "./data/app.db", "sql": "INSERT INTO users (name, email, active) VALUES ('Dave', 'dave@example.com', 1)", "readonly": false } } // Response: "(1 row(s) affected)" or "(No columns returned)" for DDL // Error case — write attempted in read-only mode: // Error: Write operations are not allowed in read-only mode. Set readonly=false to enable writes. ``` -------------------------------- ### List SQLite Databases with TypeScript API Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `listDatabases` function from the core TypeScript API to find SQLite database files in a specified directory. It returns an array of absolute paths to the found databases. ```typescript import { listDatabases } from "./src/sqlite.js"; const dbs: string[] = listDatabases("./data"); // ["/home/user/project/data/app.db", "/home/user/project/data/cache.sqlite3"] ``` -------------------------------- ### tableInfo Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Retrieves detailed information about a specific table within an SQLite database. ```APIDOC ## tableInfo ### Description Retrieves detailed information about a specific table within an SQLite database, including its row count and column definitions. ### Signature `tableInfo(dbPath: string, tableName: string): TableInfo` ### Parameters - **dbPath** (string) - Required - The path to the SQLite database file. - **tableName** (string) - Required - The name of the table to retrieve information for. ### Returns - **TableInfo** - An object containing table details, including `rowCount` and an array of `columns`. - **columns** (Array) - An array of column objects, each with `name`, `type`, `notnull`, `pk`, and `defaultValue`. ### Request Example ```typescript import { tableInfo } from "./src/sqlite.js"; const tbl = tableInfo("./app.db", "users"); console.log(tbl.rowCount); tbl.columns.forEach(c => console.log(`${c.name}: ${c.type}${c.pk ? " PK" : ""}${c.notnull ? " NOT NULL" : ""}`) ); ``` ### Response Example ```json { "rowCount": 312, "columns": [ { "name": "id", "type": "INTEGER", "notnull": false, "pk": true, "defaultValue": null }, { "name": "name", "type": "TEXT", "notnull": false, "pk": false, "defaultValue": null }, { "name": "email", "type": "TEXT", "notnull": false, "pk": false, "defaultValue": null } ] } ``` ``` -------------------------------- ### Execute SQL Query with TypeScript API Source: https://context7.com/ofershap/mcp-server-sqlite/llms.txt Use the `query` function from the core TypeScript API to execute SQL statements. It returns query results including columns, rows, and row count. The function can also be used for write operations by setting the `readonly` parameter to `false`. ```typescript import { query, type QueryResult } from "./src/sqlite.js"; // Returns: { columns: string[], rows: Record[], rowCount: number } const result: QueryResult = query("./app.db", "SELECT * FROM users LIMIT 3"); console.log(result.rowCount); // 3 console.log(result.columns); // ["id", "name", "email"] console.log(result.rows[0]); // { id: 1, name: "Alice", email: "alice@example.com" } // Write with readonly=false query("./app.db", "DELETE FROM sessions WHERE expires_at < datetime('now')", false); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.