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.
Files changed (84) hide show
  1. package/.gitleaks.toml +9 -0
  2. package/.trivyignore +8 -0
  3. package/README.md +193 -120
  4. package/dist/{chunk-DWJXQEFA.js → chunk-5Y42NPBP.js} +4168 -2411
  5. package/dist/{chunk-AOUL5SHS.js → chunk-645ZEFLA.js} +70 -20
  6. package/dist/chunk-OKOVZ5QE.js +28 -0
  7. package/dist/chunk-SFJQCNG7.js +131 -0
  8. package/dist/{chunk-S5IDDSSB.js → chunk-VIDSICEL.js} +12 -1
  9. package/dist/chunk-WBER5YY4.js +2053 -0
  10. package/dist/{chunk-4IA3DB5C.js → chunk-X3MUUOWM.js} +19 -2
  11. package/dist/{chunk-Z2GFQU3G.js → chunk-Z7C2TM4L.js} +114 -21
  12. package/dist/cli.js +79 -5
  13. package/dist/{http-VSB7DBJR.js → http-6KF4ULDI.js} +199 -77
  14. package/dist/index.d.ts +231 -8
  15. package/dist/index.js +6 -5
  16. package/dist/{sqlite-VHBA4ABV.js → sqlite-U5KSYQXK.js} +63 -140
  17. package/dist/{sqlite-native-D2LH5ZT7.js → sqlite-native-JXMCFQBA.js} +576 -114
  18. package/dist/worker-script.js +34 -10
  19. package/logs/.gitkeep +1 -0
  20. package/mcp-config-example.json +83 -0
  21. package/package.json +9 -8
  22. package/playwright.config.ts +1 -1
  23. package/scripts/update-badges.ts +99 -0
  24. package/server.json +7 -5
  25. package/test-server/README.md +20 -23
  26. package/test-server/code-map.md +45 -33
  27. package/test-server/reset-database.ps1 +59 -17
  28. package/test-server/scripts/README.md +27 -0
  29. package/test-server/{test-help-resources.mjs → scripts/test-help-resources.mjs} +12 -5
  30. package/test-server/scripts/test-prompts.mjs +251 -0
  31. package/test-server/{test-tool-annotations.mjs → scripts/test-tool-annotations.mjs} +9 -4
  32. package/test-server/test-advanced/README.md +70 -0
  33. package/test-server/test-advanced/test-codemode-advanced-admin.md +174 -0
  34. package/test-server/test-advanced/test-codemode-advanced-core.md +193 -0
  35. package/test-server/test-advanced/test-codemode-advanced-geo.md +157 -0
  36. package/test-server/test-advanced/test-codemode-advanced-introspection.md +171 -0
  37. package/test-server/test-advanced/test-codemode-advanced-json.md +169 -0
  38. package/test-server/test-advanced/test-codemode-advanced-migration.md +160 -0
  39. package/test-server/test-advanced/test-codemode-advanced-stats.md +185 -0
  40. package/test-server/test-advanced/test-codemode-advanced-text.md +183 -0
  41. package/test-server/test-advanced/test-codemode-advanced-transactions.md +136 -0
  42. package/test-server/test-advanced/test-codemode-advanced-vector.md +141 -0
  43. package/test-server/test-codemode/README.md +121 -0
  44. package/test-server/test-codemode/test-codemode-admin.md +223 -0
  45. package/test-server/test-codemode/test-codemode-core.md +286 -0
  46. package/test-server/test-codemode/test-codemode-geo.md +177 -0
  47. package/test-server/test-codemode/test-codemode-introspection.md +190 -0
  48. package/test-server/test-codemode/test-codemode-json.md +237 -0
  49. package/test-server/test-codemode/test-codemode-migration.md +278 -0
  50. package/test-server/test-codemode/test-codemode-sandbox.md +413 -0
  51. package/test-server/test-codemode/test-codemode-stats.md +232 -0
  52. package/test-server/test-codemode/test-codemode-text.md +237 -0
  53. package/test-server/test-codemode/test-codemode-transactions.md +236 -0
  54. package/test-server/test-codemode/test-codemode-vector.md +244 -0
  55. package/test-server/test-codemode/test-codemode-wasm-degradation.md +394 -0
  56. package/test-server/test-database.sql +37 -1
  57. package/test-server/test-resources.md +43 -16
  58. package/test-server/test-tool-groups/README.md +100 -0
  59. package/test-server/test-tool-groups/test-admin-core.md +165 -0
  60. package/test-server/test-tool-groups/test-admin-extensions.md +133 -0
  61. package/test-server/{test-tools.md → test-tool-groups/test-core-data.md} +103 -17
  62. package/test-server/test-tool-groups/test-core-schema.md +240 -0
  63. package/test-server/test-tool-groups/test-geo-haversine.md +130 -0
  64. package/test-server/test-tool-groups/test-geo-spatialite.md +110 -0
  65. package/test-server/test-tool-groups/test-introspection-diagnostics.md +123 -0
  66. package/test-server/test-tool-groups/test-introspection-schema.md +133 -0
  67. package/test-server/test-tool-groups/test-json-read.md +219 -0
  68. package/test-server/test-tool-groups/test-json-write.md +157 -0
  69. package/test-server/test-tool-groups/test-migration.md +193 -0
  70. package/test-server/test-tool-groups/test-stats-advanced.md +118 -0
  71. package/test-server/test-tool-groups/test-stats-basic.md +156 -0
  72. package/test-server/test-tool-groups/test-text-advanced.md +169 -0
  73. package/test-server/test-tool-groups/test-text-basic.md +177 -0
  74. package/test-server/test-tool-groups/test-transactions.md +179 -0
  75. package/test-server/test-tool-groups/test-vector-read.md +130 -0
  76. package/test-server/test-tool-groups/test-vector-write.md +115 -0
  77. package/test-server/tool-reference.md +79 -58
  78. package/tsconfig.build.json +6 -0
  79. package/dist/chunk-DZQLDEQS.js +0 -879
  80. package/test-server/test-agent-experience.md +0 -243
  81. package/test-server/test-group-tools.md +0 -861
  82. package/test-server/test-tools-advanced-1.md +0 -517
  83. package/test-server/test-tools-advanced-2.md +0 -487
  84. 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
