mcp-sqlite-explorer
# mcp-sqlite-explorer
[](https://github.com/KaryawanSurga/mcp-sqlite-explorer/actions/workflows/ci.yml)
[](LICENSE)
[](https://nodejs.org)
> **Zero-dependency, read-only SQLite explorer and query sandbox for AI agents and developers.**
Inspect databases, extract relational schemas, run bounded read-only queries, and generate token-dense database summaries for Claude, Cursor, and MCP-compatible coding agents โ without risking accidental data modification or context window flooding.
---
## โจ Features
- **๐ก๏ธ Multi-Layer Read-Only Safety**:
- AST-level query validator blocks all mutating statements (`INSERT`, `UPDATE`, `DELETE`, `DROP`, `ALTER`, `ATTACH`, mutating `PRAGMA`s).
- Multi-query injection detection (disallows statement chaining via `;`).
- Native SQLite engine-level read-only mode (`PRAGMA query_only = ON;` and `readOnly: true`).
- **โก Zero Native Dependencies**:
- Built entirely on Node 22+ native `node:sqlite`.
- No `node-gyp`, no Python runtime requirement, no C++ compilation errors on Windows, macOS, or Linux.
- **๐ง Token-Optimized AI Context Summaries**:
- `sqlite_summarize_database` produces high-density schema maps (tables, row counts, PKs, foreign keys, indexes) formatted specifically to conserve LLM context budgets.
- **๐ Bounded Query Sandbox**:
- Enforces pagination (`limit` & `offset`) with default cap (50 rows, max 500) and truncation indicators.
- Formats results into GitHub-flavored markdown tables, compact TSV, or JSONL.
- **๐ Query Plan Explainer**:
- Inspect SQLite index utilization and execution plans with `EXPLAIN QUERY PLAN`.
- **๐ป Standalone CLI**:
- Dual-mode: works as both an MCP stdio server and a standalone terminal utility.
---
## ๐ Quick Start
### 1. Claude Desktop Configuration
Add `mcp-sqlite-explorer` to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"sqlite-explorer": {
"command": "npx",
"args": ["-y", "mcp-sqlite-explorer", "serve", "--db", "/path/to/database.sqlite"]
}
}
}
```
### 2. Standalone CLI Usage
```bash
# List all tables and views with row counts
npx mcp-sqlite-explorer tables ./mydb.sqlite
# Describe table columns, primary keys, and foreign keys
npx mcp-sqlite-explorer describe ./mydb.sqlite users
# Run a safe read-only query
npx mcp-sqlite-explorer query ./mydb.sqlite "SELECT id, name FROM users LIMIT 10"
# Generate agent-ready database summary
npx mcp-sqlite-explorer summary ./mydb.sqlite
# Inspect query plan
npx mcp-sqlite-explorer explain ./mydb.sqlite "SELECT * FROM posts WHERE user_id = 1"
```
---
## ๐ ๏ธ MCP Tools Reference
| Tool | Description | Key Parameters |
| --- | --- | --- |
| `sqlite_list_tables` | List user tables and views with row and column counts | `db_path`, `include_views` |
| `sqlite_describe_table` | Full schema detail: columns, types, PKs, FKs, indexes, DDL | `db_path`, `table` |
| `sqlite_read_query` | Execute read-only query (`SELECT`, `WITH`) with pagination | `db_path`, `query`, `limit`, `offset`, `format` |
| `sqlite_explain_query` | Inspect SQLite execution plan | `db_path`, `query` |
| `sqlite_summarize_database` | Token-dense database overview for LLM context | `db_path` |
---
## ๐ Security Model
1. **Strict SQL Whitelist**: Only `SELECT`, `WITH ... SELECT`, `EXPLAIN`, and safe read-only PRAGMAs (`table_info`, `database_list`, `index_list`, `foreign_key_list`) are permitted.
2. **Comment Stripping**: SQL comments (`--` and `/* */`) are parsed and removed prior to analysis to prevent comment-cloaked attacks.
3. **No Database Writes**: Any attempt to write or mutate triggers an immediate `UnsafeQueryError` before reaching SQLite.
---
## ๐งช Testing
```bash
npm test # Run Vitest test suite (35+ unit & e2e tests)
npm run typecheck # Validate TypeScript types
npm run build # Compile TypeScript to dist/
```
---
## ๐ License
MIT ยฉ [KaryawanSurga](https://github.com/KaryawanSurga)
TDQS
Scored across 5 tools
Most tools have clearly distinct purposes: listing, describing, querying, explaining, and summarizing. However, sqlite_summarize_database overlaps substantially with sqlite_list_tables and sqlite_describe_table because it aggregates similar schema/count information, and sqlite_read_query can also surface PRAGMA-style schema details.
All tools use a consistent sqlite_verb_noun naming pattern: sqlite_list_tables, sqlite_describe_table, sqlite_read_query, sqlite_explain_query, sqlite_summarize_database. The convention is predictable and easy for an agent to follow.
Five tools is well-scoped for a read-only SQLite exploration server. Each tool earns its place: schema discovery, table inspection, querying, query-plan inspection, and context-friendly summarization.
The server explicitly targets safe read-only exploration, and its surface covers the full workflow: discover tables, inspect schema, run read-only queries, analyze query plans, and summarize a database for agent context. No obvious read-only lifecycle gap remains.