db-mcp 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitleaks.toml +9 -0
- package/.trivyignore +8 -0
- package/README.md +193 -120
- package/dist/{chunk-DWJXQEFA.js → chunk-5Y42NPBP.js} +4168 -2411
- package/dist/{chunk-AOUL5SHS.js → chunk-645ZEFLA.js} +70 -20
- package/dist/chunk-OKOVZ5QE.js +28 -0
- package/dist/chunk-SFJQCNG7.js +131 -0
- package/dist/{chunk-S5IDDSSB.js → chunk-VIDSICEL.js} +12 -1
- package/dist/chunk-WBER5YY4.js +2053 -0
- package/dist/{chunk-4IA3DB5C.js → chunk-X3MUUOWM.js} +19 -2
- package/dist/{chunk-Z2GFQU3G.js → chunk-Z7C2TM4L.js} +114 -21
- package/dist/cli.js +79 -5
- package/dist/{http-VSB7DBJR.js → http-6KF4ULDI.js} +199 -77
- package/dist/index.d.ts +231 -8
- package/dist/index.js +6 -5
- package/dist/{sqlite-VHBA4ABV.js → sqlite-U5KSYQXK.js} +63 -140
- package/dist/{sqlite-native-D2LH5ZT7.js → sqlite-native-JXMCFQBA.js} +576 -114
- package/dist/worker-script.js +34 -10
- package/logs/.gitkeep +1 -0
- package/mcp-config-example.json +83 -0
- package/package.json +9 -8
- package/playwright.config.ts +1 -1
- package/scripts/update-badges.ts +99 -0
- package/server.json +7 -5
- package/test-server/README.md +20 -23
- package/test-server/code-map.md +45 -33
- package/test-server/reset-database.ps1 +59 -17
- package/test-server/scripts/README.md +27 -0
- package/test-server/{test-help-resources.mjs → scripts/test-help-resources.mjs} +12 -5
- package/test-server/scripts/test-prompts.mjs +251 -0
- package/test-server/{test-tool-annotations.mjs → scripts/test-tool-annotations.mjs} +9 -4
- package/test-server/test-advanced/README.md +70 -0
- package/test-server/test-advanced/test-codemode-advanced-admin.md +174 -0
- package/test-server/test-advanced/test-codemode-advanced-core.md +193 -0
- package/test-server/test-advanced/test-codemode-advanced-geo.md +157 -0
- package/test-server/test-advanced/test-codemode-advanced-introspection.md +171 -0
- package/test-server/test-advanced/test-codemode-advanced-json.md +169 -0
- package/test-server/test-advanced/test-codemode-advanced-migration.md +160 -0
- package/test-server/test-advanced/test-codemode-advanced-stats.md +185 -0
- package/test-server/test-advanced/test-codemode-advanced-text.md +183 -0
- package/test-server/test-advanced/test-codemode-advanced-transactions.md +136 -0
- package/test-server/test-advanced/test-codemode-advanced-vector.md +141 -0
- package/test-server/test-codemode/README.md +121 -0
- package/test-server/test-codemode/test-codemode-admin.md +223 -0
- package/test-server/test-codemode/test-codemode-core.md +286 -0
- package/test-server/test-codemode/test-codemode-geo.md +177 -0
- package/test-server/test-codemode/test-codemode-introspection.md +190 -0
- package/test-server/test-codemode/test-codemode-json.md +237 -0
- package/test-server/test-codemode/test-codemode-migration.md +278 -0
- package/test-server/test-codemode/test-codemode-sandbox.md +413 -0
- package/test-server/test-codemode/test-codemode-stats.md +232 -0
- package/test-server/test-codemode/test-codemode-text.md +237 -0
- package/test-server/test-codemode/test-codemode-transactions.md +236 -0
- package/test-server/test-codemode/test-codemode-vector.md +244 -0
- package/test-server/test-codemode/test-codemode-wasm-degradation.md +394 -0
- package/test-server/test-database.sql +37 -1
- package/test-server/test-resources.md +43 -16
- package/test-server/test-tool-groups/README.md +100 -0
- package/test-server/test-tool-groups/test-admin-core.md +165 -0
- package/test-server/test-tool-groups/test-admin-extensions.md +133 -0
- package/test-server/{test-tools.md → test-tool-groups/test-core-data.md} +103 -17
- package/test-server/test-tool-groups/test-core-schema.md +240 -0
- package/test-server/test-tool-groups/test-geo-haversine.md +130 -0
- package/test-server/test-tool-groups/test-geo-spatialite.md +110 -0
- package/test-server/test-tool-groups/test-introspection-diagnostics.md +123 -0
- package/test-server/test-tool-groups/test-introspection-schema.md +133 -0
- package/test-server/test-tool-groups/test-json-read.md +219 -0
- package/test-server/test-tool-groups/test-json-write.md +157 -0
- package/test-server/test-tool-groups/test-migration.md +193 -0
- package/test-server/test-tool-groups/test-stats-advanced.md +118 -0
- package/test-server/test-tool-groups/test-stats-basic.md +156 -0
- package/test-server/test-tool-groups/test-text-advanced.md +169 -0
- package/test-server/test-tool-groups/test-text-basic.md +177 -0
- package/test-server/test-tool-groups/test-transactions.md +179 -0
- package/test-server/test-tool-groups/test-vector-read.md +130 -0
- package/test-server/test-tool-groups/test-vector-write.md +115 -0
- package/test-server/tool-reference.md +79 -58
- package/tsconfig.build.json +6 -0
- package/dist/chunk-DZQLDEQS.js +0 -879
- package/test-server/test-agent-experience.md +0 -243
- package/test-server/test-group-tools.md +0 -861
- package/test-server/test-tools-advanced-1.md +0 -517
- package/test-server/test-tools-advanced-2.md +0 -487
- package/test-server/test-tools-codemode.md +0 -629
package/.gitleaks.toml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Gitleaks Configuration
|
|
2
|
+
# https://github.com/gitleaks/gitleaks#configuration
|
|
3
|
+
|
|
4
|
+
title = "db-mcp gitleaks config"
|
|
5
|
+
|
|
6
|
+
# Allowlist for known false positives in test fixtures
|
|
7
|
+
[allowlist]
|
|
8
|
+
description = "Test fixtures containing intentionally fake secrets"
|
|
9
|
+
paths = []
|
package/.trivyignore
ADDED
package/README.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# db-mcp (SQLite MCP Server)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- mcp-name: io.github.neverinfamous/db-mcp -->
|
|
4
|
+
|
|
5
|
+
**SQLite MCP Server** with 151 specialized tools, 11 data resources + 9 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.
|
|
4
6
|
|
|
5
7
|
[](https://github.com/neverinfamous/db-mcp)
|
|
6
|
-
|
|
8
|
+

|
|
7
9
|
[](https://www.npmjs.com/package/db-mcp)
|
|
8
10
|
[](https://hub.docker.com/r/writenotenow/db-mcp)
|
|
9
11
|
[](https://opensource.org/licenses/MIT)
|
|
10
12
|

|
|
11
|
-
[](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.neverinfamous/db-mcp)
|
|
12
14
|
[](SECURITY.md)
|
|
13
15
|
[](https://github.com/neverinfamous/db-mcp)
|
|
14
16
|
[](https://github.com/neverinfamous/db-mcp/actions/workflows/e2e.yml)
|
|
15
|
-

|
|
16
|
-

|
|
17
|
+
[](https://github.com/neverinfamous/db-mcp)
|
|
18
|
+
[](https://github.com/neverinfamous/db-mcp)
|
|
18
19
|
|
|
19
20
|
**[Wiki](https://github.com/neverinfamous/db-mcp/wiki)** • **[Changelog](CHANGELOG.md)**
|
|
20
21
|
|
|
@@ -24,15 +25,14 @@
|
|
|
24
25
|
|
|
25
26
|
| Feature | Description |
|
|
26
27
|
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
27
|
-
| **
|
|
28
|
-
| **
|
|
28
|
+
| **151 Specialized Tools** | The most comprehensive SQLite MCP server available — core CRUD, JSON/JSONB, FTS5 full-text search, statistical analysis, vector search, geospatial/SpatiaLite, introspection, migration, and admin |
|
|
29
|
+
| **20 Resources** | 11 data resources (schema, tables, indexes, views, health, metadata, insights, audit, compile_options, pragma) + 9 help resources (`sqlite://help` + per-group reference) — filtered by `--tool-filter` |
|
|
29
30
|
| **10 AI-Powered Prompts** | Guided workflows for schema exploration, query building, data analysis, optimization, migration, debugging, and hybrid FTS5 + vector search |
|
|
30
|
-
| **Code Mode** | **Massive Token Savings:** Execute complex, multi-step operations inside a
|
|
31
|
-
| **Token-Optimized Payloads** | Every tool response is designed for minimal token footprint. Tools include `compact`, `nodesOnly`, `maxOutliers`, `minSeverity`, and `maxInvalid` parameters where applicable — letting agents control response size without losing data access
|
|
32
|
-
| **Dual SQLite Backends** | WASM (sql.js) for zero-compilation portability, Native (better-sqlite3) for full features including transactions, window functions, and SpatiaLite GIS
|
|
33
|
-
| **Performance** | **⚠️ WASM Caution:** Synchronous execution blocks Node Event Loop on heavy workloads. **🚀 Native:** High-performance concurrent execution. |
|
|
31
|
+
| **Code Mode** | **Massive Token Savings:** Execute complex, multi-step operations inside a **V8 isolate sandbox** with process-level isolation and hard timeouts. Instead of spending thousands of tokens on back-and-forth tool calls, Code Mode exposes all 151 capabilities locally, reducing token overhead by 70–90% and supercharging AI agent reasoning |
|
|
32
|
+
| **Token-Optimized Payloads** | Every tool response is designed for minimal token footprint with `_meta.tokenEstimate` on every response so agents know their token cost. Tools include `compact`, `nodesOnly`, `maxOutliers`, `minSeverity`, and `maxInvalid` parameters where applicable — letting agents control response size without losing data access |
|
|
33
|
+
| **Dual SQLite Backends** | WASM (sql.js) for zero-compilation portability, Native (better-sqlite3) for high-performance concurrent execution with full features including transactions, window functions, and SpatiaLite GIS |
|
|
34
34
|
| **OAuth 2.1 + Access Control** | Enterprise-ready security with RFC 9728/8414 compliance, granular scopes (`read`, `write`, `admin`, `db:*`, `table:*:*`), and Keycloak integration |
|
|
35
|
-
| **Smart Tool Filtering** |
|
|
35
|
+
| **Smart Tool Filtering** | 10 tool groups + 7 shortcuts let you stay within IDE limits while exposing exactly what you need |
|
|
36
36
|
| **HTTP Streaming Transport** | Streamable HTTP (`/mcp`) for modern clients + legacy SSE (`/sse`) for backward compatibility — both protocols supported simultaneously with security headers, rate limiting, health check, and stateless mode for serverless |
|
|
37
37
|
| **Production-Ready Security** | SQL injection protection, parameterized queries, input validation, sandboxed code execution, HTTP body size enforcement, 7 security headers, server timeouts (slowloris protection), Retry-After rate limiting, `trustProxy` for reverse proxy deployments, opt-in HSTS, non-root Docker execution, and build provenance |
|
|
38
38
|
| **Strict TypeScript** | 100% type-safe codebase with strict mode, no `any` types, 1911 unit tests + 1136 E2E tests and 90% coverage |
|
|
@@ -84,17 +84,19 @@ Build the project:
|
|
|
84
84
|
npm run build
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
Run the server:
|
|
87
|
+
Run the server with **Native backend** (better-sqlite3 — full features, requires Node.js native build):
|
|
88
88
|
|
|
89
89
|
```bash
|
|
90
|
-
# Native backend (better-sqlite3) - Full features, requires Node.js native build
|
|
91
90
|
node dist/cli.js --transport stdio --sqlite-native ./database.db
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Or with **WASM backend** (sql.js — cross-platform, no compilation required):
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
```bash
|
|
94
96
|
node dist/cli.js --transport stdio --sqlite ./database.db
|
|
95
97
|
```
|
|
96
98
|
|
|
97
|
-
> **Backend Choice:** Use `--sqlite-native` for full features (
|
|
99
|
+
> **Backend Choice:** Use `--sqlite-native` for full features (151 tools, transactions, window functions, SpatiaLite). Use `--sqlite` for WASM mode (125 tools, no native dependencies).
|
|
98
100
|
|
|
99
101
|
### Verify It Works
|
|
100
102
|
|
|
@@ -121,16 +123,22 @@ npm run test
|
|
|
121
123
|
- ✅ Docker installed and running (for Docker method)
|
|
122
124
|
- ✅ Node.js 24+ (LTS) (for local installation)
|
|
123
125
|
|
|
124
|
-
##
|
|
126
|
+
## Code Mode: Maximum Efficiency
|
|
125
127
|
|
|
126
|
-
|
|
127
|
-
> **AI-enabled IDEs like Cursor have tool limits.** With 139 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.
|
|
128
|
+
Code Mode (`sqlite_execute_code`) dramatically reduces token usage (70–90%) and is included by default in all presets.
|
|
128
129
|
|
|
129
|
-
|
|
130
|
+
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:
|
|
131
|
+
|
|
132
|
+
- **Process-level isolation** — user code runs in a separate V8 instance with enforced heap limits
|
|
133
|
+
- **Readonly enforcement** — when `readonly: true`, write methods return structured errors instead of executing
|
|
134
|
+
- **Hard timeouts** — worker termination if execution exceeds the configured limit
|
|
135
|
+
- **Full API access** — all 11 tool groups are available via `sqlite.*` (e.g., `sqlite.core.readQuery()`, `sqlite.json.extract()`)
|
|
136
|
+
|
|
137
|
+
Set `CODEMODE_ISOLATION=vm` to fall back to the in-process `vm` module sandbox if needed.
|
|
130
138
|
|
|
131
|
-
|
|
139
|
+
### ⚡ Code Mode Only (Maximum Token Savings)
|
|
132
140
|
|
|
133
|
-
|
|
141
|
+
If you control your own setup, you can run with **only Code Mode enabled** — a single tool that provides access to all 151 tools' worth of capability through the `sqlite.*` API:
|
|
134
142
|
|
|
135
143
|
```json
|
|
136
144
|
{
|
|
@@ -138,11 +146,11 @@ Code Mode (`sqlite_execute_code`) provides access to all 139 tools' worth of cap
|
|
|
138
146
|
"db-mcp-sqlite": {
|
|
139
147
|
"command": "node",
|
|
140
148
|
"args": [
|
|
141
|
-
"
|
|
149
|
+
"/path/to/db-mcp/dist/cli.js",
|
|
142
150
|
"--transport",
|
|
143
151
|
"stdio",
|
|
144
152
|
"--sqlite-native",
|
|
145
|
-
"
|
|
153
|
+
"/path/to/database.db",
|
|
146
154
|
"--tool-filter",
|
|
147
155
|
"codemode"
|
|
148
156
|
]
|
|
@@ -151,7 +159,21 @@ Code Mode (`sqlite_execute_code`) provides access to all 139 tools' worth of cap
|
|
|
151
159
|
}
|
|
152
160
|
```
|
|
153
161
|
|
|
154
|
-
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
|
|
162
|
+
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 11 tool groups, and returning exactly the data it needs — in one execution. This mirrors the [Code Mode pattern](https://blog.cloudflare.com/code-mode-mcp/) pioneered by Cloudflare for their entire API: fixed token cost regardless of how many capabilities exist.
|
|
163
|
+
|
|
164
|
+
> [!TIP]
|
|
165
|
+
> **Maximize Token Savings:** Instruct your AI agent to prefer Code Mode over individual tool calls:
|
|
166
|
+
>
|
|
167
|
+
> _"When using db-mcp, prefer `sqlite_execute_code` (Code Mode) for multi-step database operations to minimize token usage."_
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 🎛️ Tool Filtering
|
|
172
|
+
|
|
173
|
+
> [!IMPORTANT]
|
|
174
|
+
> **AI-enabled IDEs like Cursor have tool limits.** With 151 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.
|
|
175
|
+
|
|
176
|
+
### Quick Start: Recommended Configurations
|
|
155
177
|
|
|
156
178
|
#### Starter (50 tools)
|
|
157
179
|
|
|
@@ -175,17 +197,17 @@ Specify exactly the groups you need:
|
|
|
175
197
|
|
|
176
198
|
### Shortcuts (Predefined Bundles)
|
|
177
199
|
|
|
178
|
-
> **Note:** Native includes FTS5 (
|
|
200
|
+
> **Note:** Native includes FTS5 (5), window functions (6), transactions (8), and SpatiaLite (7) not available in WASM.
|
|
179
201
|
|
|
180
202
|
| Shortcut | WASM | Native | + Built-in | What's Included |
|
|
181
203
|
| ------------ | ------ | ------ | ---------- | ------------------------------ |
|
|
182
|
-
| `starter` | **
|
|
183
|
-
| `analytics` |
|
|
184
|
-
| `search` |
|
|
185
|
-
| `spatial` |
|
|
186
|
-
| `dev-schema` |
|
|
187
|
-
| `minimal` |
|
|
188
|
-
| `full` |
|
|
204
|
+
| `starter` | **53** | **58** | +3 | Core, JSON, Text |
|
|
205
|
+
| `analytics` | 55 | 61 | +3 | Core, JSON, Stats |
|
|
206
|
+
| `search` | 40 | 45 | +3 | Core, Text, Vector |
|
|
207
|
+
| `spatial` | 30 | 37 | +3 | Core, Geo, Vector |
|
|
208
|
+
| `dev-schema` | 30 | 30 | +3 | Core, Introspection, Migration |
|
|
209
|
+
| `minimal` | 15 | 15 | +3 | Core only |
|
|
210
|
+
| `full` | 125 | 151 | +3 | Everything enabled |
|
|
189
211
|
|
|
190
212
|
### Tool Groups (10 Available)
|
|
191
213
|
|
|
@@ -194,15 +216,16 @@ Specify exactly the groups you need:
|
|
|
194
216
|
| Group | WASM | Native | + Built-in | Description |
|
|
195
217
|
| --------------- | ---- | ------ | ---------- | -------------------------------------------- |
|
|
196
218
|
| `codemode` | 1 | 1 | +3 | Code Mode (sandboxed code execution) 🌟 |
|
|
197
|
-
| `core` |
|
|
219
|
+
| `core` | 14 | 14 | +3 | Basic CRUD, schema, tables |
|
|
198
220
|
| `json` | 24 | 24 | +3 | JSON/JSONB operations, analysis |
|
|
199
|
-
| `text` | 14 |
|
|
200
|
-
| `stats` |
|
|
201
|
-
| `vector` |
|
|
202
|
-
| `admin` |
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `
|
|
221
|
+
| `text` | 14 | 19 | +3 | Text processing + FTS5 + advanced search |
|
|
222
|
+
| `stats` | 16 | 22 | +3 | Statistical analysis (+ window funcs) |
|
|
223
|
+
| `vector` | 11 | 11 | +3 | Embeddings, similarity search |
|
|
224
|
+
| `admin` | 26 | 26 | +3 | Backup, restore, virtual tables, pragma |
|
|
225
|
+
| `transactions` | 0 | 8 | +3 | Transaction control and atomic execution |
|
|
226
|
+
| `geo` | 4 | 11 | +3 | Geospatial + SpatiaLite (Native only) |
|
|
227
|
+
| `introspection` | 9 | 9 | +3 | FK graph, cascade sim, storage/index audit |
|
|
228
|
+
| `migration` | 6 | 6 | +3 | Migration tracking, apply, rollback (opt-in) |
|
|
206
229
|
|
|
207
230
|
### Syntax Reference
|
|
208
231
|
|
|
@@ -220,14 +243,21 @@ Specify exactly the groups you need:
|
|
|
220
243
|
|
|
221
244
|
You can list individual tool names (without `+` prefix) to create a fully custom whitelist — only the tools you specify will be enabled:
|
|
222
245
|
|
|
246
|
+
Enable exactly 3 tools (whitelist mode):
|
|
247
|
+
|
|
223
248
|
```bash
|
|
224
|
-
# Enable exactly 3 tools (whitelist mode)
|
|
225
249
|
--tool-filter "read_query,write_query,list_tables"
|
|
250
|
+
```
|
|
226
251
|
|
|
227
|
-
|
|
252
|
+
Mix tools from different groups:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
228
255
|
--tool-filter "read_query,fuzzy_search,vector_search"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Combine with a shortcut or group:
|
|
229
259
|
|
|
230
|
-
|
|
260
|
+
```bash
|
|
231
261
|
--tool-filter "starter,+vector_search,+fuzzy_search"
|
|
232
262
|
```
|
|
233
263
|
|
|
@@ -249,7 +279,7 @@ If you start with a negative filter (e.g., `-vector,-geo`), it assumes you want
|
|
|
249
279
|
--tool-filter "-stats,-vector,-geo,-backup,-monitoring,-transactions,-window"
|
|
250
280
|
```
|
|
251
281
|
|
|
252
|
-
##
|
|
282
|
+
## 🔌 SQLite Extensions
|
|
253
283
|
|
|
254
284
|
SQLite supports both **built-in** extensions (compiled into better-sqlite3) and **loadable** extensions (require separate binaries).
|
|
255
285
|
|
|
@@ -272,33 +302,43 @@ SQLite supports both **built-in** extensions (compiled into better-sqlite3) and
|
|
|
272
302
|
|
|
273
303
|
**CSV Extension:**
|
|
274
304
|
|
|
305
|
+
Download a precompiled binary or compile from source: https://www.sqlite.org/csv.html
|
|
306
|
+
|
|
307
|
+
Set the environment variable (Linux/macOS):
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
export CSV_EXTENSION_PATH=/path/to/csv.so
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
On Windows, use `.dll`:
|
|
314
|
+
|
|
275
315
|
```bash
|
|
276
|
-
|
|
277
|
-
|
|
316
|
+
export CSV_EXTENSION_PATH=/path/to/csv.dll
|
|
317
|
+
```
|
|
278
318
|
|
|
279
|
-
|
|
280
|
-
export CSV_EXTENSION_PATH=/path/to/csv.so # Linux
|
|
281
|
-
export CSV_EXTENSION_PATH=/path/to/csv.dll # Windows
|
|
319
|
+
Or use the CLI flag:
|
|
282
320
|
|
|
283
|
-
|
|
321
|
+
```bash
|
|
284
322
|
db-mcp --sqlite-native ./data.db --csv
|
|
285
323
|
```
|
|
286
324
|
|
|
287
325
|
**SpatiaLite Extension:**
|
|
288
326
|
|
|
289
|
-
|
|
290
|
-
# Linux (apt):
|
|
291
|
-
sudo apt install libspatialite-dev
|
|
327
|
+
Install the library for your platform:
|
|
292
328
|
|
|
293
|
-
|
|
294
|
-
brew install libspatialite
|
|
329
|
+
- **Linux (apt):** `sudo apt install libspatialite-dev`
|
|
330
|
+
- **macOS (Homebrew):** `brew install libspatialite`
|
|
331
|
+
- **Windows:** Download from https://www.gaia-gis.it/gaia-sins/
|
|
295
332
|
|
|
296
|
-
|
|
333
|
+
Set the environment variable:
|
|
297
334
|
|
|
298
|
-
|
|
335
|
+
```bash
|
|
299
336
|
export SPATIALITE_PATH=/path/to/mod_spatialite.so
|
|
337
|
+
```
|
|
300
338
|
|
|
301
|
-
|
|
339
|
+
Or use the CLI flag:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
302
342
|
db-mcp --sqlite-native ./data.db --spatialite
|
|
303
343
|
```
|
|
304
344
|
|
|
@@ -306,7 +346,7 @@ db-mcp --sqlite-native ./data.db --spatialite
|
|
|
306
346
|
|
|
307
347
|
## 📁 Resources
|
|
308
348
|
|
|
309
|
-
### Data Resources (
|
|
349
|
+
### Data Resources (11)
|
|
310
350
|
|
|
311
351
|
MCP resources provide read-only access to database metadata:
|
|
312
352
|
|
|
@@ -319,7 +359,10 @@ MCP resources provide read-only access to database metadata:
|
|
|
319
359
|
| `sqlite_views` | `sqlite://views` | All views in the database | `core,admin` |
|
|
320
360
|
| `sqlite_health` | `sqlite://health` | Database health and status | _(read-only)_ |
|
|
321
361
|
| `sqlite_meta` | `sqlite://meta` | Database metadata and PRAGMAs | `core,admin` |
|
|
362
|
+
| `sqlite_compile_options`| `sqlite://compile_options` | SQLite compile-time build options | _(read-only)_ |
|
|
363
|
+
| `sqlite_pragma` | `sqlite://pragma` | Runtime PRAGMA config snapshot | _(read-only)_ |
|
|
322
364
|
| `sqlite_insights` | `memo://insights` | Business insights memo (analysis) | `core,admin` |
|
|
365
|
+
| `sqlite_audit` | `sqlite://audit` | Recent audit log + backup stats | `--audit-log` |
|
|
323
366
|
|
|
324
367
|
### Help Resources (1 + up to 8)
|
|
325
368
|
|
|
@@ -333,7 +376,8 @@ On-demand tool reference documentation, filtered by `--tool-filter`:
|
|
|
333
376
|
| `sqlite_help_stats` | `sqlite://help/stats` | Statistical analysis + window functions reference | When stats group on |
|
|
334
377
|
| `sqlite_help_vector` | `sqlite://help/vector` | Vector/semantic search reference | When vector group on |
|
|
335
378
|
| `sqlite_help_geo` | `sqlite://help/geo` | Geospatial + SpatiaLite reference | When geo group on |
|
|
336
|
-
| `sqlite_help_admin` | `sqlite://help/admin` | Admin,
|
|
379
|
+
| `sqlite_help_admin` | `sqlite://help/admin` | Admin, backup, virtual tables reference | When admin group on |
|
|
380
|
+
| `sqlite_help_transactions` | `sqlite://help/transactions` | Transaction control reference | When transactions group on |
|
|
337
381
|
| `sqlite_help_introspection` | `sqlite://help/introspection` | Schema introspection, FK graph, diagnostics reference | When introspection group on |
|
|
338
382
|
| `sqlite_help_migration` | `sqlite://help/migration` | Migration tracking, apply, rollback reference | When migration group on |
|
|
339
383
|
|
|
@@ -377,6 +421,11 @@ MCP prompts provide AI-assisted database workflows:
|
|
|
377
421
|
| `MCP_RATE_LIMIT_MAX` | `100` | Max requests/minute per IP (HTTP transport) |
|
|
378
422
|
| `CSV_EXTENSION_PATH` | — | Custom path to CSV extension binary (native only) |
|
|
379
423
|
| `SPATIALITE_PATH` | — | Custom path to SpatiaLite extension binary (native only) |
|
|
424
|
+
| `AUDIT_LOG` | — | Audit log file path, or `stderr` (CLI: `--audit-log`) |
|
|
425
|
+
| `AUDIT_REDACT` | `false` | Redact tool arguments from audit entries (CLI: `--audit-redact`)|
|
|
426
|
+
| `AUDIT_READS` | `false` | Also log read-scoped tool invocations (CLI: `--audit-reads`) |
|
|
427
|
+
| `AUDIT_BACKUP` | `false` | Enable pre-mutation DDL snapshots (CLI: `--audit-backup`) |
|
|
428
|
+
| `AUDIT_BACKUP_DATA` | `false` | Include sample data rows in snapshots (CLI: `--audit-backup-data`) |
|
|
380
429
|
|
|
381
430
|
> **Tip:** Lower `METADATA_CACHE_TTL_MS` for 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).
|
|
382
431
|
|
|
@@ -389,6 +438,7 @@ Transport: --transport <stdio|http|sse> --port <N> --server-host <host> --
|
|
|
389
438
|
Auth: --auth-token <token> | --oauth-enabled --oauth-issuer <url> --oauth-audience <aud>
|
|
390
439
|
Database: --sqlite <path> | --sqlite-native <path>
|
|
391
440
|
Extensions: --csv --spatialite (native only)
|
|
441
|
+
Audit: --audit-log <path> --audit-redact --audit-reads --audit-backup --audit-backup-data
|
|
392
442
|
Server: --name <name> --version <ver> --tool-filter <filter>
|
|
393
443
|
```
|
|
394
444
|
|
|
@@ -431,51 +481,65 @@ Add to your `~/.cursor/mcp.json`, Claude Desktop config, or equivalent:
|
|
|
431
481
|
|
|
432
482
|
> See [Tool Filtering](#️-tool-filtering) to customize which tools are exposed.
|
|
433
483
|
|
|
434
|
-
|
|
484
|
+
## 🌐 HTTP/SSE Transport (Remote Access)
|
|
485
|
+
|
|
486
|
+
For remote access, web-based clients, or HTTP-compatible MCP hosts, use the HTTP transport:
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
node dist/cli.js \
|
|
490
|
+
--transport http \
|
|
491
|
+
--port 3000 \
|
|
492
|
+
--sqlite-native ./database.db
|
|
493
|
+
```
|
|
435
494
|
|
|
436
|
-
|
|
495
|
+
**Docker:**
|
|
437
496
|
|
|
438
497
|
```bash
|
|
439
|
-
|
|
498
|
+
docker run --rm -p 3000:3000 \
|
|
499
|
+
-v ./data:/app/data \
|
|
500
|
+
writenotenow/db-mcp:latest \
|
|
501
|
+
--transport http --port 3000 \
|
|
502
|
+
--sqlite-native /app/data/database.db
|
|
440
503
|
```
|
|
441
504
|
|
|
442
|
-
**
|
|
505
|
+
The server supports **two MCP transport protocols simultaneously**, enabling both modern and legacy clients to connect:
|
|
443
506
|
|
|
444
|
-
|
|
445
|
-
| ---------------- | ------------------------------------------------ | -------- |
|
|
446
|
-
| `GET /` | Server info and available endpoints | Both |
|
|
447
|
-
| `POST /mcp` | JSON-RPC requests (initialize, tools/call, etc.) | Both |
|
|
448
|
-
| `GET /mcp` | SSE stream for server-to-client notifications | Stateful |
|
|
449
|
-
| `DELETE /mcp` | Session termination | Stateful |
|
|
450
|
-
| `GET /sse` | Legacy SSE connection (MCP 2024-11-05) | Stateful |
|
|
451
|
-
| `POST /messages` | Legacy SSE message endpoint | Stateful |
|
|
452
|
-
| `GET /health` | Health check (always public) | Both |
|
|
507
|
+
### Streamable HTTP (Recommended)
|
|
453
508
|
|
|
454
|
-
|
|
509
|
+
Modern protocol (MCP 2025-03-26) — single endpoint, session-based:
|
|
455
510
|
|
|
456
|
-
|
|
511
|
+
| Method | Endpoint | Purpose |
|
|
512
|
+
| -------- | -------- | ------------------------------------------------ |
|
|
513
|
+
| `POST` | `/mcp` | JSON-RPC requests (initialize, tools/list, etc.) |
|
|
514
|
+
| `GET` | `/mcp` | SSE stream for server notifications |
|
|
515
|
+
| `DELETE` | `/mcp` | Session termination |
|
|
457
516
|
|
|
458
|
-
|
|
459
|
-
- **Server Timeouts** — Request, keep-alive, and headers timeouts prevent slowloris-style DoS
|
|
460
|
-
- **Rate Limiting** — 100 requests/minute per IP (429 + Retry-After on excess, health checks exempt)
|
|
461
|
-
- **CORS** — Configurable via `--cors-origins` (default: `*`, supports wildcard subdomains like `*.example.com`). ⚠️ **Security Warning:** The default `*` allows requests from any origin. For production HTTP deployments, explicitly configure this to your trusted domains.
|
|
462
|
-
- **Trust Proxy** — Opt-in `trustProxy` for X-Forwarded-For IP extraction behind reverse proxies
|
|
463
|
-
- **Body Size Limit** — Configurable via `--max-body-bytes` (default: 1 MB)
|
|
464
|
-
- **404 Handler** — Unknown paths return `{ error: "Not found" }`
|
|
465
|
-
- **Cross-Protocol Guard** — SSE session IDs rejected on `/mcp` and vice versa
|
|
517
|
+
Sessions are managed via the `Mcp-Session-Id` header.
|
|
466
518
|
|
|
467
|
-
|
|
519
|
+
### Stateless Mode
|
|
468
520
|
|
|
469
|
-
For serverless deployments
|
|
521
|
+
For serverless/stateless deployments where sessions are not needed:
|
|
470
522
|
|
|
471
523
|
```bash
|
|
472
|
-
node dist/cli.js --transport http --port 3000 --
|
|
524
|
+
node dist/cli.js --transport http --port 3000 --stateless --sqlite-native ./database.db
|
|
473
525
|
```
|
|
474
526
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
527
|
+
In stateless mode: `GET /mcp` returns 405, `DELETE /mcp` returns 204, `/sse` and `/messages` return 404. Each `POST /mcp` creates a fresh transport.
|
|
528
|
+
|
|
529
|
+
### Legacy SSE (Backward Compatibility)
|
|
530
|
+
|
|
531
|
+
Legacy protocol (MCP 2024-11-05) — for clients like Python `mcp.client.sse`:
|
|
532
|
+
|
|
533
|
+
| Method | Endpoint | Purpose |
|
|
534
|
+
| ------ | -------------------------- | ------------------------------------------------------------- |
|
|
535
|
+
| `GET` | `/sse` | Opens SSE stream, returns `/messages?sessionId=<id>` endpoint |
|
|
536
|
+
| `POST` | `/messages?sessionId=<id>` | Send JSON-RPC messages to the session |
|
|
537
|
+
|
|
538
|
+
### Utility Endpoints
|
|
539
|
+
|
|
540
|
+
| Method | Endpoint | Purpose |
|
|
541
|
+
| ------ | --------- | ---------------------------------------------------------------------- |
|
|
542
|
+
| `GET` | `/health` | Health check (bypasses rate limiting, always available for monitoring) |
|
|
479
543
|
|
|
480
544
|
## 🔐 Authentication
|
|
481
545
|
|
|
@@ -486,10 +550,9 @@ db-mcp supports two authentication mechanisms for HTTP transport:
|
|
|
486
550
|
Lightweight authentication for development or single-tenant deployments:
|
|
487
551
|
|
|
488
552
|
```bash
|
|
489
|
-
# CLI
|
|
490
553
|
node dist/cli.js --transport http --port 3000 --auth-token my-secret --sqlite-native ./database.db
|
|
491
554
|
|
|
492
|
-
#
|
|
555
|
+
# Or via environment variable
|
|
493
556
|
export MCP_AUTH_TOKEN=my-secret
|
|
494
557
|
node dist/cli.js --transport http --port 3000 --sqlite-native ./database.db
|
|
495
558
|
```
|
|
@@ -500,15 +563,21 @@ Clients must include `Authorization: Bearer my-secret` on all requests. `/health
|
|
|
500
563
|
|
|
501
564
|
Full OAuth 2.1 with RFC 9728/8414 compliance for production multi-tenant deployments:
|
|
502
565
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
566
|
+
```bash
|
|
567
|
+
node dist/cli.js \
|
|
568
|
+
--transport http \
|
|
569
|
+
--port 3000 \
|
|
570
|
+
--sqlite-native ./database.db \
|
|
571
|
+
--oauth-enabled \
|
|
572
|
+
--oauth-issuer http://localhost:8080/realms/db-mcp \
|
|
573
|
+
--oauth-audience db-mcp-server
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
> **Additional flags:** `--oauth-jwks-uri <url>` (auto-discovered if omitted), `--oauth-clock-tolerance <seconds>` (default: 60).
|
|
577
|
+
|
|
578
|
+
### OAuth Scopes
|
|
510
579
|
|
|
511
|
-
|
|
580
|
+
Access control is managed through OAuth scopes:
|
|
512
581
|
|
|
513
582
|
| Scope | Description |
|
|
514
583
|
| -------------------- | -------------------------------------- |
|
|
@@ -518,34 +587,38 @@ Full OAuth 2.1 with RFC 9728/8414 compliance for production multi-tenant deploym
|
|
|
518
587
|
| `db:{name}` | Access to specific database only |
|
|
519
588
|
| `table:{db}:{table}` | Access to specific table only |
|
|
520
589
|
|
|
521
|
-
|
|
590
|
+
### RFC Compliance
|
|
522
591
|
|
|
523
|
-
|
|
524
|
-
node dist/cli.js --transport http --port 3000 \
|
|
525
|
-
--oauth-enabled \
|
|
526
|
-
--oauth-issuer http://localhost:8080/realms/db-mcp \
|
|
527
|
-
--oauth-audience db-mcp-server \
|
|
528
|
-
--sqlite-native ./database.db
|
|
529
|
-
```
|
|
592
|
+
This implementation follows:
|
|
530
593
|
|
|
531
|
-
|
|
594
|
+
- **RFC 9728** — OAuth 2.1 Protected Resource Metadata
|
|
595
|
+
- **RFC 8414** — OAuth 2.1 Authorization Server Metadata
|
|
596
|
+
- **RFC 7591** — OAuth 2.1 Dynamic Client Registration
|
|
597
|
+
|
|
598
|
+
The server exposes metadata at `/.well-known/oauth-protected-resource`.
|
|
599
|
+
|
|
600
|
+
> **Note for Keycloak users:** Add an **Audience mapper** to your client (Client → Client scopes → dedicated scope → Add mapper → Audience) to include the correct `aud` claim in tokens.
|
|
532
601
|
|
|
533
|
-
|
|
602
|
+
> [!NOTE]
|
|
603
|
+
> **Per-tool scope enforcement:** Scopes are enforced at the tool level — each tool group maps to a required scope (`read`, `write`, or `admin`). 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.
|
|
534
604
|
|
|
535
|
-
|
|
605
|
+
> [!TIP]
|
|
606
|
+
> **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 are `null`/`[]`.
|
|
536
607
|
|
|
537
|
-
>
|
|
608
|
+
> [!WARNING]
|
|
609
|
+
> **HTTP without authentication:** When using `--transport http` without enabling OAuth or `--auth-token`, all clients have full unrestricted access. Always enable authentication for production HTTP deployments. See [SECURITY.md](SECURITY.md) for details.
|
|
538
610
|
|
|
539
611
|
## 📊 Benchmarks
|
|
540
612
|
|
|
541
613
|
Performance benchmarks measure framework overhead on critical hot paths using [Vitest bench](https://vitest.dev/guide/features.html#benchmarking) (tinybench). The suite validates that framework plumbing stays negligible relative to actual database I/O:
|
|
542
614
|
|
|
543
|
-
- **Tool dispatch:**
|
|
544
|
-
- **Auth scope checks:**
|
|
545
|
-
- **Identifier validation:** 6
|
|
546
|
-
- **Schema cache hits:** 4
|
|
547
|
-
- **Debug log (filtered):**
|
|
548
|
-
- **Code Mode security:** 1.
|
|
615
|
+
- **Tool dispatch:** 11–14M ops/sec — Map-based lookup is effectively zero-cost
|
|
616
|
+
- **Auth scope checks:** 6–8M ops/sec — OAuth middleware adds no measurable latency
|
|
617
|
+
- **Identifier validation:** 6–7M ops/sec — SQL sanitization is near-instant
|
|
618
|
+
- **Schema cache hits:** 4–6M ops/sec — metadata lookups avoid redundant queries
|
|
619
|
+
- **Debug log (filtered):** 10–11M ops/sec — disabled log levels are true no-ops
|
|
620
|
+
- **Code Mode security:** 1–1.3M validations/sec for typical code, blocked patterns rejected in <1 µs
|
|
621
|
+
- **Sandbox execution:** ~4.4–4.9K executions/sec — trivial code round-trips through V8 isolate in ~0.2 ms
|
|
549
622
|
|
|
550
623
|
```bash
|
|
551
624
|
npm run bench # Run all benchmarks
|