db-mcp 3.0.2 → 5.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 (183) hide show
  1. package/README.md +112 -75
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/adapters/database-adapter.d.ts +11 -1
  4. package/dist/adapters/database-adapter.d.ts.map +1 -1
  5. package/dist/adapters/registration/resources.d.ts.map +1 -1
  6. package/dist/adapters/registration/tools.d.ts.map +1 -1
  7. package/dist/adapters/sqlite/prompts/analysis.d.ts.map +1 -1
  8. package/dist/adapters/sqlite/query-executor.d.ts.map +1 -1
  9. package/dist/adapters/sqlite/read-write-lock.d.ts +49 -0
  10. package/dist/adapters/sqlite/read-write-lock.d.ts.map +1 -0
  11. package/dist/adapters/sqlite/resources.d.ts +1 -1
  12. package/dist/adapters/sqlite/resources.d.ts.map +1 -1
  13. package/dist/adapters/sqlite/schemas/admin.d.ts +33 -19
  14. package/dist/adapters/sqlite/schemas/admin.d.ts.map +1 -1
  15. package/dist/adapters/sqlite/schemas/core.d.ts +96 -0
  16. package/dist/adapters/sqlite/schemas/core.d.ts.map +1 -1
  17. package/dist/adapters/sqlite/schemas/fts.d.ts +4 -0
  18. package/dist/adapters/sqlite/schemas/fts.d.ts.map +1 -1
  19. package/dist/adapters/sqlite/schemas/introspection.d.ts +25 -15
  20. package/dist/adapters/sqlite/schemas/introspection.d.ts.map +1 -1
  21. package/dist/adapters/sqlite/schemas/migration.d.ts +2 -2
  22. package/dist/adapters/sqlite/schemas/migration.d.ts.map +1 -1
  23. package/dist/adapters/sqlite/schemas/spatialite.d.ts +1 -0
  24. package/dist/adapters/sqlite/schemas/spatialite.d.ts.map +1 -1
  25. package/dist/adapters/sqlite/schemas/text.d.ts +36 -0
  26. package/dist/adapters/sqlite/schemas/text.d.ts.map +1 -1
  27. package/dist/adapters/sqlite/sqlite-adapter.d.ts +6 -0
  28. package/dist/adapters/sqlite/sqlite-adapter.d.ts.map +1 -1
  29. package/dist/adapters/sqlite/tools/admin/backup/create.d.ts.map +1 -1
  30. package/dist/adapters/sqlite/tools/admin/backup/dump.d.ts.map +1 -1
  31. package/dist/adapters/sqlite/tools/admin/backup/restore.d.ts.map +1 -1
  32. package/dist/adapters/sqlite/tools/admin/index.d.ts.map +1 -1
  33. package/dist/adapters/sqlite/tools/admin/pragma.d.ts +0 -4
  34. package/dist/adapters/sqlite/tools/admin/pragma.d.ts.map +1 -1
  35. package/dist/adapters/sqlite/tools/admin/verify.d.ts.map +1 -1
  36. package/dist/adapters/sqlite/tools/codemode.d.ts.map +1 -1
  37. package/dist/adapters/sqlite/tools/core/convenience.d.ts.map +1 -1
  38. package/dist/adapters/sqlite/tools/core/index.d.ts.map +1 -1
  39. package/dist/adapters/sqlite/tools/core/queries.d.ts.map +1 -1
  40. package/dist/adapters/sqlite/tools/core/tables.d.ts.map +1 -1
  41. package/dist/adapters/sqlite/tools/core/versioning.d.ts +19 -0
  42. package/dist/adapters/sqlite/tools/core/versioning.d.ts.map +1 -0
  43. package/dist/adapters/sqlite/tools/fts.d.ts.map +1 -1
  44. package/dist/adapters/sqlite/tools/introspection/diagnostics/indexes.d.ts.map +1 -1
  45. package/dist/adapters/sqlite/tools/introspection/graph/tools.d.ts.map +1 -1
  46. package/dist/adapters/sqlite/tools/json-helpers/read.d.ts.map +1 -1
  47. package/dist/adapters/sqlite/tools/json-operations/crud.d.ts.map +1 -1
  48. package/dist/adapters/sqlite/tools/json-operations/query.d.ts.map +1 -1
  49. package/dist/adapters/sqlite/tools/migration/helpers.d.ts.map +1 -1
  50. package/dist/adapters/sqlite/tools/text/helpers.d.ts +9 -0
  51. package/dist/adapters/sqlite/tools/text/helpers.d.ts.map +1 -1
  52. package/dist/adapters/sqlite/tools/text/index.d.ts.map +1 -1
  53. package/dist/adapters/sqlite/tools/text/search.d.ts +4 -0
  54. package/dist/adapters/sqlite/tools/text/search.d.ts.map +1 -1
  55. package/dist/adapters/sqlite/tools/vector/metadata.d.ts.map +1 -1
  56. package/dist/adapters/sqlite/tools/vector/search.d.ts.map +1 -1
  57. package/dist/adapters/sqlite/tools/vector/storage.d.ts.map +1 -1
  58. package/dist/adapters/sqlite/tools/virtual/vtable/analyze-csv.d.ts.map +1 -1
  59. package/dist/adapters/sqlite/tools/virtual/vtable/csv.d.ts.map +1 -1
  60. package/dist/adapters/sqlite/tools/virtual/vtable/info.d.ts.map +1 -1
  61. package/dist/adapters/sqlite/types.d.ts +5 -1
  62. package/dist/adapters/sqlite/types.d.ts.map +1 -1
  63. package/dist/adapters/sqlite-native/index.d.ts +1 -1
  64. package/dist/adapters/sqlite-native/index.d.ts.map +1 -1
  65. package/dist/adapters/sqlite-native/native-sqlite-adapter.d.ts.map +1 -1
  66. package/dist/adapters/sqlite-native/tools/spatialite/tools.d.ts.map +1 -1
  67. package/dist/adapters/sqlite-native/tools/window/helpers.d.ts +52 -0
  68. package/dist/adapters/sqlite-native/tools/window/helpers.d.ts.map +1 -0
  69. package/dist/adapters/sqlite-native/tools/window/index.d.ts +7 -0
  70. package/dist/adapters/sqlite-native/tools/window/index.d.ts.map +1 -0
  71. package/dist/adapters/sqlite-native/tools/window/lag-lead.d.ts +7 -0
  72. package/dist/adapters/sqlite-native/tools/window/lag-lead.d.ts.map +1 -0
  73. package/dist/adapters/sqlite-native/tools/window/moving-average.d.ts +7 -0
  74. package/dist/adapters/sqlite-native/tools/window/moving-average.d.ts.map +1 -0
  75. package/dist/adapters/sqlite-native/tools/window/ntile.d.ts +7 -0
  76. package/dist/adapters/sqlite-native/tools/window/ntile.d.ts.map +1 -0
  77. package/dist/adapters/sqlite-native/tools/window/rank.d.ts +7 -0
  78. package/dist/adapters/sqlite-native/tools/window/rank.d.ts.map +1 -0
  79. package/dist/adapters/sqlite-native/tools/window/row-number.d.ts +7 -0
  80. package/dist/adapters/sqlite-native/tools/window/row-number.d.ts.map +1 -0
  81. package/dist/adapters/sqlite-native/tools/window/running-total.d.ts +7 -0
  82. package/dist/adapters/sqlite-native/tools/window/running-total.d.ts.map +1 -0
  83. package/dist/adapters/sqlite-native/tools/window/schemas.d.ts +159 -0
  84. package/dist/adapters/sqlite-native/tools/window/schemas.d.ts.map +1 -0
  85. package/dist/adapters/sqlite-native/transaction-methods.d.ts.map +1 -1
  86. package/dist/audit/interceptor.d.ts.map +1 -1
  87. package/dist/audit/logger.d.ts +26 -25
  88. package/dist/audit/logger.d.ts.map +1 -1
  89. package/dist/auth/authorization-server-discovery.d.ts.map +1 -1
  90. package/dist/auth/scopes/mapping.d.ts.map +1 -1
  91. package/dist/auth/token-validator.d.ts.map +1 -1
  92. package/dist/{chunk-W5WQVNVX.js → chunk-27C5EE6U.js} +23 -17
  93. package/dist/chunk-2TYICG7B.js +1183 -0
  94. package/dist/{chunk-37G4DLL6.js → chunk-LLIAIJPO.js} +1146 -539
  95. package/dist/{chunk-NV34JSQM.js → chunk-UE7GVOBV.js} +1757 -1331
  96. package/dist/{chunk-L552U3QS.js → chunk-XLIYO3YA.js} +401 -77
  97. package/dist/cli.js +116 -11
  98. package/dist/codemode/api-constants.d.ts.map +1 -1
  99. package/dist/codemode/api.d.ts.map +1 -1
  100. package/dist/codemode/sandbox-factory.d.ts.map +1 -1
  101. package/dist/codemode/sandbox.d.ts +0 -3
  102. package/dist/codemode/sandbox.d.ts.map +1 -1
  103. package/dist/codemode/security.d.ts.map +1 -1
  104. package/dist/codemode/types.d.ts +2 -0
  105. package/dist/codemode/types.d.ts.map +1 -1
  106. package/dist/constants/server-instructions.d.ts +1 -1
  107. package/dist/constants/server-instructions.d.ts.map +1 -1
  108. package/dist/filtering/tool-constants.d.ts +11 -11
  109. package/dist/filtering/tool-constants.d.ts.map +1 -1
  110. package/dist/{http-HWTUVFIA.js → http-ZDMK46QU.js} +195 -32
  111. package/dist/index.js +4 -4
  112. package/dist/observability/metrics.d.ts +36 -0
  113. package/dist/observability/metrics.d.ts.map +1 -0
  114. package/dist/observability/system-db.d.ts +13 -0
  115. package/dist/observability/system-db.d.ts.map +1 -0
  116. package/dist/server/mcp-server.d.ts +3 -0
  117. package/dist/server/mcp-server.d.ts.map +1 -1
  118. package/dist/server/registration/admin-tools.d.ts +6 -0
  119. package/dist/server/registration/admin-tools.d.ts.map +1 -0
  120. package/dist/server/registration/audit-tools/backup.d.ts +8 -0
  121. package/dist/server/registration/audit-tools/backup.d.ts.map +1 -0
  122. package/dist/server/registration/audit-tools/helpers.d.ts +11 -0
  123. package/dist/server/registration/audit-tools/helpers.d.ts.map +1 -0
  124. package/dist/server/registration/audit-tools/index.d.ts +4 -0
  125. package/dist/server/registration/audit-tools/index.d.ts.map +1 -0
  126. package/dist/server/registration/audit-tools/resource.d.ts +8 -0
  127. package/dist/server/registration/audit-tools/resource.d.ts.map +1 -0
  128. package/dist/server/registration/audit-tools/search.d.ts +7 -0
  129. package/dist/server/registration/audit-tools/search.d.ts.map +1 -0
  130. package/dist/server/registration/help-resources.d.ts.map +1 -1
  131. package/dist/server/registration/index.d.ts +3 -1
  132. package/dist/server/registration/index.d.ts.map +1 -1
  133. package/dist/server/registration/observability-resources.d.ts +11 -0
  134. package/dist/server/registration/observability-resources.d.ts.map +1 -0
  135. package/dist/server/subscription-manager.d.ts +35 -0
  136. package/dist/server/subscription-manager.d.ts.map +1 -0
  137. package/dist/{sqlite-TB56Z7G3.js → sqlite-XWZPEZJO.js} +195 -19
  138. package/dist/{sqlite-native-IF75BB3O.js → sqlite-native-5GQ3WKCZ.js} +311 -147
  139. package/dist/transports/http/middleware.d.ts.map +1 -1
  140. package/dist/transports/http/oauth.d.ts.map +1 -1
  141. package/dist/transports/http/sessions/legacy-sse.d.ts.map +1 -1
  142. package/dist/transports/http/sessions/stateful.d.ts +5 -1
  143. package/dist/transports/http/sessions/stateful.d.ts.map +1 -1
  144. package/dist/transports/http/transport.d.ts +2 -0
  145. package/dist/transports/http/transport.d.ts.map +1 -1
  146. package/dist/transports/http/types.d.ts +11 -0
  147. package/dist/transports/http/types.d.ts.map +1 -1
  148. package/dist/types/auth.d.ts +4 -0
  149. package/dist/types/auth.d.ts.map +1 -1
  150. package/dist/types/server.d.ts +5 -0
  151. package/dist/types/server.d.ts.map +1 -1
  152. package/dist/utils/annotations.d.ts +8 -0
  153. package/dist/utils/annotations.d.ts.map +1 -1
  154. package/dist/utils/errors/categories.d.ts +16 -11
  155. package/dist/utils/errors/categories.d.ts.map +1 -1
  156. package/dist/utils/errors/classes.d.ts +37 -0
  157. package/dist/utils/errors/classes.d.ts.map +1 -1
  158. package/dist/utils/errors/format.d.ts +2 -2
  159. package/dist/utils/errors/format.d.ts.map +1 -1
  160. package/dist/utils/errors/index.d.ts +1 -1
  161. package/dist/utils/errors/index.d.ts.map +1 -1
  162. package/dist/utils/errors/suggestions.d.ts +1 -0
  163. package/dist/utils/errors/suggestions.d.ts.map +1 -1
  164. package/dist/utils/index.d.ts +3 -0
  165. package/dist/utils/index.d.ts.map +1 -1
  166. package/dist/utils/logger/types.d.ts +1 -1
  167. package/dist/utils/logger/types.d.ts.map +1 -1
  168. package/dist/utils/security-utils.d.ts +29 -0
  169. package/dist/utils/security-utils.d.ts.map +1 -0
  170. package/dist/utils/stream-utils.d.ts +14 -0
  171. package/dist/utils/stream-utils.d.ts.map +1 -0
  172. package/dist/utils/tokens.d.ts +15 -0
  173. package/dist/utils/tokens.d.ts.map +1 -0
  174. package/dist/utils/where-clause.d.ts +0 -13
  175. package/dist/utils/where-clause.d.ts.map +1 -1
  176. package/package.json +43 -44
  177. package/dist/adapters/sqlite-native/tools/window.d.ts +0 -7
  178. package/dist/adapters/sqlite-native/tools/window.d.ts.map +0 -1
  179. package/dist/chunk-E5IESRTK.js +0 -489
  180. package/dist/server/registration/audit-tools.d.ts +0 -13
  181. package/dist/server/registration/audit-tools.d.ts.map +0 -1
  182. package/dist/utils/insights-manager.d.ts +0 -39
  183. package/dist/utils/insights-manager.d.ts.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- mcp-name: io.github.neverinfamous/db-mcp -->
