Skip to main content
Glama
KaryawanSurga

mcp-sqlite-explorer

README.md
# mcp-sqlite-explorer

[![CI](https://github.com/KaryawanSurga/mcp-sqlite-explorer/actions/workflows/ci.yml/badge.svg)](https://github.com/KaryawanSurga/mcp-sqlite-explorer/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Node](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen.svg)](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

A4/5.0

Scored across 5 tools

Disambiguation4/5

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.

Naming Consistency5/5

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.

Tool Count5/5

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.

Completeness5/5

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.

Maintenance

ActivityMaintained
ResponsivenessNo issues