
db-mcp (SQLite MCP Server)
io.github.neverinfamous由 GitHub 帳號 neverinfamous 發布v1.0.2更新於 Oct 24, 2026
SQLite MCP server with OAuth 2.1, HTTP/SSE, 122 tools, and smart tool filtering
概覽
讓助理透過大量 SQL、JSON、搜尋、統計與管理工具檢查並修改本機 SQLite 資料庫。
- 可以做什麼
- 這是一個本機 SQLite MCP 伺服器,依群組提供大量工具,涵蓋新增查詢更新刪除、結構與資料表管理、JSON/JSONB 操作、FTS5 全文檢索、向量相似度搜尋、統計與視窗函式查詢、地理空間處理、結構內省、遷移追蹤,以及備份與維護等資料庫管理作業。它也提供唯讀的 MCP 資源,用來檢視結構、資料表、索引、健康狀態、指標與稽核資料,並提供用於解釋結構、建構查詢、分析、最佳化與遷移的提示。工具篩選、快捷預設與 Code Mode 工具可限制或合併對外暴露的能力。
- 適用情境
- 當助理需要讀寫同一台機器上的 SQLite 資料庫時適用,例如檢視結構、執行分析查詢、全文或向量檢索,或產生遷移指令碼。也適合需要稽核記錄、指標或帶 OAuth 範圍的 HTTP 存取情境。
- 執行需求
- 透過 stdio 在本機執行,使用 HTTP 傳輸時也可透過 HTTP/SSE 執行。npm 套件需要 Node.js 24+,容器映像需要 Docker。資料庫路徑透過命令列傳入。選用擴充功能需要 CSV_EXTENSION_PATH 或 SPATIALITE_PATH,加密需要 DB_ENCRYPTION_KEY。啟用 OAuth 需要 issuer 與 audience。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 db-mcp (SQLite MCP Server),將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
db-mcp (SQLite MCP Server)
SQLite MCP Server with 170+ specialized tools, 11 data resources + 11 help resources, and 10 prompts, audit logging with DDL backup snapshots, HTTP/SSE Transport, OAuth 2.1 authentication, tool filtering, granular access control, and structured error handling with categorized, actionable responses. Available in WASM and better-sqlite3 variants.
[GitHub] [GitHub Release] [npm] [Docker Pulls] [License: MIT] [Status] [MCP] [Security] [TypeScript] [E2E] [Tests] [Coverage]
🎯 What Sets Us Apart
🚀 Quick Start
Option 1: Docker (Recommended)
Pull and run instantly:
Run with volume mount:
Option 2: Node.js Installation
Clone the repository:
Navigate to directory:
Install dependencies:
Build the project:
Run the server with Native backend (better-sqlite3 — full features, requires Node.js native build):
Or with WASM backend (sql.js — cross-platform, no compilation required):
Backend Choice: Use
--sqlite-nativefor full features (181 MCP tools / 170 group tools, transactions, window functions, SpatiaLite). Use--sqlitefor WASM mode (154 MCP tools / 143 group tools, no native dependencies).
Verify It Works
Expected output:
Run the test suite:
Prerequisites
- ✅ Docker installed and running (for Docker method)
- ✅ Node.js 24+ (LTS) (for local installation)
Code Mode: Maximum Efficiency
Code Mode (sqlite_execute_code) dramatically reduces token usage (70–90%) and is included by default in all presets.
Code executes in a worker-thread sandbox — a separate V8 isolate with its own memory space. All sqlite.* API calls are forwarded to the main thread via a MessagePort-based RPC bridge, where the actual database operations execute. This provides:
- Process-level isolation — user code runs in a separate V8 instance with enforced heap limits
- Readonly enforcement — when
readonly: true, stripped methods throw clear error messages listing available methods via Proxy traps - Hard timeouts — worker termination if execution exceeds the configured limit
- V8 code generation restrictions —
eval()andFunction()construction from strings disabled at the V8 engine level viacodeGeneration: { strings: false, wasm: false } - RPC allowlist — host-side validation prevents workers from invoking unauthorized API methods
- Full API access — all 10 tool groups are available via
sqlite.*(e.g.,sqlite.core.readQuery(),sqlite.json.extract())
Set CODEMODE_ISOLATION=vm with CODEMODE_ISOLATION_INSECURE=1 to fall back to the in-process vm module sandbox if needed.
⚡ Code Mode Only (Maximum Token Savings)
If you control your own setup, you can run with only Code Mode enabled — a single tool that provides access to all 180+ tools' worth of capability through the sqlite.* API:
This exposes just sqlite_execute_code plus built-in tools. The agent writes JavaScript against the typed sqlite.* SDK — composing queries, chaining operations across all 10 tool groups, and returning exactly the data it needs — in one execution. This mirrors the Code Mode pattern pioneered by Cloudflare for their entire API: fixed token cost regardless of how many capabilities exist.
[!TIP] Maximize Token Savings: Instruct your AI agent to prefer Code Mode over individual tool calls:
"When using db-mcp, prefer
sqlite_execute_code(Code Mode) for multi-step database operations to minimize token usage."
🎛️ Tool Filtering
[!IMPORTANT] AI-enabled IDEs like Cursor have tool limits. With 180+ tools in the native backend, you must use tool filtering to stay within limits. Use shortcuts or specify groups to enable only what you need.
Quick Start: Recommended Configurations
Starter (core + json + text)
If you prefer individual tool calls, starter provides Core + JSON + Text:
Custom Groups
Specify exactly the groups you need:
Shortcuts (Predefined Bundles)
Note: Native includes FTS5 (5), window functions (6), transactions (8), and SpatiaLite (7) not available in WASM.
Tool Groups (10 Available)
Note: +4 built-in tools (server_info, server_health, list_adapters, sqlite_execute_code) are injected into every group.
Syntax Reference
Custom Tool Selection
You can list individual tool names (without + prefix) to create a fully custom whitelist — only the tools you specify will be enabled:
Enable exactly 3 tools (whitelist mode):
Mix tools from different groups:
Combine with a shortcut or group:
This is useful for scripted or automated clients that need a minimal, precise set of capabilities.
Examples:
Legacy Syntax (still supported):
If you start with a negative filter (e.g., -vector,-geo), it assumes you want to start with all tools enabled and then subtract.
🔌 SQLite Extensions
SQLite supports both built-in extensions (compiled into better-sqlite3) and loadable extensions (require separate binaries).
Built-in Extensions (work out of box)
Loadable Extensions (require installation)
Installing Extensions
CSV Extension:
Download a precompiled binary or compile from source: https://www.sqlite.org/csv.html
Set the environment variable (Linux/macOS):
On Windows, use .dll:
Or use the CLI flag:
SpatiaLite Extension:
Install the library for your platform:
- Linux (apt):
sudo apt install libspatialite-dev - macOS (Homebrew):
brew install libspatialite - Windows: Download from https://www.gaia-gis.it/gaia-sins/
Set the environment variable:
Or use the CLI flag:
Note: Extension binaries must match your platform and architecture. The server searches common paths automatically, or use the
CSV_EXTENSION_PATH/SPATIALITE_PATHenvironment variables for custom locations.
📁 Resources
Data Resources (11)
MCP resources provide read-only access to database metadata:
Help Resources (1 + up to 10)
On-demand tool reference documentation, filtered by --tool-filter:
Efficiency Tip: Data resources are always readable regardless of tool configuration. The "Min Config" column shows the smallest configuration that provides tools to act on what the resource exposes. Help resources are served on-demand — agents read them only when working with a specific tool group.
💬 Prompts (10)
MCP prompts provide AI-assisted database workflows:
🔧 Configuration
Environment Variables
Tip: Lower
METADATA_CACHE_TTL_MSfor development (e.g.,1000), or increase it for production with stable schemas (e.g.,60000= 1 min). Schema cache is automatically invalidated on DDL operations (CREATE/ALTER/DROP).
CLI Reference
CLI flags override environment variables. Run
node dist/cli.js --helpfor full details.
📚 MCP Client Configuration
Add to your ~/.cursor/mcp.json, Claude Desktop config, or equivalent:
[!TIP] Switching backends: The config above uses the Native backend (better-sqlite3, 181 MCP tools). To use the WASM backend (sql.js, 154 MCP tools, zero native dependencies), change
--sqlite-nativeto--sqlitein the args array. See the Backend Options table in DOCKER_README for feature differences.
Variants (modify the args array above):
See Tool Filtering to customize which tools are exposed.
🌐 HTTP/SSE Transport (Remote Access)
For remote access, web-based clients, or HTTP-compatible MCP hosts, use the HTTP transport:
Docker:
The server supports two MCP transport protocols simultaneously, enabling both modern and legacy clients to connect:
Streamable HTTP (Recommended)
Modern protocol (MCP 2025-03-26) — single endpoint, session-based:
Sessions are managed via the Mcp-Session-Id header.
Stateless Mode
For serverless/stateless deployments where sessions are not needed:
In stateless mode: GET /mcp returns 405, DELETE /mcp returns 204, /sse and /messages return 404. Each POST /mcp creates a fresh transport.
Legacy SSE (Backward Compatibility)
Legacy protocol (MCP 2024-11-05) — for clients like Python mcp.client.sse:
Utility Endpoints
🔐 Authentication
db-mcp secures the HTTP transport using strict OAuth 2.1 authentication:
OAuth 2.1 (Enterprise)
Full OAuth 2.1 with RFC 9728/8414 compliance for production multi-tenant deployments:
Additional flags:
--oauth-jwks-uri <url>(auto-discovered if omitted),--oauth-clock-tolerance <seconds>(default: 60).
OAuth Scopes
Access control is managed through OAuth scopes:
RFC Compliance
This implementation follows:
- RFC 9728 — OAuth 2.1 Protected Resource Metadata
- RFC 8414 — OAuth 2.1 Authorization Server Metadata
- RFC 7591 — OAuth 2.1 Dynamic Client Registration
The server exposes metadata at /.well-known/oauth-protected-resource.
Note for Keycloak users: Add an Audience mapper to your client (Client → Client scopes → dedicated scope → Add mapper → Audience) to include the correct
audclaim in tokens.
[!NOTE] Per-tool scope enforcement: Scopes are enforced at the tool level — each tool group maps to a required scope (
read,write, oradmin). Unknown or unmapped tools default toadmin(fail-closed). When OAuth is enabled, every tool invocation checks the calling token's scopes before execution. When OAuth is not configured, scope checks are skipped entirely.
[!TIP] Audit identity integration: When OAuth is enabled alongside audit logging (
--audit-log), audit entries for write/admin tools automatically capture the authenticated user (claims.sub) and granted scopes. This provides a complete forensic trail linking every mutation to a specific identity. Without OAuth, these fields arenull/[].
[!WARNING] HTTP without authentication: When using
--transport httpwithout enabling OAuth, all clients have full unrestricted access. Always enable authentication for production HTTP deployments. See SECURITY.md for details.
🔐 Encryption at Rest (Native Only)
db-mcp supports transparent database encryption using SQLCipher via the better-sqlite3-multiple-ciphers driver. When encryption is enabled, the server automatically encrypts both your target database (if newly created) and the sidecar SystemDb audit log, ensuring your schema, queries, and results are protected at rest.
Important WASM Limitation: The WASM backend (sql.js) does not support encryption. If you supply an encryption key to the WASM backend, it will gracefully ignore it for the target database. However, this can cause conflicts if both a Native and WASM backend share the same --audit-log file (since the Native backend will encrypt the shared audit log, causing the WASM backend to crash when reading it). To avoid this in dual-backend setups, assign a separate audit log (e.g., --audit-log mcp-audit-wasm.db) for your WASM instance.
Configuring the Key:
You can provide the key via the --encryption-key CLI flag or the DB_ENCRYPTION_KEY environment variable.
- Strong Passphrase: A standard string. SQLCipher will automatically use PBKDF2 key derivation.
- Raw Hex Key (Best Performance): To skip PBKDF2 derivation overhead, provide an exact 256-bit raw hex key prefixed with
xand wrapped in single quotes:
[!WARNING] Audit Log Compatibility: The
DB_ENCRYPTION_KEYenvironment variable applies globally and will cause the internalSystemDbto attempt to decrypt your audit log (--audit-log). If you have an existing unencrypted audit log, the server will fail to start withfile is not a database. To encrypt ONLY your target database (leaving the audit log unencrypted), use the--encryption-keyCLI flag instead of the global environment variable.
📊 Benchmarks
Performance benchmarks measure framework overhead on critical hot paths using Vitest bench (tinybench). The suite validates that framework plumbing stays negligible relative to actual database I/O:
- Tool dispatch: 6–14M ops/sec — Map-based lookup is effectively zero-cost
- Auth scope checks: 4–8M ops/sec — OAuth middleware adds no measurable latency
- Identifier validation: 4–7M ops/sec — SQL sanitization is near-instant
- Schema cache hits: 3–6M ops/sec — metadata lookups avoid redundant queries
- Debug log (filtered): 5–11M ops/sec — disabled log levels are true no-ops
- Code Mode security: ~0.2–1.3M validations/sec for typical code, blocked patterns rejected in 1-2 µs
- Sandbox execution: ~0.5–4.9K executions/sec — trivial code round-trips through V8 isolate in 0.2-1.5 ms
Contributing
Contributions are welcome! Please read our Contributing Guidelines before submitting a pull request.
Security
For security concerns, please see our Security Policy.
⚠️ Never commit credentials - Store secrets in
.env(gitignored)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Code of Conduct
Please read our Code of Conduct before participating in this project.
來源:README.md,提交 bb0dd6f
工具
0版本歷史
1- v1.0.2最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分