4
4
 
5
- **SQLite MCP Server** with 170+ 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.
5
+ **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.
6
6
 
7
7
  [![GitHub](https://img.shields.io/badge/GitHub-neverinfamous/db--mcp-blue?logo=github)](https://github.com/neverinfamous/db-mcp)
8
8
  ![GitHub Release](https://img.shields.io/github/v/release/neverinfamous/db-mcp)
@@ -15,7 +15,7 @@
15
15
  [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://github.com/neverinfamous/db-mcp)
16
16
  [![E2E](https://github.com/neverinfamous/db-mcp/actions/workflows/e2e.yml/badge.svg)](https://github.com/neverinfamous/db-mcp/actions/workflows/e2e.yml)
17
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-87.54%25-green.svg)](https://github.com/neverinfamous/db-mcp)
18
+ [![Coverage](https://img.shields.io/badge/Coverage-90.04%25-green.svg)](https://github.com/neverinfamous/db-mcp)
19
19
 
20
20
  **[Wiki](https://github.com/neverinfamous/db-mcp/wiki)** • **[Changelog](CHANGELOG.md)**
21
21
 
@@ -23,21 +23,27 @@
23
23
 
24
24
  ## 🎯 What Sets Us Apart
25
25
 
26
- | Feature | Description |
27
- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
28
- | **170+ 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` |
30
- | **10 AI-Powered Prompts** | Guided workflows for schema exploration, query building, data analysis, optimization, migration, debugging, and hybrid FTS5 + vector search |
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 170+ 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
- | **OAuth 2.1 + Access Control** | Enterprise-ready security with RFC 9728/8414 compliance, granular scopes (`full`, `read`, `write`, `admin`, `db:*`, `table:*:*`), and Keycloak integration |
35
- | **Smart Tool Filtering** | 10 tool groups + 7 shortcuts let you stay within IDE limits while exposing exactly what you need |
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
- | **Production-Ready Security** | SQL injection protection (parameterized queries + Unicode-normalized WHERE clause validation), sandboxed code execution (V8 `codeGeneration` restrictions, frozen prototypes, 29 blocked patterns, Proxy nullified, RPC allowlist), CORS deny-all default, fail-closed scope enforcement, JWT claims sanitization, 7 security headers, body size limits, rate limiting with Retry-After, slowloris timeouts, `trustProxy`, opt-in HSTS, non-root Docker, and build provenance |
38
- | **Strict TypeScript** | 100% type-safe codebase with strict mode, no `any` types, 1911 unit tests + 1136 E2E tests and 90% coverage |
39
- | **Deterministic Error Handling** | Every tool returns structured `{success, error, code, category, suggestion, recoverable}` responses no raw exceptions, no silent failures. Agents get enriched error context with actionable suggestions instead of cryptic SQLite codes |
40
- | **MCP 2025-03-26 Compliant** | Full protocol support with tool safety hints (`sensitiveHint`, `readOnlyHint`), resource priorities, and progress notifications |
26
+ | Feature | Description |
27
+ | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
28
+ | **181+ 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
+ | **Deep Observability** | Built-in Prometheus `/metrics` export, real-time `sqlite://metrics` MCP resource, historical persistence to a `SystemDb` sidecar, and a granular `sqlite_audit_search` tool for compliance and investigation |
30
+ | **Dynamic Configuration** | Full YAML/JSON config file support (`--config`) with precedence rules, plus a `sqlite_server_config` tool for live runtime config updates (e.g., log levels) without server restarts |
31
+ | **Advanced Query & Search** | O(1) cursor-based keyset pagination, faceted search aggregation, and `sqlite_hybrid_search` orchestrating FTS5 + Vector similarity with Reciprocal Rank Fusion (RRF) in a single tool call |
32
+ | **AI Index Recommendations** | `sqlite_index_audit` automatically analyzes `EXPLAIN QUERY PLAN` responses to suggest optimized composite and partial indexes based on workload patterns |
33
+ | **Real-time Subscriptions** | Native `resources/subscribe` support pushing event-driven notifications for `sqlite://schema` DDL changes and periodic `sqlite://health` updates directly to clients |
34
+ | **22 Resources** | 11 data resources (schema, tables, table_schema, indexes, views, health, meta, audit, metrics, compile_options, pragma) + 11 help resources (`sqlite://help` + per-group reference) filtered by `--tool-filter` |
35
+ | **10 AI-Powered Prompts** | Guided workflows for schema exploration, query building, data analysis, optimization, migration, debugging, and hybrid FTS5 + vector search |
36
+ | **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 180+ capabilities locally, reducing token overhead by 70–90% and supercharging AI agent reasoning |
37
+ | **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 |
38
+ | **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 |
39
+ | **OAuth 2.1 + Access Control** | Enterprise-ready security with RFC 9728/8414 compliance, granular scopes (`full`, `read`, `write`, `admin`, `db:*`, `table:*:*`), and Keycloak integration |
40
+ | **Smart Tool Filtering** | 10 tool groups + 7 shortcuts let you stay within IDE limits while exposing exactly what you need |
41
+ | **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 |
42
+ | **Production-Ready Security** | SQL injection protection (parameterized queries + Unicode-normalized WHERE clause validation), sandboxed code execution (V8 `codeGeneration` restrictions, frozen prototypes, 29 blocked patterns, Proxy nullified, RPC allowlist), CORS deny-all default, fail-closed scope enforcement, JWT claims sanitization, 7 security headers, body size limits, rate limiting with Retry-After, slowloris timeouts, `trustedProxyIps`, opt-in HSTS, non-root Docker, and build provenance |
43
+ | **Encryption at Rest** | Native SQLCipher support via `--encryption-key` or `DB_ENCRYPTION_KEY`. Dynamically loads `better-sqlite3-multiple-ciphers` and automatically encrypts the sidecar `SystemDb` audit logs to prevent sensitive queries from leaking |
44
+ | **Strict TypeScript** | 100% type-safe codebase with strict mode, no `any` types, 1911 unit tests + 1136 E2E tests and 90% coverage |
45
+ | **Deterministic Error Handling** | Every tool returns structured `{success, error, code, category, suggestion, recoverable}` responses — no raw exceptions, no silent failures. Agents get enriched error context with actionable suggestions instead of cryptic SQLite codes |
46
+ | **MCP 2025-03-26 Compliant** | Full protocol support with tool safety hints (`sensitiveHint`, `readOnlyHint`), resource priorities, and progress notifications |
41
47
 
42
48
  ## 🚀 Quick Start
43
49
 
@@ -75,13 +81,13 @@ cd db-mcp
75
81
  Install dependencies:
76
82
 
77
83
  ```bash
78
- npm install
84
+ pnpm install
79
85
  ```
80
86
 
81
87
  Build the project:
82
88
 
83
89
  ```bash
84
- npm run build
90
+ pnpm run build
85
91
  ```
86
92
 
87
93
  Run the server with **Native backend** (better-sqlite3 — full features, requires Node.js native build):
@@ -96,7 +102,7 @@ Or with **WASM backend** (sql.js — cross-platform, no compilation required):
96
102
  node dist/cli.js --transport stdio --sqlite ./database.db
97
103
  ```
98
104
 
99
- > **Backend Choice:** Use `--sqlite-native` for full features (166 group tools, transactions, window functions, SpatiaLite). Use `--sqlite` for WASM mode (139 tools, no native dependencies).
105
+ > **Backend Choice:** Use `--sqlite-native` for full features (181 MCP tools / 170 group tools, transactions, window functions, SpatiaLite). Use `--sqlite` for WASM mode (154 MCP tools / 143 group tools, no native dependencies).
100
106
 
101
107
  ### Verify It Works
102
108
 
@@ -115,7 +121,7 @@ Expected output:
115
121
  Run the test suite:
116
122
 
117
123
  ```bash
118
- npm run test
124
+ pnpm run test
119
125
  ```
120
126
 
121
127
  ### Prerequisites
@@ -140,7 +146,7 @@ Set `CODEMODE_ISOLATION=vm` with `CODEMODE_ISOLATION_INSECURE=1` to fall back to
140
146
 
141
147
  ### ⚡ Code Mode Only (Maximum Token Savings)
142
148
 
143
- If you control your own setup, you can run with **only Code Mode enabled** — a single tool that provides access to all 170+ tools' worth of capability through the `sqlite.*` API:
149
+ 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:
144
150
 
145
151
  ```json
146
152
  {
@@ -173,7 +179,7 @@ This exposes just `sqlite_execute_code` plus built-in tools. The agent writes Ja
173
179
  ## 🎛️ Tool Filtering
174
180
 
175
181
  > [!IMPORTANT]
176
- > **AI-enabled IDEs like Cursor have tool limits.** With 170+ 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.
182
+ > **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.
177
183
 
178
184
  ### Quick Start: Recommended Configurations
179
185
 
@@ -203,13 +209,13 @@ Specify exactly the groups you need:
203
209
 
204
210
  | Shortcut | WASM | Native | + Built-in | What's Included |
205
211
  | ------------ | ------ | ------ | ---------- | ------------------------------ |
206
- | `starter` | **60** | **65** | +4 | Core, JSON, Text |
207
- | `analytics` | 63 | 69 | +4 | Core, JSON, Stats |
208
- | `search` | 46 | 51 | +4 | Core, Text, Vector |
209
- | `spatial` | 36 | 43 | +4 | Core, Geo, Vector |
210
- | `dev-schema` | 37 | 37 | +4 | Core, Introspection, Migration |
211
- | `minimal` | 21 | 21 | +4 | Core only |
212
- | `full` | 139 | 166 | +4 | Everything enabled |
212
+ | `starter` | **65** | **70** | +4 | Core, JSON, Text |
213
+ | `analytics` | 67 | 73 | +4 | Core, JSON, Stats |
214
+ | `search` | 51 | 56 | +4 | Core, Text, Vector |
215
+ | `spatial` | 40 | 47 | +4 | Core, Geo, Vector |
216
+ | `dev-schema` | 41 | 41 | +4 | Core, Introspection, Migration |
217
+ | `minimal` | 25 | 25 | +4 | Core only |
218
+ | `full` | 143 | 170 | +4 | Everything enabled |
213
219
 
214
220
  ### Tool Groups (10 Available)
215
221
 
@@ -217,13 +223,12 @@ Specify exactly the groups you need:
217
223
 
218
224
  | Group | WASM | Native | + Built-in | Description |
219
225
  | --------------- | ---- | ------ | ---------- | ------------------------------------------ |
220
- | `codemode` | 1 | 1 | +4 | Code Mode (sandboxed code execution) 🧠 |
221
- | `core` | 21 | 21 | +4 | Basic CRUD, schema, tables |
226
+ | `core` | 25 | 25 | +4 | Basic CRUD, schema, tables |
222
227
  | `json` | 25 | 25 | +4 | JSON/JSONB operations, analysis |
223
- | `text` | 14 | 19 | +4 | Text processing + FTS5 + advanced search |
228
+ | `text` | 15 | 20 | +4 | Text processing + FTS5 + advanced search |
224
229
  | `stats` | 17 | 23 | +4 | Descriptive, inference, window functions |
225
230
  | `vector` | 11 | 11 | +4 | Vector storage, similarity search |
226
- | `admin` | 31 | 32 | +4 | DB maintenance, backup, virtual tables |
231
+ | `admin` | 30 | 31 | +4 | DB maintenance, backup, virtual tables |
227
232
  | `transactions` | 0 | 8 | +4 | Commit, rollback, savepoints (Native only) |
228
233
  | `geo` | 4 | 11 | +4 | Geospatial + SpatiaLite (Native only) |
229
234
  | `introspection` | 10 | 10 | +4 | Schema mapping, FK graph, analysis |
@@ -269,9 +274,9 @@ This is useful for scripted or automated clients that need a minimal, precise se
269
274
 
270
275
  ```bash
271
276
  --tool-filter "starter"
272
- --tool-filter "core,json,text,fts5"
277
+ --tool-filter "core,json,text,stats"
273
278
  --tool-filter "starter,+stats"
274
- --tool-filter "starter,-fts5"
279
+ --tool-filter "starter,-vector"
275
280
  ```
276
281
 
277
282
  **Legacy Syntax (still supported):**
@@ -363,16 +368,17 @@ MCP resources provide read-only access to database metadata:
363
368
  | `sqlite_meta` | `sqlite://meta` | Database metadata and PRAGMAs | `core,admin` |
364
369
  | `sqlite_compile_options` | `sqlite://compile_options` | SQLite compile-time build options | _(read-only)_ |
365
370
  | `sqlite_pragma` | `sqlite://pragma` | Runtime PRAGMA config snapshot | _(read-only)_ |
366
- | `sqlite_insights` | `memo://insights` | Business insights memo (analysis) | `core,admin` |
367
371
  | `sqlite_audit` | `sqlite://audit` | Recent audit log + backup stats | `--audit-log` |
372
+ | `sqlite_metrics` | `sqlite://metrics` | Internal server metrics | _(read-only)_ |
368
373
 
369
- ### Help Resources (1 + up to 8)
374
+ ### Help Resources (1 + up to 10)
370
375
 
371
376
  On-demand tool reference documentation, filtered by `--tool-filter`:
372
377
 
373
378
  | Resource | URI | Description | When Registered |
374
379
  | --------------------------- | ----------------------------- | ----------------------------------------------------- | --------------------------- |
375
380
  | `sqlite_help` | `sqlite://help` | Gotchas, WASM vs Native, Code Mode API | Always |
381
+ | `sqlite_help_core` | `sqlite://help/core` | Core CRUD and table operations reference | When core group on |
376
382
  | `sqlite_help_json` | `sqlite://help/json` | JSON/JSONB operations reference | When json group on |
377
383
  | `sqlite_help_text` | `sqlite://help/text` | Text processing + FTS5 reference | When text group on |
378
384
  | `sqlite_help_stats` | `sqlite://help/stats` | Statistical analysis + window functions reference | When stats group on |
@@ -406,28 +412,34 @@ MCP prompts provide AI-assisted database workflows:
406
412
 
407
413
  ### Environment Variables
408
414
 
409
- | Variable | Default | Description |
410
- | --------------------------- | --------- | ------------------------------------------------------------------------------ |
411
- | `MCP_HOST` | `0.0.0.0` | Host/IP to bind to (CLI: `--server-host`) |
412
- | `SQLITE_DATABASE` | — | SQLite database path (CLI: `--sqlite` / `--sqlite-native`) |
413
- | `DB_MCP_TOOL_FILTER` | — | Tool filter string (CLI: `--tool-filter`) |
414
- | `OAUTH_ENABLED` | `false` | Enable OAuth 2.1 (CLI: `--oauth-enabled`) |
415
- | `OAUTH_ISSUER` | — | Authorization server URL (CLI: `--oauth-issuer`) |
416
- | `OAUTH_AUDIENCE` | | Expected token audience (CLI: `--oauth-audience`) |
417
- | `OAUTH_JWKS_URI` | — | JWKS URI, auto-discovered if omitted (CLI: `--oauth-jwks-uri`) |
418
- | `OAUTH_CLOCK_TOLERANCE` | `60` | Clock tolerance in seconds (CLI: `--oauth-clock-tolerance`) |
419
- | `LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warning`, `error` |
420
- | `METADATA_CACHE_TTL_MS` | `5000` | Schema cache TTL in ms (auto-invalidated on DDL operations) |
421
- | `CODEMODE_ISOLATION` | `isolate` | Code Mode sandbox: `isolate` (isolated-vm native) or `worker` |
422
- | `CODE_MODE_MAX_RESULT_SIZE` | `102400` | Maximum Code Mode result payload in bytes (default 100KB, cap 50MB) |
423
- | `MCP_RATE_LIMIT_MAX` | `100` | Max requests/minute per IP (HTTP transport) |
424
- | `CSV_EXTENSION_PATH` | | Custom path to CSV extension binary (native only) |
425
- | `SPATIALITE_PATH` | | Custom path to SpatiaLite extension binary (native only) |
426
- | `AUDIT_LOG` | | Audit log file path, or `stderr` (CLI: `--audit-log`) |
427
- | `AUDIT_REDACT` | `true` | Redact tool arguments from audit entries (CLI: `--audit-no-redact` to disable) |
428
- | `AUDIT_READS` | `false` | Also log read-scoped tool invocations (CLI: `--audit-reads`) |
429
- | `AUDIT_BACKUP` | `false` | Enable pre-mutation DDL snapshots (CLI: `--audit-backup`) |
430
- | `AUDIT_BACKUP_DATA` | `false` | Include sample data rows in snapshots (CLI: `--audit-backup-data`) |
415
+ | Variable | Default | Description |
416
+ | --------------------------- | ----------- | ------------------------------------------------------------------------------ |
417
+ | `MCP_HOST` | `127.0.0.1` | Host/IP to bind to (`0.0.0.0` in Docker) (CLI: `--server-host`) |
418
+ | `SQLITE_DATABASE` | — | SQLite database path (CLI: `--sqlite` / `--sqlite-native`) |
419
+ | `DB_ENCRYPTION_KEY` | — | SQLCipher encryption key (Native only) (CLI: `--encryption-key`) |
420
+ | `DB_MCP_TOOL_FILTER` | | Tool filter string (CLI: `--tool-filter`) |
421
+ | `METRICS_EXPORT` | — | Export metrics at HTTP /metrics (e.g., `prometheus`) (CLI: `--metrics-export`) |
422
+ | `OAUTH_ENABLED` | `false` | Enable OAuth 2.1 (CLI: `--oauth-enabled`) |
423
+ | `OAUTH_ISSUER` | — | Authorization server URL (CLI: `--oauth-issuer`) |
424
+ | `OAUTH_AUDIENCE` | | Expected token audience (CLI: `--oauth-audience`) |
425
+ | `OAUTH_JWKS_URI` | | JWKS URI, auto-discovered if omitted (CLI: `--oauth-jwks-uri`) |
426
+ | `OAUTH_CLOCK_TOLERANCE` | `60` | Clock tolerance in seconds (CLI: `--oauth-clock-tolerance`) |
427
+ | `MCP_ENABLE_HSTS` | `false` | Enable HSTS header (CLI: `--enable-hsts`) |
428
+ | `NO_AUTH_ENFORCEMENT` | `false` | Explicitly bypass auth enforcement for HTTP (CLI: `--no-auth-enforcement`) |
429
+ | `LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warning`, `error` |
430
+ | `METADATA_CACHE_TTL_MS` | `5000` | Schema cache TTL in ms (auto-invalidated on DDL operations) |
431
+ | `CODEMODE_ISOLATION` | `isolate` | Code Mode sandbox: `isolate` (isolated-vm native) or `worker` |
432
+ | `CODE_MODE_MAX_RESULT_SIZE` | `102400` | Maximum Code Mode result payload in bytes (default 100KB, cap 50MB) |
433
+ | `MCP_RATE_LIMIT_MAX` | `100` | Max requests/minute per IP (HTTP transport) |
434
+ | `CSV_EXTENSION_PATH` | | Custom path to CSV extension binary (native only) |
435
+ | `SPATIALITE_PATH` | | Custom path to SpatiaLite extension binary (native only) |
436
+ | `ALLOWED_IO_ROOTS` | | JSON array or comma-separated list of absolute paths allowed for IO operations |
437
+ | `MCP_AUTH_TOKEN` | — | Simple bearer token for HTTP auth (CLI: `--auth-token`) |
438
+ | `AUDIT_LOG` | — | Audit log file path, or `stderr` (CLI: `--audit-log`) |
439
+ | `AUDIT_REDACT` | `true` | Redact tool arguments from audit entries (CLI: `--audit-no-redact` to disable) |
440
+ | `AUDIT_READS` | `false` | Also log read-scoped tool invocations (CLI: `--audit-reads`) |
441
+ | `AUDIT_BACKUP` | `false` | Enable pre-mutation DDL snapshots (CLI: `--audit-backup`) |
442
+ | `AUDIT_BACKUP_DATA` | `false` | Include sample data rows in snapshots (CLI: `--audit-backup-data`) |
431
443
 
432
444
  > **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).
433
445
 
@@ -438,10 +450,11 @@ db-mcp [options]
438
450
 
439
451
  Transport: --transport <stdio|http|sse> --port <N> --server-host <host> --stateless
440
452
  Auth: --oauth-enabled --oauth-issuer <url> --oauth-audience <aud>
441
- Database: --sqlite <path> | --sqlite-native <path>
453
+ Database: --sqlite <path> | --sqlite-native <path> [--encryption-key <key>]
442
454
  Extensions: --csv --spatialite (native only)
455
+ Security: --allowed-io-roots <paths>
443
456
  Audit: --audit-log <path> --audit-no-redact --audit-reads --audit-backup --audit-backup-data
444
- Server: --name <name> --version <ver> --tool-filter <filter>
457
+ Server: --name <name> --version <ver> --metrics-export <type> --tool-filter <filter>
445
458
  ```
446
459
 
447
460
  > CLI flags override environment variables. Run `node dist/cli.js --help` for full details.
@@ -470,7 +483,7 @@ Add to your `~/.cursor/mcp.json`, Claude Desktop config, or equivalent:
470
483
  ```
471
484
 
472
485
  > [!TIP]
473
- > **Switching backends:** The config above uses the **Native** backend (better-sqlite3, 166 tools). To use the **WASM** backend (sql.js, 139 tools, zero native dependencies), change `--sqlite-native` to `--sqlite` in the args array. See the [Backend Options table in DOCKER_README](DOCKER_README.md#backend-options) for feature differences.
486
+ > **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-native` to `--sqlite` in the args array. See the [Backend Options table in DOCKER_README](DOCKER_README.md#backend-options) for feature differences.
474
487
 
475
488
  **Variants** (modify the `args` array above):
476
489
 
@@ -494,7 +507,8 @@ For remote access, web-based clients, or HTTP-compatible MCP hosts, use the HTTP
494
507
  node dist/cli.js \
495
508
  --transport http \
496
509
  --port 3000 \
497
- --sqlite-native ./database.db
510
+ --sqlite-native ./database.db \
511
+ --allowed-io-roots $(pwd)
498
512
  ```
499
513
 
500
514
  **Docker:**
@@ -504,7 +518,8 @@ docker run --rm -p 3000:3000 \
504
518
  -v ./data:/app/data \
505
519
  writenotenow/db-mcp:latest \
506
520
  --transport http --port 3000 \
507
- --sqlite-native /app/data/database.db
521
+ --sqlite-native /app/data/database.db \
522
+ --allowed-io-roots /app/data
508
523
  ```
509
524
 
510
525
  The server supports **two MCP transport protocols simultaneously**, enabling both modern and legacy clients to connect:
@@ -526,7 +541,7 @@ Sessions are managed via the `Mcp-Session-Id` header.
526
541
  For serverless/stateless deployments where sessions are not needed:
527
542
 
528
543
  ```bash
529
- node dist/cli.js --transport http --port 3000 --stateless --sqlite-native ./database.db
544
+ node dist/cli.js --transport http --port 3000 --stateless --sqlite-native ./database.db --allowed-io-roots $(pwd)
530
545
  ```
531
546
 
532
547
  In stateless mode: `GET /mcp` returns 405, `DELETE /mcp` returns 204, `/sse` and `/messages` return 404. Each `POST /mcp` creates a fresh transport.
@@ -559,6 +574,7 @@ node dist/cli.js \
559
574
  --transport http \
560
575
  --port 3000 \
561
576
  --sqlite-native ./database.db \
577
+ --allowed-io-roots $(pwd) \
562
578
  --oauth-enabled \
563
579
  --oauth-issuer http://localhost:8080/realms/db-mcp \
564
580
  --oauth-audience db-mcp-server
@@ -598,21 +614,42 @@ The server exposes metadata at `/.well-known/oauth-protected-resource`.
598
614
  > [!WARNING]
599
615
  > **HTTP without authentication:** When using `--transport http` without enabling OAuth, all clients have full unrestricted access. Always enable authentication for production HTTP deployments. See [SECURITY.md](SECURITY.md) for details.
600
616
 
617
+ ## 🔐 Encryption at Rest (Native Only)
618
+
619
+ 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.
620
+
621
+ **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.
622
+
623
+ **Configuring the Key**:
624
+ You can provide the key via the `--encryption-key` CLI flag or the `DB_ENCRYPTION_KEY` environment variable.
625
+
626
+ 1. **Strong Passphrase**: A standard string. SQLCipher will automatically use PBKDF2 key derivation.
627
+ ```bash
628
+ DB_ENCRYPTION_KEY="your-strong-passphrase-here"
629
+ ```
630
+ 2. **Raw Hex Key (Best Performance)**: To skip PBKDF2 derivation overhead, provide an exact 256-bit raw hex key prefixed with `x` and wrapped in single quotes:
631
+ ```bash
632
+ DB_ENCRYPTION_KEY="x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'"
633
+ ```
634
+
635
+ > [!WARNING]
636
+ > **Audit Log Compatibility**: The `DB_ENCRYPTION_KEY` environment variable applies globally and will cause the internal `SystemDb` to attempt to decrypt your audit log (`--audit-log`). If you have an existing unencrypted audit log, the server will fail to start with `file is not a database`. To encrypt ONLY your target database (leaving the audit log unencrypted), use the `--encryption-key` CLI flag instead of the global environment variable.
637
+
601
638
  ## 📊 Benchmarks
602
639
 
603
640
  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:
604
641
 
605
- - **Tool dispatch:** 11–14M ops/sec — Map-based lookup is effectively zero-cost
606
- - **Auth scope checks:** 6–8M ops/sec — OAuth middleware adds no measurable latency
607
- - **Identifier validation:** 6–7M ops/sec — SQL sanitization is near-instant
608
- - **Schema cache hits:** 4–6M ops/sec — metadata lookups avoid redundant queries
609
- - **Debug log (filtered):** 10–11M ops/sec — disabled log levels are true no-ops
610
- - **Code Mode security:** 1–1.3M validations/sec for typical code, blocked patterns rejected in <1 µs
611
- - **Sandbox execution:** ~4.4–4.9K executions/sec — trivial code round-trips through V8 isolate in ~0.2 ms
642
+ - **Tool dispatch:** 6–14M ops/sec — Map-based lookup is effectively zero-cost
643
+ - **Auth scope checks:** 4–8M ops/sec — OAuth middleware adds no measurable latency
644
+ - **Identifier validation:** 4–7M ops/sec — SQL sanitization is near-instant
645
+ - **Schema cache hits:** 3–6M ops/sec — metadata lookups avoid redundant queries
646
+ - **Debug log (filtered):** 5–11M ops/sec — disabled log levels are true no-ops
647
+ - **Code Mode security:** ~0.2–1.3M validations/sec for typical code, blocked patterns rejected in 1-2 µs
648
+ - **Sandbox execution:** ~0.5–4.9K executions/sec — trivial code round-trips through V8 isolate in 0.2-1.5 ms
612
649
 
613
650
  ```bash
614
- npm run bench # Run all benchmarks
615
- npm run bench:verbose # Verbose mode with detailed timings
651
+ pnpm run bench # Run all benchmarks
652
+ pnpm run bench:verbose # Verbose mode with detailed timings
616
653
  ```
617
654
 
618
655
  | Benchmark | What It Measures |