@@ -0,0 +1,8 @@
1
+ # Trivy CVE Ignore List for db-mcp
2
+ # Add CVEs here that are:
3
+ # 1. False positives
4
+ # 2. Upstream issues with no fix available
5
+ # 3. Not applicable to our use case
6
+
7
+ # Format: CVE-YYYY-NNNNN
8
+ tmp/
package/README.md CHANGED
@@ -1,20 +1,21 @@
1
1
  # db-mcp (SQLite MCP Server)
2
2
 
3
- **SQLite MCP Server** with 139 specialized tools, 8 data resources + 9 help resources, and 10 prompts, 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.
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
  [![GitHub](https://img.shields.io/badge/GitHub-neverinfamous/db--mcp-blue?logo=github)](https://github.com/neverinfamous/db-mcp)
6
- [![GitHub Release](https://img.shields.io/github/v/release/neverinfamous/db-mcp)](https://github.com/neverinfamous/db-mcp/releases/latest)
8
+ ![GitHub Release](https://img.shields.io/github/v/release/neverinfamous/db-mcp)
7
9
  [![npm](https://img.shields.io/npm/v/db-mcp)](https://www.npmjs.com/package/db-mcp)
8
10
  [![Docker Pulls](https://img.shields.io/docker/pulls/writenotenow/db-mcp)](https://hub.docker.com/r/writenotenow/db-mcp)
9
11
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
10
12
  ![Status](https://img.shields.io/badge/status-Production%2FStable-brightgreen)
11
- [![MCP Registry](https://img.shields.io/badge/MCP_Registry-Published-green)](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.neverinfamous/db-mcp)
13
+ [![MCP](https://img.shields.io/badge/MCP-Registry-green.svg)](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.neverinfamous/db-mcp)
12
14
  [![Security](https://img.shields.io/badge/Security-Enhanced-green.svg)](SECURITY.md)
13
15
  [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://github.com/neverinfamous/db-mcp)
14
16
  [![E2E](https://github.com/neverinfamous/db-mcp/actions/workflows/e2e.yml/badge.svg)](https://github.com/neverinfamous/db-mcp/actions/workflows/e2e.yml)
15
- ![Tests](https://img.shields.io/badge/Tests-1911%20passed-brightgreen)
16
- ![E2E Tests](https://img.shields.io/badge/E2E-1136%20passed-brightgreen)
17
- ![Coverage](https://img.shields.io/badge/Coverage-90%25-brightgreen)
17
+ [![Tests](https://img.shields.io/badge/Tests-1911%20passed-brightgreen.svg)](https://github.com/neverinfamous/db-mcp)
18
+ [![Coverage](https://img.shields.io/badge/Coverage-90.34%25-green.svg)](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
- | **139 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 |
28
- | **17 Resources** | 8 data resources (schema, tables, indexes, views, health, metadata, insights) + 9 help resources (`sqlite://help` + per-group reference) — filtered by `--tool-filter` |
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 fast, secure JavaScript sandbox. Instead of spending thousands of tokens on back-and-forth tool calls, Code Mode exposes all 139 capabilities locally, reducing token overhead by up to 90% and supercharging AI agent reasoning |
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. Large datasets include metadata so agents always know the full picture |
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** | 9 tool groups + 7 shortcuts let you stay within IDE limits while exposing exactly what you need |
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
- # WASM backend (sql.js) - Cross-platform, no compilation required
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 (139 tools, transactions, window functions, SpatiaLite). Use `--sqlite` for WASM mode (115 tools, no native dependencies).
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
- ## 🎛️ Tool Filtering
126
+ ## Code Mode: Maximum Efficiency
125
127
 
126
- > [!IMPORTANT]
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
- ### Quick Start: Recommended Configurations
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
- #### Recommended: Code Mode (Maximum Token Savings)
139
+ ### Code Mode Only (Maximum Token Savings)
132
140
 
133
- Code Mode (`sqlite_execute_code`) provides access to all 139 tools' worth of capability through a single, secure JavaScript sandbox. Instead of spending thousands of tokens on back-and-forth tool calls, Code Mode exposes all capabilities locally reducing token overhead by up to 90%.
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
- "C:/path/to/db-mcp/dist/cli.js",
149
+ "/path/to/db-mcp/dist/cli.js",
142
150
  "--transport",
143
151
  "stdio",
144
152
  "--sqlite-native",
145
- "C:/path/to/database.db",
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 9 tool groups, and returning exactly the data it needs — in one execution.
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 (4), window functions (6), transactions (7), and SpatiaLite (7) not available in WASM.
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` | **46** | **50** | +3 | Core, JSON, Text |
183
- | `analytics` | 46 | 52 | +3 | Core, JSON, Stats |
184
- | `search` | 34 | 38 | +3 | Core, Text, Vector |
185
- | `spatial` | 25 | 32 | +3 | Core, Geo, Vector |
186
- | `dev-schema` | 25 | 25 | +3 | Core, Introspection, Migration |
187
- | `minimal` | 10 | 10 | +3 | Core only |
188
- | `full` | 115 | 139 | +3 | Everything enabled |
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` | 10 | 10 | +3 | Basic CRUD, schema, tables |
219
+ | `core` | 14 | 14 | +3 | Basic CRUD, schema, tables |
198
220
  | `json` | 24 | 24 | +3 | JSON/JSONB operations, analysis |
199
- | `text` | 14 | 18 | +3 | Text processing + FTS5 + advanced search |
200
- | `stats` | 14 | 20 | +3 | Statistical analysis (+ window funcs) |
201
- | `vector` | 12 | 12 | +3 | Embeddings, similarity search |
202
- | `admin` | 27 | 34 | +3 | Backup, restore, virtual tables, pragma |
203
- | `geo` | 5 | 12 | +3 | Geospatial + SpatiaLite (Native only) |
204
- | `introspection` | 10 | 10 | +3 | FK graph, cascade sim, storage/index audit |
205
- | `migration` | 7 | 7 | +3 | Migration tracking, apply, rollback (opt-in) |
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
- # Mix tools from different groups
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
- # Combine with a shortcut or group
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
- ## SQLite Extensions
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
- # Download precompiled binary or compile from SQLite source:
277
- # https://www.sqlite.org/csv.html
316
+ export CSV_EXTENSION_PATH=/path/to/csv.dll
317
+ ```
278
318
 
279
- # Set environment variable:
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
- # Or use CLI flag:
321
+ ```bash
284
322
  db-mcp --sqlite-native ./data.db --csv
285
323
  ```
286
324
 
287
325
  **SpatiaLite Extension:**
288
326
 
289
- ```bash
290
- # Linux (apt):
291
- sudo apt install libspatialite-dev
327
+ Install the library for your platform:
292
328
 
293
- # macOS (Homebrew):
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
- # Windows: Download from https://www.gaia-gis.it/gaia-sins/
333
+ Set the environment variable:
297
334
 
298
- # Set environment variable:
335
+ ```bash
299
336
  export SPATIALITE_PATH=/path/to/mod_spatialite.so
337
+ ```
300
338
 
301
- # Or use CLI flag:
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 (8)
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, transactions, backup, virtual tables reference | When admin group on |
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
- ### HTTP/SSE Transport (Remote Access)
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
- For remote access, web-based clients, or MCP Inspector testing, run the server in HTTP mode:
495
+ **Docker:**
437
496
 
438
497
  ```bash
439
- node dist/cli.js --transport http --port 3000 --server-host 0.0.0.0 --sqlite-native ./database.db
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
- **Endpoints:**
505
+ The server supports **two MCP transport protocols simultaneously**, enabling both modern and legacy clients to connect:
443
506
 
444
- | Endpoint | Description | Mode |
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
- **Session Management:** The server uses stateful sessions by default. Include the `mcp-session-id` header (returned from initialization) in subsequent requests for session continuity.
509
+ Modern protocol (MCP 2025-03-26) single endpoint, session-based:
455
510
 
456
- **Security Features:**
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
- - **7 Security Headers** `X-Content-Type-Options`, `X-Frame-Options`, `Content-Security-Policy`, `Cache-Control`, `Referrer-Policy` (no-referrer), `Permissions-Policy` + opt-in `Strict-Transport-Security` via `enableHSTS`
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
- #### Stateless Mode (Serverless)
519
+ ### Stateless Mode
468
520
 
469
- For serverless deployments (AWS Lambda, Cloudflare Workers, Vercel), use stateless mode:
521
+ For serverless/stateless deployments where sessions are not needed:
470
522
 
471
523
  ```bash
472
- node dist/cli.js --transport http --port 3000 --server-host 0.0.0.0 --stateless --sqlite-native :memory:
524
+ node dist/cli.js --transport http --port 3000 --stateless --sqlite-native ./database.db
473
525
  ```
474
526
 
475
- | Mode | Progress Notifications | Legacy SSE | Serverless |
476
- | ------------------------- | ---------------------- | ---------- | ---------- |
477
- | Stateful (default) | ✅ Yes | ✅ Yes | ⚠️ Complex |
478
- | Stateless (`--stateless`) | ❌ No | ❌ No | ✅ Native |
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
- # Environment variable
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
- | Component | Status | Description |
504
- | --------------------------- | ------ | ------------------------------------------------ |
505
- | Protected Resource Metadata | ✅ | RFC 9728 `/.well-known/oauth-protected-resource` |
506
- | Auth Server Discovery | ✅ | RFC 8414 metadata discovery with caching |
507
- | Token Validation | ✅ | JWT validation with JWKS support |
508
- | Scope Enforcement | ✅ | Granular `read`, `write`, `admin` scopes |
509
- | HTTP Transport | ✅ | Streamable HTTP with OAuth middleware |
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
- #### Supported Scopes
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
- #### Quick Start with OAuth CLI Flags
590
+ ### RFC Compliance
522
591
 
523
- ```bash
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
- > **Additional flags:** `--oauth-jwks-uri <url>` (auto-discovered if omitted), `--oauth-clock-tolerance <seconds>` (default: 60).
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
- #### Keycloak Integration
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
- See [docs/KEYCLOAK_SETUP.md](docs/KEYCLOAK_SETUP.md) for setting up Keycloak as your OAuth provider.
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
- > **Priority:** When both `--auth-token` and `--oauth-enabled` are set, OAuth 2.1 takes precedence. If neither is configured, the server warns and runs without authentication.
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:** ~11M ops/sec — Map-based lookup is effectively zero-cost
544
- - **Auth scope checks:** 79M ops/sec — OAuth middleware adds no measurable latency
545
- - **Identifier validation:** 6.4M ops/sec — SQL sanitization is near-instant
546
- - **Schema cache hits:** 4.3M ops/sec — metadata lookups avoid redundant queries
547
- - **Debug log (filtered):** 9.5M ops/sec — disabled log levels are true no-ops (50× faster than actual writes)
548
- - **Code Mode security:** 1.2M validations/sec for typical code, blocked patterns rejected in <1 µs
615
+ - **Tool dispatch:** 11–14M ops/sec — Map-based lookup is effectively zero-cost
616
+ - **Auth scope checks:** 68M 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