sqlite-mcp-server
Provides tools for exploring and modifying a local SQLite database: lists tables and views, describes schemas, runs paged read-only SELECT/WITH queries with named parameters, inserts rows, and executes INSERT/UPDATE/DELETE/DDL statements.
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., "@sqlite-mcp-server list all tables in my SQLite database"
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.
sqlite-mcp-server
An MCP server for exploring and querying a local SQLite database. It gives an LLM five tools to
inspect and modify a .db file, and serves both stdio (local hosts) and Streamable HTTP.
Built with the MCP TypeScript SDK v2 (@modelcontextprotocol/server) and the built-in
node:sqlite module, so there are no native modules to compile.
Tools
Tool | What it does | Read-only |
| Lists tables and views with row and column counts | yes |
| Columns, types, primary key, foreign keys, indexes, DDL | yes |
| Runs one | yes |
| Inserts one row with validated column names, returns the stored row | no |
| Runs one | no (destructive hint) |
Read tools accept response_format (markdown default, or json for structuredContent) and
limit/offset pagination. Query values are bound with named parameters — write $author_id in
the SQL and pass {"author_id": 1} — so values are never interpolated into SQL.
sqlite_execute returns {changes, last_insert_rowid}. changes counts the rows the statement
touched, so it is 0 for DDL and for an UPDATE/DELETE that matched nothing. last_insert_rowid
is filled only when the statement stored a row: INSERT and REPLACE return the id they wrote,
while UPDATE, DELETE and DDL return null. SQLite's last_insert_rowid belongs to the
connection, so without this rule an UPDATE would report the id of an earlier INSERT.
{"sql": "INSERT INTO books (title, author_id, genre, published, price, stock) VALUES ($title, 1, 'fiction', 2026, 9.99, 1)", "params": {"title": "Dune"}}
-> {"changes": 1, "last_insert_rowid": 23}
{"sql": "UPDATE books SET stock = stock + 1 WHERE id = $id", "params": {"id": 23}}
-> {"changes": 1, "last_insert_rowid": null}SQLite INTEGER columns hold 64-bit values, so the connection reads them as bigint. JSON has no
such type: sqlite_query returns a value as an exact string when it falls outside the safe integer
range (±(2^53 − 1)), and keeps ordinary integers as numbers.
{"sql": "SELECT 9007199254740993 AS big, 42 AS small", "response_format": "json"}
-> {"columns": ["big", "small"], "rows": [{"big": "9007199254740993", "small": 42}], "count": 1, "offset": 0, "has_more": false}Read as a number, 9007199254740993 would come back as 9007199254740992; the string keeps the
stored value exact. The same rule applies wherever a tool returns row values, sqlite_insert_row
included, while counters such as count and changes stay numbers.
The server also exposes a sqlite://schema resource with the CREATE statements for every table,
view and index.
Related MCP server: Universal Safe Database MCP Toolbox
Requirements
Node.js 22.16+ (
node:sqlitewithstatement.columns()), or Bun 1.2+A SQLite database file
Setup
bun install # or: npm install
bun run build # type-checks src/ and scripts/, then compiles src/ to dist/
bun run seed # optional: creates data/demo.db with a sample bookstoreThe demo database has four tables (authors, books, customers, orders) and one view
(sales_by_book), with 6 authors, 22 books, 10 customers and 34 orders.
Configuration
Variable | Default | Purpose |
|
| Database file to open. Relative paths resolve against the working directory; prefer an absolute path. |
|
| Set to |
|
| HTTP port (loopback only) |
The database is opened lazily on the first tool call. If the file does not exist, tools return an error naming the path rather than failing silently.
Use with an MCP host (stdio)
Claude Desktop (claude_desktop_config.json), Cursor, VS Code and similar hosts:
{
"mcpServers": {
"sqlite": {
"command": "bun",
"args": ["C:\\path\\to\\sqlite-mcp-server\\dist\\index.js"],
"env": {
"SQLITE_DB_PATH": "C:\\path\\to\\your\\database.db"
}
}
}
}Use "command": "node" with the same args on Node 22.16+.
To explore the server interactively:
SQLITE_DB_PATH=./data/demo.db npx @modelcontextprotocol/inspector bun dist/index.jsUse over Streamable HTTP
TRANSPORT=http PORT=3000 bun dist/index.js
# MCP endpoint: http://127.0.0.1:3000/mcpThe HTTP handler is stateless (no sessions) and a fresh server is built per request. It binds
127.0.0.1 only, and createMcpExpressApp validates Host/Origin headers, which blocks DNS
rebinding: a request whose hostname is not 127.0.0.1, localhost or [::1] gets 403 with a
JSON-RPC error naming the offending header (Invalid Host: … / Invalid Origin: …). Both checks
compare the hostname only, so any port on those three hosts is accepted, and an absent Origin
(non-browser client) passes. bun run smoke starts this transport on a free loopback port, sends
initialize then a tools/call to /mcp, checks those two refusals, and stops the process again,
so the path is covered without a manual run. The handler authenticates nothing: put a reverse proxy with authentication in front of
/mcp before exposing it to a network.
Safety notes
sqlite_queryonly acceptsSELECT/WITH/VALUES. SQLite silently ignores everything after a statement's first;, so all tools reject a second statement instead of reporting a partial batch as success.sqlite_executerefusesPRAGMAandATTACH, which could change connection settings or reach files outside the database.Table and column names are validated against the live schema before being quoted as identifiers.
Every tool opens the same lazily-created connection;
PRAGMA foreign_keys = ONis set at open.
Security
The server binds 127.0.0.1 and authenticates nothing: put a reverse proxy with authentication in
front of /mcp before exposing it anywhere else. SQL is guarded rather than trusted (single
read-only statement for sqlite_query, validated identifiers, PRAGMA/ATTACH refused), and no
credential is needed to run the server — the optional model evaluations read EVAL_API_KEY from the
environment only.
Report a vulnerability privately through GitHub's Security Advisories; SECURITY.md describes what is in scope and what is accepted by design. Secret scanning and push protection are enabled on the repository, and it holds no environment files.
Development
bun run dev # run src/index.ts directly
bun run build # type-check src/ and scripts/, then emit src/ to dist/
bun run typecheck # type-check src/ and scripts/ without emitting
bun run test # SQL-guard table tests and the offline model-runner tests
bun run coverage:unit # unit coverage with the per-file floors (scripts/check-coverage.ts)
bun run coverage:e2e # smoke + evals under NODE_V8_COVERAGE, the c8 report and the entry-point floor
bun run smoke # exercise every tool over stdio, then the HTTP endpoint and its refusals
bun run evals # replay every eval question through the tools (deterministic)
bun run evals:model # let a model choose the tool calls (needs EVAL_API_KEY, EVAL_MODEL)scripts/smoke.ts, scripts/evals.ts and scripts/db.test.ts copy the demo database to a temp
directory first, so write tests never touch data/demo.db.
The built server runs on Node 22.16+ (node dist/index.js). The scripts are TypeScript, so
node scripts/smoke.ts and node scripts/evals.ts need Node 22.18+ (or --experimental-strip-types
on 22.16–22.17). That constraint is also why the scripts resolve data/demo.db themselves instead
of importing src/: type stripping refuses the enum in src/constants.ts, and Node does not
remap src/'s .js specifiers to the .ts files. Node prints
ExperimentalWarning: SQLite is an experimental feature on stderr at runtime, including during the
smoke (node scripts/smoke.ts): it comes from node:sqlite and is not a failure. bun run test and bun run seed are Bun-only: the tests use bun:test and the seed
script imports src/ directly.
Coverage
Two reports answer two different questions. The unit suite measures the modules it imports in-process; the end-to-end report measures the built server while real clients drive it. Neither replaces the other, so CI enforces both.
Unit coverage (Bun). bun run coverage:unit runs bun test --coverage --coverage-reporter=lcov, which instruments, through Bun, every module the tests import, then
applies two layers of floors to coverage/lcov.info: bunfig.toml fails the run when any file
drops below 0.9, and scripts/check-coverage.ts holds the modules the suite owns to per-file
floors — 100 % for src/constants.ts, src/server.ts and src/tools/write.ts, 90 % for
src/db.ts and src/format.ts.
The unit suite never imports src/index.ts, so Bun's report cannot see the entry point: measuring
it needs the built server running in a child process, which Bun does not instrument. End-to-end
coverage therefore uses Node's own V8 dumps, merged with c8 (a devDependency, so the lockfile
pins it). bun run coverage:e2e runs the whole sequence below — CI calls exactly that — and it
needs node on PATH (or COVERAGE_NODE pointing at one), because Bun writes no V8 dumps:
rm -rf .v8cov coverage-e2e
NODE_V8_COVERAGE="$PWD/.v8cov" node scripts/smoke.ts # stdio + HTTP, sends a real SIGTERM to the HTTP child
NODE_V8_COVERAGE="$PWD/.v8cov" node scripts/evals.ts # 11 deterministic questions
./node_modules/.bin/c8 report --temp-directory=.v8cov --reporter=text --reporter=lcov --report-dir=coverage-e2e
./node_modules/.bin/c8 check-coverage --temp-directory=.v8cov --include=dist/index.js --lines=90 # the gateThe smoke forwards NODE_V8_COVERAGE to its children by hand, because the SDK's
getDefaultEnvironment() drops it, and src/index.ts closes the server and the database on
SIGTERM/SIGINT, which is what lets the HTTP child exit normally and flush its dump. On Windows,
set the variable with $env:NODE_V8_COVERAGE = "$PWD/.v8cov".
The floor. After writing the report, bun run coverage:e2e runs c8's own gate:
c8 check-coverage --temp-directory=.v8cov --include=dist/index.js --lines=90. Thresholds are
percentages, so the 0.9 floor is written --lines=90. The include names the built entry point on
purpose: c8 filters its raw script paths before applying the source map, where src/index.ts
matches nothing, and a gate that matches nothing passes silently; dist/index.js selects the entry
point, which the report still attributes to src/index.ts. Only the entry point is gated — every
module the unit suite imports already has a floor above, and the end-to-end run exists to measure
what Bun cannot: the built server's own startup and shutdown.
Why 90 % on the entry point. The entry point has 60 executable lines, and on Linux all 60 are
measured (60/60): the stdio path from the smoke, the missing-database startup, and the HTTP path
including its SIGTERM/SIGINT shutdown. At 90 %, up to six lines can move or be temporarily
uncovered by a refactor without failing CI, while a whole branch left unexercised still does.
Lines 24-27 used to be excluded. While the smoke only ever started against a seeded database,
the catch in reportDatabase could not run there, so those lines carried a /* c8 ignore start */
… /* c8 ignore stop */ range — a range c8 treats as covered, which is an assumption, not a
measurement. The smoke now also starts the server with SQLITE_DB_PATH pointing at an absent file, asserts the
No SQLite database at … message and a clean exit, so lines 24-27 execute and are counted; the
markers are gone and no line number appears in the check, so moving that function cannot
invalidate the gate.
Why the gate only runs on Linux. Windows terminates child processes unconditionally: the HTTP
child never receives SIGTERM, its handler does not run and no dump is written, so only the stdio
children (36 of the 60 lines, i.e. 60 %) are measured, which would sit below the 90 % floor. A gate
there would fail on missing instrumentation rather than on missing tests. Windows CI jobs skip the step, and bun run coverage:e2e still
writes the report locally but skips the check with a notice; Linux is the reference platform. The
current Linux report is 60/60 lines for the entry point.
Continuous integration
.github/workflows/ci.yml runs on every push, on pull requests and on demand; the
workflow's run history lists
each run with its matrix. It has nine jobs:
actionlint, which checks the workflow file itself with the pinned actionlint 1.7.12, and an
eight-cell matrix of four runtimes (node-22.16, node-22.18, node-24, bun) on ubuntu-latest
and windows-latest. Each matrix job installs with bun install --frozen-lockfile, builds,
type-checks, runs the unit suite, then the smoke and the deterministic evals under its own runtime.
Coverage is measured once per run rather than in all eight cells:
Step | Runs on | What it does |
| Linux + Bun |
|
| Linux + node-24 |
|
The six other cells run the suite once, without instrumentation. The end-to-end floor stays on Linux because Windows terminates child processes unconditionally, so its HTTP child never writes a dump.
Two artefacts are published per run: coverage-unit (coverage/lcov.info, Bun instrumentation)
and coverage-e2e (coverage-e2e/lcov.info, V8 dumps merged by c8). Both are downloadable from the
run page, next to each other.
Evaluations
evals/evaluation.xml holds 11 read-only questions over the demo database, each requiring several
tool calls (schema discovery, joins, aggregation); see the MCP evaluation guide
for the qa_pair format.
bun run build && bun run evalsscripts/evals.ts parses the XML and, for each question, plays the tool calls a model would make
(sqlite_list_tables, sqlite_describe_table, sqlite_query with named parameters) through a real
stdio client against a temp copy of the demo database. It formats the answer from the last query's
structured rows and asserts it equals the expected answer, so the evaluations are proven through
the server rather than only computed with direct SQL. The check fails when a question has no replay
plan, a tool errors, or an answer differs.
One question reads a list two rows at a time: its plan asserts has_more and next_offset on the
first page, then asks for the second page with the offset the first one returned.
Model-driven evaluations
scripts/evals-model.ts hands the tools to a model, lets it choose its own calls, and checks that
its final message contains the expected answer as whole words (prose around it is allowed, but a
longer value that merely contains it is not: 15 does not answer 5).
It is bounded: a turn cap per question and a cost cap for the whole run, computed from the usage
block of every response. An endpoint that does not report usage is refused, so the cap cannot be
silently ignored.
The scripted runner above stays the deterministic gate (bun run evals); this one answers a
different question: can a model actually drive the tools, and what does that cost?
Variable | Default | Meaning |
| required | bearer token for the endpoint |
| required | model name sent in every request |
|
| base URL before |
| all | run only this question number (1-based) from |
|
| assistant turns allowed per question |
|
| budget for the whole run |
|
| USD per million prompt tokens |
|
| USD per million completion tokens |
The two prices are placeholders: set them to your provider's rates, since the budget is enforced from them.
The loop and the endpoint client are covered offline by scripts/evals-model.test.ts, which runs
them against a fake chat completions endpoint on 127.0.0.1: a correct answer and the cost it
reports, a wrong answer, the turn cap, the cost cap, a response without a usage block, tool
arguments that are not valid JSON, a budget already spent before the next question and the
EVAL_ONLY selection of a single question.
scripts/evals-model-cli.test.ts runs the CLI itself in a child process with a sanitized
environment, so a missing EVAL_MODEL or EVAL_API_KEY and a non-numeric EVAL_MAX_TURNS or
EVAL_MAX_COST_USD are covered before any connection is opened. No key and no model are involved,
so bun run test exercises those paths for free.
EVAL_API_KEY=... EVAL_MODEL=... bun run build && bun run evals:modelWhile tuning a prompt or a tool, EVAL_ONLY runs a single question, so iterating does not spend the
whole budget or wait for the other ten:
EVAL_API_KEY=... EVAL_MODEL=... EVAL_ONLY=3 bun run evals:modelNumbers are 1-based, in the order of the file; an out-of-range value fails with the valid range instead of silently running everything.
Available Tools
5 toolssqlite_describe_tableDescribe TableARead-onlyIdempotent
Describe one table or view: columns and types, primary key, foreign keys, indexes, and the CREATE statement.
Use this before writing a query or an insert so column names, types and keys are correct. To find table names, call sqlite_list_tables. Example: {"table": "books"} -> every column of books plus its foreign keys.
Inputs: table (required), response_format.
sqlite_executeExecute StatementADestructive
Run one modifying SQL statement: INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER or DROP.
Use this for updates, deletes and schema changes. For a single INSERT prefer sqlite_insert_row, which validates columns and returns the new row. For reads use sqlite_query.
One statement per call: a batch would be silently truncated by SQLite, so extra statements are rejected. Use named placeholders ($name) with params instead of interpolating values.
Example: {"sql": "UPDATE books SET stock = stock - $n WHERE id = $id", "params": {"n": 2, "id": 5}} -> {"changes": 1}. A result of 0 changes means the WHERE clause matched nothing; call sqlite_query first to confirm the rows exist.
Inputs: sql (required), params.
sqlite_insert_rowInsert RowA
Insert one row into a table and return the row as SQLite stored it.
Prefer this over hand-written INSERT SQL: column names are validated against the table, so typos come back as a clear error. Omit auto-increment primary keys and let SQLite assign them.
Example: {"table": "books", "values": {"title": "Dune", "author_id": 3, "price": 9.99}} -> the inserted row with its new id. Call sqlite_describe_table first when you are unsure of column names.
Inputs: table (required), values (required).
sqlite_list_tablesList TablesARead-onlyIdempotent
List the tables and views in the connected SQLite database, with row and column counts.
Start here when you do not know the schema, then use sqlite_describe_table for columns and keys and sqlite_query to read rows.
Returns one page at a time; when more exist, the result includes next_offset to pass back as offset. Example: "What data is in this database?" -> no arguments.
Inputs: limit, offset, response_format.
sqlite_queryQuery RowsARead-onlyIdempotent
Run one read-only SQL statement (SELECT or WITH) against the SQLite database.
Results are paged at the SQL level: pass limit/offset rather than writing your own LIMIT when you need to page through many rows. Use named placeholders ($name) and params for values instead of interpolating them into the SQL.
Examples:
"How many books are there?" -> SELECT COUNT(*) AS books FROM books
"Books by author 3" -> sql: SELECT title FROM books WHERE author_id = $author_id, params: {"author_id": 3}
"Top 5 orders" -> sql: SELECT * FROM orders ORDER BY total DESC LIMIT 5
SQLite errors come back as tool errors naming the available tables or columns. This tool cannot modify data; use sqlite_execute or sqlite_insert_row for that.
Inputs: sql (required), limit, offset, params, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
The tools have mostly distinct roles: list tables, describe a table, read via query, insert one row, and execute modifying SQL. The main overlap is sqlite_insert_row versus sqlite_execute, since INSERT can be done through either, but the descriptions clearly recommend insert_row for single inserts and execute for other modifications.
All names use snake_case with a consistent sqlite_ prefix, making the set predictable. Most names follow a verb_noun pattern (list_tables, describe_table, insert_row), though sqlite_query and sqlite_execute are verb-only names rather than verb_noun.
Five tools is well-scoped for a SQLite MCP server, covering schema discovery, reading, inserting, and general SQL execution without bloat. Each tool has a clear place in a compact workflow.
The surface covers schema inspection, reads, inserts, updates, deletes, and DDL through sqlite_execute, giving broad CRUD and lifecycle coverage. Minor gaps include no explicit transaction or multi-statement support, but agents can work around this for typical SQLite tasks.
Maintenance
Related MCP Connectors
Query, explore, and manage your databases through natural conversation.
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Persistent memory, hybrid search and a goal graph for AI agents, over stdio or remote HTTP.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides AI agents read-only analytical access to a SQLite database over stdio, with tools for listing tables, describing schemas, and running paginated SQL queries.-
- AlicenseNot gradedqualityCmaintenanceEnables AI models to securely analyze SQLite datasets and read local text documents through a local stdio interface. It provides read-only querying, schema discovery, pagination, and timeout protections to prevent data leaks or destructive changes.MIT
- AlicenseNot gradedqualityCmaintenanceEnables agents to inspect and query local SQLite databases and, when write mode is enabled, perform inserts, updates, deletes, schema changes, and atomic transactions over stdio.1MIT
- AlicenseAqualityCmaintenanceEnables agents to explore a database safely and read-only through three tools — list_tables, describe_table, and run_query — served over stdio. Queries are guarded by lexical validation, a capped LIMIT, a read-only SQLite connection, and an authorizer with a timeout.3MIT