sqlscope-mcp
Provides read-only exploration and analysis of SQLite database files, including schema overviews, table descriptions, foreign-key graphing, safe SELECT queries, query-plan explanations, data-quality checks, full-database search, and generated schema documentation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sqlscope-mcp Can you show me the schema and foreign-key relationships in ./shop.db?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
sqlscope-mcp
Let your AI agent explore and understand an SQLite database file, without any way to change it.
sqlscope-mcp is an MCP server for SQLite files. Point it at
an app's .db, a browser profile, a game save or a data export, and the agent can see what is
in there, how the tables relate, whether the data is healthy and why a query is slow.
How it differs from other SQLite MCP servers. Several good read-only SQLite servers exist (mcp-sqlite-insights, sqlite-explorer-fastmcp, mcp-sqlite-explorer, mcp-sql-explorer); going by their READMEs they cover schema listing, sampling, a read-only query and some of them plan output. This one is built around two things they do not advertise:
Read-only is a tested property, not a promise. Five layers (read-only URI,
query_only, an authorizer allow-list, a deadline, a value-size limit) and an attack suite that fires 53 hostile statements and checks the file hash and the folder listing are unchanged afterwards. That includes WAL-mode databases, where a naive read-only open silently creates-waland-shmfiles next to your database.Insight tools, not just a query box. A foreign-key graph that finds unindexed FK columns and orphan rows,
typeof()distributions that expose SQLite's dynamic typing, dangling references withforeign_keysoff, inconsistent date formats, whole-database search, plan findings with index suggestions, and generated markdown docs.
Only the Python standard library's sqlite3 and the mcp SDK are used. No native dependencies.
What it looks like
Real output from a stdio session against a small shop database:
> schema_graph
Foreign keys (3), child -> parent:
order_items (sku) -> products(sku)
order_items (order_id) -> orders(id)
orders (customer_id) -> customers(id) [ON DELETE CASCADE]
Missing indexes on foreign-key columns:
orders(customer_id) has no index. Suggestion: CREATE INDEX "idx_orders_customer_id" ON "orders" ("customer_id");
Orphan check (child rows whose parent is missing; independent of PRAGMA foreign_keys):
orders(customer_id) -> customers: 2 of 302 non-null values have no parent (0.7%); e.g. 99999; 88888
order_items(sku) -> products: 1 of 4 non-null values have no parent (25.0%); e.g. ZZZ
> data_quality table=customers
[WARN] notes: 99% NULL (198 of 200)
[WARN] email looks like a key but is not unique: 1 value(s) repeat (1 extra rows), e.g. 'user5@example.com' x2
[WARN] email: 2 value(s) collide after lower() and trim() (2 extra rows; 1 are exact duplicates)
[WARN] created: date-looking text is inconsistent: 4 different formats: '9999-99-99' x197, '99.99.9999' x1, '99/99/9999' x1, ...
> explain_query "SELECT * FROM orders WHERE customer_id = 5"
Query plan:
- SCAN orders
Findings:
* FULL TABLE SCAN of orders (302 rows): every row is read.
Index suggestions (text only, nothing was created):
* orders is scanned and the query filters on customer_id: CREATE INDEX "idx_orders_customer_id" ON "orders" ("customer_id");
> query "DROP TABLE orders"
Error: Only SELECT / WITH / VALUES queries are allowed (got DROP). This server is read-only by construction.Related MCP server: sql-guard-mcp
Install
You need uv and Python 3.11 or newer.
Claude Code
claude mcp add sqlscope -- uvx sqlscope-mcp --dir "C:\Users\me\databases"Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"sqlscope": {
"command": "uvx",
"args": ["sqlscope-mcp", "--dir", "C:\\Users\\me\\databases"]
}
}
}Or with pip: pip install sqlscope-mcp, then run sqlscope-mcp --dir PATH.
--dir is optional but recommended: with it, every tool refuses paths outside that folder
(.., absolute paths and symlinks are resolved first) and relative paths are taken inside it.
Without it, any file the server process can read may be opened.
Tools
Every tool takes path, the database file.
Tool | What it does |
| File size, page size, encoding, journal mode, |
| Columns with type, NOT NULL, default, PK and generated flags; NULL %, distinct, min, max and |
| Foreign-key graph as text or mermaid, load order, cycles, FK columns with no index (with |
| One |
|
|
| Find a string or number in any non-BLOB column of any table, with a match cap and a time budget per table. |
| NULL-heavy and always-NULL columns, NULL vs |
| Markdown documentation of the whole schema as text, with a mermaid ER diagram. Nothing is written to disk. |
Handled on purpose: BLOBs are shown as <BLOB n bytes 0x...> and never dumped; very long text is
cut with its length; FTS5 and other virtual tables are listed and queryable but not scanned;
WITHOUT ROWID, STRICT and generated columns; Turkish, quoted and otherwise odd identifiers;
UTF-16 databases; invalid UTF-8 in text; and WAL databases (a pending -wal is read, nothing is
written or checkpointed).
Files that are not usable produce a specific message instead of a stack trace: zero bytes, not SQLite, probably encrypted (SQLCipher), truncated header, corrupt pages, and a hot rollback journal left by a crashed writer.
Try asking
"Give me an overview of
app.db. What are the biggest tables?""Describe the
orderstable and show me a few rows.""How do the tables in this database relate? Draw it as a mermaid diagram."
"Which foreign keys have no index? Are there any orphan rows?"
"Is there anything wrong with the data in this database?"
"Where does the email
ada@example.comappear in this database?""Why is this query slow?" (it will use
explain_query)"Write schema documentation for this database that I can paste into a README."
Security
What is enforced, and by what:
Threat | Defence |
Any write: | Connection opened with |
| Denied by the authorizer; the attach limit is also set to 0. |
| Denied by the authorizer. The statement gate also rejects it. |
| Denied: only a short list of read-only pragmas is allowed, and only in read form. |
Temp tables, views, triggers |
|
| Denied by function name; extension loading is also never enabled. |
Stacked statements ( | One statement per call; the |
Creating | A WAL file with no pending WAL is opened |
Runaway queries ( | A progress handler interrupts after |
Memory bombs ( |
|
Flooding the model's context | Row cap (default 200, max 5000), about 200 KB output cap, 200-character cell cap, BLOBs never dumped. |
Opening files outside a folder |
|
The attack suite in tests/test_readonly.py runs these against real databases and compares a
SHA-256 of every file in the folder before and after.
What it does not do:
Read-only does not mean private. A database can contain secrets, and every row a tool returns becomes part of your conversation with the model. Do not point it at a file you would not paste.
-shm(the WAL index) can be touched by SQLite itself when a database has a pending WAL that another process is using; the database file and the-walare never modified. The tests compare those two, not-shm.It uses the SQLite library bundled with your Python, so features newer than that library are unavailable.
Encrypted databases are not supported; they are detected and reported.
A single value larger than 64 MiB cannot be read.
Without
--dirthe server can open any file the process can read (it still only reads).
Development
uv sync --extra test
uv run ruff check src tests && uv run mypy --strict src
uv run pytest testsTests build real databases with sqlite3: a shop schema with seeded problems, WAL databases (with
and without a live writer), FTS5 (skipped if the build lacks it), a database with a hot journal,
broken and encrypted-looking files, a 1,000,000-row table for the cap and time checks, the attack
suite, and a stdio test that launches the installed server and talks MCP to it.
Want to know how it works? sqlscope-mcp-the-hard-way builds a minimal version step by step.
License
MIT
Available Tools
8 toolsdata_qualityARead-onlyIdempotent
Look for data problems, using SQL over a sample of each table: columns that are mostly or always NULL (and NULL versus empty-string mixes); columns holding mixed storage types (SQLite does not enforce column types; the typeof() distribution is reported, with examples); key-like columns (id, email, uuid, ...) that contain duplicates, case/space-only duplicates, and rows identical in every non-key column; dangling foreign keys even though SQLite does not enforce them by default; and date-looking text columns whose formats are inconsistent.
table: check just this table (default: all ordinary tables). sample: rows to examine per table (100-200000).
Inputs: path (required), table, sample. Returns: result
db_overviewARead-onlyIdempotent
Start here. Summarise an SQLite database file: size, page size, text encoding, journal mode (WAL or not), user_version, counts of tables / views / indexes / triggers, and a row count for every table (from ANALYZE statistics when present, otherwise an exact count that stops at 100,000). Virtual tables (FTS5, rtree) are listed with their module and their internal shadow tables are folded away. Opening is read-only and never modifies the file or creates -wal / -shm files.
path: the .db / .sqlite file (relative paths are resolved inside the --dir folder, if one was set).
Inputs: path (required). Returns: result
describe_tableARead-onlyIdempotent
Describe one table or view in depth: columns with declared type, NOT NULL, default, primary key and generated-column flags; per-column NULL percentage, distinct count, min, max and the storage types actually seen (computed over a sample of up to stats_sample rows); foreign keys in both directions; indexes; CHECK constraints; triggers; the CREATE statement; and sample rows. BLOBs are shown as size plus a hex prefix, long text is truncated with its length.
table: table or view name (case-insensitive; a close-match hint is given if it does not exist). sample_rows: how many example rows to show (0-50). stats_sample: rows to sample for the statistics (100-200000).
Inputs: path (required), table (required), sample_rows, stats_sample. Returns: result
explain_queryARead-onlyIdempotent
Show the execution plan of a SELECT / WITH query without running it (EXPLAIN QUERY PLAN), as an indented tree, followed by plain-language findings: full table scans (with row counts), temporary B-tree sorts for ORDER BY / GROUP BY / DISTINCT, and automatic indexes SQLite has to build on every run. Missing-index suggestions are returned as CREATE INDEX text only; nothing is ever created.
Inputs: sql (required), path (required). Returns: result
find_in_dbARead-onlyIdempotent
Find where a string or number appears anywhere in the database: a substring search over every non-BLOB column of every ordinary table (virtual and shadow tables are skipped). Returns, per table, the matching rows (rowid or primary key), the column and a snippet around the match. Each table has a time budget and a match cap, so a huge database cannot hang the call; tables that ran out of budget are listed.
case_sensitive: default false (SQLite folds ASCII letters only, so Turkish or other non-ASCII letters match case-sensitively). max_matches_per_table: 1-50. seconds_per_table: 0.1-30.
Inputs: path (required), term (required), case_sensitive, seconds_per_table, +1 more. Returns: result
queryARead-onlyIdempotent
Run one read-only SELECT / WITH / VALUES statement. Anything that would write (INSERT, UPDATE, DELETE, CREATE, DROP, ATTACH, VACUUM, PRAGMA assignments, load_extension) is refused. Results stop at max_rows rows and about 200 KB, and the query is interrupted after timeout_seconds. BLOB cells show size plus a hex prefix, and text longer than 200 characters is truncated with its length. Prefer aggregates (COUNT, GROUP BY) over pulling raw rows.
format: markdown (default), csv or json. max_rows: 1-5000. timeout_seconds: 0.1-60.
Inputs: sql (required), path (required), format, max_rows, +1 more. Returns: result
schema_docsARead-onlyIdempotent
Generate markdown documentation of the whole schema as text: an entity-relationship diagram (mermaid) when foreign keys exist, then every table with its columns, types, defaults, key and reference notes, indexes, CHECK constraints and triggers, followed by views and trigger definitions. Nothing is written to disk; paste the result where you want it.
Inputs: path (required). Returns: result
schema_graphARead-onlyIdempotent
Show how tables relate through foreign keys: every child -> parent edge, tables with no relationships, a parents-first load order and circular references. Also reports foreign-key columns that have no index (with a CREATE INDEX suggestion as text) and checks for orphan rows (child rows whose parent does not exist) over a sample, even when PRAGMA foreign_keys is off.
format: "text" (default) or "mermaid" (an erDiagram you can paste into a renderer). orphan_sample: child rows to sample per foreign key (100-100000).
Inputs: path (required), format, orphan_sample. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool has a reasonably distinct role: overview, single-table deep dive, whole-schema docs, FK graph, ad-hoc query, plan analysis, cross-DB text search and data-quality checks. The main overlap is between schema_docs and schema_graph, since both can emit a mermaid ER diagram, and data_quality partially overlaps with what an agent could do via query. Descriptions give strong cues (db_overview is explicitly 'start here'), so misselection is unlikely but not impossible.
All eight names use consistent snake_case with no camelCase or casing drift. The only inconsistency is grammatical style: some are verb_noun (describe_table, explain_query, find_in_db) while others are noun_noun (schema_docs, schema_graph, db_overview, data_quality) or a bare verb (query). Readable and predictable overall, just not a single uniform pattern.
Eight tools is a well-scoped set for a read-only SQLite inspection server, and each tool maps to a distinct inspection task. Nothing feels padded or redundant enough to merge, and nothing essential appears to be missing from the count.
Coverage of the read-only introspection domain is strong: schema docs, overview, per-table detail, FK graph, query execution, plan explanation, value search and data-quality auditing. Minor gaps exist, such as no explicit lightweight 'list tables/views/trigger names' operation (db_overview reports counts and describe_table requires a known name) and no schema-diff or index-only listing tool. The deliberately read-only scope means no write/migration operations, which is appropriate rather than a gap.
Maintenance
Related MCP Connectors
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query, explore, and manage your databases through natural conversation.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- AlicenseAqualityCmaintenanceEnables AI agents to safely explore and query a SQLite database in read-only mode, allowing them to inspect schema and run analytical SQL queries without risking data modification.3MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely query and explore SQLite databases through read-only, guard-protected tools that block writes, sensitive table access, and runaway queries.1MIT
- AlicenseAqualityBmaintenanceEnables AI agents to inspect database schemas and run strictly read-only SQL queries with guardrails against destructive statements, multi-statement chaining, and unbounded scans. Supports SQLite natively and PostgreSQL optionally.430 PyPIMIT
- AlicenseAqualityCmaintenanceEnables AI agents to explore and query SQLite databases through read-only, sandboxed tools for listing tables, describing schemas, fetching DDL, and running a single capped SELECT statement. Also supports plain-English questions that are converted to SQL and routed through the same sandbox.4MIT