
SQLite MCP Sidecar
dev.xakpc由 xakpc.dev 发布v0.1.3更新于 Oct 24, 2026
Agent-safe MCP sidecar for one live SQLite database: read-only default, bounded writes.
概览
一个容器化的 MCP 边车,让 AI 助手以受权限约束的方式访问一个已有的在线 SQLite 数据库,默认只读。
- 可以做什么
- 在启用 schema 权限时,以 DDL 形式查看数据库结构,不含行数据和内部对象。每次调用执行一条读取语句,以紧凑表格文本返回行,受行数、字节数和超时限制。通过结构化调用插入、更新或删除行,必须提供过滤条件和行数上限,并按请求 ID 保证重试幂等。在所属应用继续写入的同时把在线数据库复制到备份目录,并轮询结果。报告一组固定的健康指标,例如日志模式和快速检查结果。可选执行原始 INSERT、UPDATE 或 DELETE 语句,仅在启用 danger-raw-write 权限时可用。
- 适用场景
- 适用于某个应用已经拥有一个 SQLite 文件,而你希望助手读取它或修改少量行,又不想交出完整 SQL 连接的场景。适合能在数据库旁运行容器、并希望默认只读、写入受限的运维人员。
- 运行要求
- 需要 Docker 和一个已存在、位于本地文件系统的 SQLite 数据库文件;边车不会创建数据库。文件路径由 SQLITE_SIDECAR_DB 指定,令牌由 SQLITE_SIDECAR_TOKEN 指定并通过 Authorization 请求头发送。权限集由 SQLITE_SIDECAR_PERMISSIONS 选择,默认为 schema,read。即使只读权限,数据挂载也必须可写。客户端连接 /db/mcp 端点,不支持 OAuth。一个进程服务一个数据库,容器端口不应直接暴露到公网。
安装
在 SourceWeft 中
- 打开 控制台中的 SQLite MCP Sidecar,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
sqlite-sidecar-mcp
An agent-safe MCP sidecar for one live SQLite database.
It gives an AI agent controlled access to a database that another application already owns, and it limits the damage that an authorized but mistaken agent can cause.
Contents
About the project
An application owns a SQLite file. You want an agent to read it, and perhaps to change a few rows.
Handing the agent a SQL connection gives it the whole file and one DELETE with a wrong predicate
is unrecoverable. sqlite-sidecar-mcp sits next to that application as one more SQLite client and
speaks MCP over HTTP. The owning application does not change.
It runs in production next to the MCP Canary API, where it gives the operator's coding agent read-only access to the live database.
The product defends against two callers. One is an unauthorized client, which the token and the request budget stop. The other is an authorized client that makes a mistake, and that one is the unusual part: an agent with permission to write can still write the wrong thing. Structured writes, a mandatory predicate, a row limit that counts cascades, and a per-minute write budget exist for it.
[!IMPORTANT] One sidecar process serves one database. The request budget, the write budget and the idempotency cache live in process memory. A second replica gives you two independent budgets and two independent caches, and nothing reports it. Do not scale this service. Run a second sidecar only for a different database or a different trust boundary.
Built with
- .NET 10, ASP.NET Core
- Model Context Protocol over Streamable HTTP
Microsoft.Data.Sqlitewith the bundled native SQLite- TOON for row output, which costs fewer tokens than JSON
Getting started
Prerequisites
- Docker
- A SQLite database that already exists. The sidecar never creates one: creation would hide a wrong path and leave an empty database next to the real one.
Run it
The mount must be writable, also for the read-only permission set above. SQLite opens the -shm
file read-write for a read-only connection to a WAL database, and a read-only mount fails in a way
that reads like a permission fault rather than a configuration mistake.
Connect an agent
The endpoint is /db/mcp and the token goes in an Authorization header:
There is no OAuth. A client that insists on OAuth discovery finds no resource metadata on a 401
and stops; the expected consumer is one agent that an operator configured with a static header.
Generate a token and an environment block
It asks for the deployment shape, mints a token from a cryptographic random source, repairs a
permission set that would fail startup, and prints the block as .env, shell or compose.
The eight tools
Which tools exist is decided by the permission set. A tool the deployment does not cover is absent
from tools/list — it does not appear and then fail.
A query answers in TOON, which is a compact tabular text:
truncated: true means a limit stopped the read, not that the query failed.
Structured writes
update and delete take a flat filter, never SQL. Every condition joins with AND; there is no
or and no nesting. A disjunction is one call per branch, and that is the tighter bound: each call
is pre-counted and limited on its own, while one or call would pool the blast radius of every
branch into a single maxRows.
maxRows counts every row the write changes — rows removed by ON DELETE CASCADE and rows a
trigger writes included. A delete with maxRows: 1 cannot quietly destroy a cascade subtree and
report one row. A filter that matches too many rows is rejected before the write starts, and a
write that turns out to exceed the limit is rolled back.
Every write tool takes a mandatory requestId. The same requestId returns the stored response of
a committed write instead of applying it twice. Failures are not cached, so a retry after a failure
is a real retry.
Permissions
One deployment has one token and one permission set. A permission is a property of the deployment, not of a user — there are no users, roles or ACLs. Separate trust levels use separate deployments, which keeps the boundary visible in the deployment configuration.
The name danger-raw-write is deliberately alarming. A neutral name would hide the cost.
[!WARNING] A permission applies to every table in the database. There is no table allowlist and no column allowlist.
writedoes not protect one table from an agent that haswrite. If a table must stay untouched, it belongs in a different database with a different sidecar.
Two rules the sidecar enforces at startup, so a mistake is a failed start and not a surprise later:
- The read floor.
writeanddanger-raw-writeare only valid together withschemaandread. A structured write validates names against the live schema, so an agent that cannot callschemawould be guessing. The missing permissions are never added silently, because that would makeSQLITE_SIDECAR_PERMISSIONSan untrue record of the deployment. - No unknown names.
SQLITE_SIDECAR_PERMISSIONS=reedfails startup instead of quietly granting less than the operator believes.
No permission grants another. read does not imply write, and danger-raw-write is independent
of write.
Configuration
Every value is an environment variable with the SQLITE_SIDECAR_ prefix. Startup fails when a value
is absent or invalid, and it reports every problem at once. The sidecar does not start in a
degraded state.
Required:
Optional, with defaults
ASP.NET Core settings that matter: ASPNETCORE_URLS (the image sets http://0.0.0.0:8080) and
ASPNETCORE_ENVIRONMENT. Outside Development the sidecar logs JSON, which is what a container log
pipeline wants.
The effective write limit is min(the caller's maxRows, SQLITE_SIDECAR_MAX_WRITE_ROWS), so an agent
can ask for less but never for more.
Paths
/health reports that the process is alive and nothing else. It never touches the database: a probe
runs every few seconds, and an expensive probe would become a denial-of-service vector against the
owning application. The checks that do need the file run once, at startup.
Deployment
[!CAUTION] The proxy must not strip the
/dbprefix./db/mcpis the whole public path: the sidecar routes the same URL the agent calls. Both Kamal and Coolify strip a matched prefix by default, and a stripped prefix produces a404that reads like a broken server. Every recipe below turns stripping off.
Common to all of them: one replica, /data writable even for schema,read, and the container
port never published to the internet — the reverse proxy is the only way in, and it is also what
matches the Host header. The sidecar does no host filtering of its own.
Docker Compose
Both containers mount the same volume. The database file must stay on a local filesystem: NFS and SMB do not implement the locking SQLite needs.
Kamal
One service for one database, and one host. A sidecar reads a local file, so it cannot follow a multi-region role set: name the host that holds the database.
healthcheck.pathis not optional here. kamal-proxy asks for/upby default, and the deploy fails on that default.- kamal-proxy has no rate limiting. It gives buffering, body-size limits and forwarded headers. The in-process request budget is therefore the only request limit on this platform.
Coolify
Use a subdomain, not a path. Coolify generates Traefik labels for a domain path, and the
path-plus-strip-prefix combination has open defects. A subdomain costs nothing and removes the risk.
The application path stays /db/mcp either way.
Coolify runs Traefik, so a rate-limit middleware is available. It is not necessary: the in-process budget is active on every platform.
A plain VPS, with systemd
No orchestrator at all. Put the docker run under systemd so it survives a reboot:
-p 127.0.0.1:8080:8080 binds to loopback, so only a proxy on the same host reaches it. Put the
token in /etc/sqlite-sidecar.env with mode 0600, and point Caddy or nginx at 127.0.0.1:8080
with the path forwarded unchanged.
Fly.io
A Fly Volume attaches to exactly one machine, which suits this product: one file, one writer, one sidecar.
[!WARNING] The sidecar and the owning application must run on the same machine. A volume attaches to one machine, so two machines means two different database files, and the one-sidecar rule fails silently — each process would serve its own copy. Keep
auto_stop_machines = falseand do not scale the app.
Token rotation
A deployment has one token. It never expires, and the sidecar accepts no second value. Rotation is a secret change plus a restart, which stops every client at the same moment. That is accepted here: a rotation window would need a list of valid tokens, which is a different product.
Security
Every request passes every layer, in order. No layer is a feature flag.
What is guaranteed
With the default configuration, these statements are true:
- Remote access needs authentication.
- Default permissions are read-only.
readdoes not implywrite.- A write permission is not valid without
schemaandread. writedoes not accept caller-supplied write SQL.- Structured
updateanddeleteneed a predicate, and the predicate joins withANDonly. - Structured
updateanddeletehave a hard row limit, and a broad filter is rejected before the write starts. - That row limit counts every row the write changes, so a delete cannot destroy an unbounded cascade subtree while reporting one row.
- A repeated write with the same
requestIdapplies one time only. - Repeated structured writes reach a rate limit.
- Raw writes need an explicitly dangerous permission.
- Raw writes cannot run DDL,
ATTACHor native extension loading. - A caller cannot supply a backup filesystem path.
- A complete backup file is always a complete database. A partial copy keeps a
.partialsuffix. - Queries have a time limit, a result limit and a concurrency limit.
- The native SQLite defensive mechanisms are on.
- The database file never goes over the network.
These are concrete controls. None of them makes a network-exposed database absolutely safe.
The SQLite sandbox
The innermost layer is always on, and no permission disables any part of it —
danger-raw-write included. It uses the native SQLite authorizer rather than inspecting SQL with
string matching, so these are rejected during statement preparation on every path:
Defensive mode is on, trusted schema is off, per-connection runtime limits bound SQL length, expression depth and VDBE operations, and a running statement is interrupted — inside SQLite, not merely abandoned — when it passes the timeout. Connection pooling is off, because a pooled handle would keep the authorizer and limits of the previous operation.
What is not guaranteed
[!CAUTION] There is no undo. A
deleteinside the configured limits commits, and there is no restore tool. The operator owns the backup strategy. The limits protect against breadth — how many rows one mistake touches. They do not protect against wrongness: a correct-looking write of wrong values is applied exactly as asked.
danger-raw-write means what the name says. When an operator enables it, the token holder can
run this:
That is expected behavior, not a defect. The permission deliberately removes six protections —
structured writes, the mandatory predicate, the mandatory maxRows, the bounded pre-count, the
total-changes bound, and server-generated SQL. It keeps exactly two: the idempotency key and the
write budget. The SQLite sandbox above is untouched, so raw writes still cannot run DDL, attach a
database, load an extension, or write to an internal sqlite_% object.
A permission covers the whole database. See Permissions.
A stolen token gets exactly the capabilities of its deployment. The sidecar limits capability and blast radius. It cannot make an intentionally granted destructive permission harmless. There is no expiry and no revocation list — revoking means changing the secret and restarting.
The budgets throttle; they do not isolate. SQLITE_SIDECAR_MAX_REQUESTS_PER_MINUTE is one fixed
window for the whole process, with no per-caller partition, and it runs before authentication — so
a flood of wrong tokens is bounded too, and a rejected request still spends a permit. One agent that
exhausts the budget stops the other. The write budget behaves the same way. Both are process memory:
a restart resets them, and two processes do not share them.
The container port must never face the internet. The reverse proxy is the only path in, it terminates TLS, and it is the host gate — the sidecar itself does no host filtering.
Reporting a vulnerability
Use GitHub's private security advisories on this repository. Please do not open a public issue for a security report.
Contributing
Contributions are welcome. Fork the repository, create a branch, and open a pull request.
Security tests are mandatory, not optional. A change to a query path, a write path or the sandbox needs a test that proves the boundary still holds — and the suite runs a second time against the Linux container, because the sandbox depends on the native SQLite build and a developer run on another platform does not prove the shipped behaviour.
License
Apache-2.0. See LICENSE.
Contact
Pavel Osadchuk — xakpc.dev · github.com/xakpc
Project: github.com/xakpc/sqlite-mcp-sidecar
Acknowledgments
- Model Context Protocol and the C# SDK
- SQLite, for the authorizer and the online backup API this is built on
- TOON
- Best-README-Template
来源:README.md,提交 4d692e8
工具
0版本历史
1- v0.1.3最新Oct 24, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分