db-mcp 1.0.2 → 1.1.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 (241) hide show
  1. package/.gitattributes +2 -0
  2. package/LICENSE +1 -1
  3. package/README.md +244 -518
  4. package/dist/chunk-4IA3DB5C.js +135 -0
  5. package/dist/chunk-AOUL5SHS.js +930 -0
  6. package/dist/chunk-DWJXQEFA.js +13759 -0
  7. package/dist/chunk-DZQLDEQS.js +879 -0
  8. package/dist/chunk-S5IDDSSB.js +74 -0
  9. package/dist/chunk-Z2GFQU3G.js +363 -0
  10. package/dist/cli.d.ts +0 -7
  11. package/dist/cli.js +227 -183
  12. package/dist/http-VSB7DBJR.js +1541 -0
  13. package/dist/index.d.ts +842 -10
  14. package/dist/index.js +5 -17
  15. package/dist/sqlite-VHBA4ABV.js +600 -0
  16. package/dist/sqlite-native-D2LH5ZT7.js +2498 -0
  17. package/dist/worker-script.d.ts +2 -0
  18. package/dist/worker-script.js +126 -0
  19. package/package.json +26 -16
  20. package/playwright.config.ts +101 -0
  21. package/scripts/generate-server-instructions.ts +111 -0
  22. package/server.json +5 -6
  23. package/test-server/README.md +118 -0
  24. package/test-server/code-map.md +409 -0
  25. package/test-server/fixtures/sample.csv +6 -0
  26. package/test-server/reset-database.ps1 +373 -0
  27. package/test-server/sample.csv +11 -0
  28. package/test-server/test-agent-experience.md +243 -0
  29. package/test-server/test-database.sql +388 -0
  30. package/test-server/test-group-tools.md +861 -0
  31. package/test-server/test-help-resources.mjs +238 -0
  32. package/test-server/test-preflight.md +53 -0
  33. package/test-server/test-prompts.md +354 -0
  34. package/test-server/test-resources.md +245 -0
  35. package/test-server/test-tool-annotations.mjs +157 -0
  36. package/test-server/test-tools-advanced-1.md +517 -0
  37. package/test-server/test-tools-advanced-2.md +487 -0
  38. package/test-server/test-tools-codemode.md +629 -0
  39. package/test-server/test-tools.md +176 -0
  40. package/test-server/tool-reference.md +236 -0
  41. package/tsconfig.test.json +9 -0
  42. package/dist/adapters/DatabaseAdapter.d.ts +0 -141
  43. package/dist/adapters/DatabaseAdapter.d.ts.map +0 -1
  44. package/dist/adapters/DatabaseAdapter.js +0 -131
  45. package/dist/adapters/DatabaseAdapter.js.map +0 -1
  46. package/dist/adapters/sqlite/SchemaManager.d.ts +0 -58
  47. package/dist/adapters/sqlite/SchemaManager.d.ts.map +0 -1
  48. package/dist/adapters/sqlite/SchemaManager.js +0 -187
  49. package/dist/adapters/sqlite/SchemaManager.js.map +0 -1
  50. package/dist/adapters/sqlite/SqliteAdapter.d.ts +0 -161
  51. package/dist/adapters/sqlite/SqliteAdapter.d.ts.map +0 -1
  52. package/dist/adapters/sqlite/SqliteAdapter.js +0 -741
  53. package/dist/adapters/sqlite/SqliteAdapter.js.map +0 -1
  54. package/dist/adapters/sqlite/index.d.ts +0 -9
  55. package/dist/adapters/sqlite/index.d.ts.map +0 -1
  56. package/dist/adapters/sqlite/index.js +0 -8
  57. package/dist/adapters/sqlite/index.js.map +0 -1
  58. package/dist/adapters/sqlite/json-utils.d.ts +0 -100
  59. package/dist/adapters/sqlite/json-utils.d.ts.map +0 -1
  60. package/dist/adapters/sqlite/json-utils.js +0 -274
  61. package/dist/adapters/sqlite/json-utils.js.map +0 -1
  62. package/dist/adapters/sqlite/output-schemas.d.ts +0 -1187
  63. package/dist/adapters/sqlite/output-schemas.d.ts.map +0 -1
  64. package/dist/adapters/sqlite/output-schemas.js +0 -1337
  65. package/dist/adapters/sqlite/output-schemas.js.map +0 -1
  66. package/dist/adapters/sqlite/prompts.d.ts +0 -13
  67. package/dist/adapters/sqlite/prompts.d.ts.map +0 -1
  68. package/dist/adapters/sqlite/prompts.js +0 -605
  69. package/dist/adapters/sqlite/prompts.js.map +0 -1
  70. package/dist/adapters/sqlite/resources.d.ts +0 -13
  71. package/dist/adapters/sqlite/resources.d.ts.map +0 -1
  72. package/dist/adapters/sqlite/resources.js +0 -251
  73. package/dist/adapters/sqlite/resources.js.map +0 -1
  74. package/dist/adapters/sqlite/tools/admin.d.ts +0 -14
  75. package/dist/adapters/sqlite/tools/admin.d.ts.map +0 -1
  76. package/dist/adapters/sqlite/tools/admin.js +0 -788
  77. package/dist/adapters/sqlite/tools/admin.js.map +0 -1
  78. package/dist/adapters/sqlite/tools/core.d.ts +0 -25
  79. package/dist/adapters/sqlite/tools/core.d.ts.map +0 -1
  80. package/dist/adapters/sqlite/tools/core.js +0 -359
  81. package/dist/adapters/sqlite/tools/core.js.map +0 -1
  82. package/dist/adapters/sqlite/tools/fts.d.ts +0 -13
  83. package/dist/adapters/sqlite/tools/fts.d.ts.map +0 -1
  84. package/dist/adapters/sqlite/tools/fts.js +0 -347
  85. package/dist/adapters/sqlite/tools/fts.js.map +0 -1
  86. package/dist/adapters/sqlite/tools/geo.d.ts +0 -14
  87. package/dist/adapters/sqlite/tools/geo.d.ts.map +0 -1
  88. package/dist/adapters/sqlite/tools/geo.js +0 -252
  89. package/dist/adapters/sqlite/tools/geo.js.map +0 -1
  90. package/dist/adapters/sqlite/tools/index.d.ts +0 -30
  91. package/dist/adapters/sqlite/tools/index.d.ts.map +0 -1
  92. package/dist/adapters/sqlite/tools/index.js +0 -61
  93. package/dist/adapters/sqlite/tools/index.js.map +0 -1
  94. package/dist/adapters/sqlite/tools/json-helpers.d.ts +0 -14
  95. package/dist/adapters/sqlite/tools/json-helpers.d.ts.map +0 -1
  96. package/dist/adapters/sqlite/tools/json-helpers.js +0 -477
  97. package/dist/adapters/sqlite/tools/json-helpers.js.map +0 -1
  98. package/dist/adapters/sqlite/tools/json-operations.d.ts +0 -14
  99. package/dist/adapters/sqlite/tools/json-operations.d.ts.map +0 -1
  100. package/dist/adapters/sqlite/tools/json-operations.js +0 -839
  101. package/dist/adapters/sqlite/tools/json-operations.js.map +0 -1
  102. package/dist/adapters/sqlite/tools/stats.d.ts +0 -15
  103. package/dist/adapters/sqlite/tools/stats.d.ts.map +0 -1
  104. package/dist/adapters/sqlite/tools/stats.js +0 -1219
  105. package/dist/adapters/sqlite/tools/stats.js.map +0 -1
  106. package/dist/adapters/sqlite/tools/text.d.ts +0 -14
  107. package/dist/adapters/sqlite/tools/text.d.ts.map +0 -1
  108. package/dist/adapters/sqlite/tools/text.js +0 -1141
  109. package/dist/adapters/sqlite/tools/text.js.map +0 -1
  110. package/dist/adapters/sqlite/tools/vector.d.ts +0 -14
  111. package/dist/adapters/sqlite/tools/vector.d.ts.map +0 -1
  112. package/dist/adapters/sqlite/tools/vector.js +0 -613
  113. package/dist/adapters/sqlite/tools/vector.js.map +0 -1
  114. package/dist/adapters/sqlite/tools/virtual.d.ts +0 -13
  115. package/dist/adapters/sqlite/tools/virtual.d.ts.map +0 -1
  116. package/dist/adapters/sqlite/tools/virtual.js +0 -930
  117. package/dist/adapters/sqlite/tools/virtual.js.map +0 -1
  118. package/dist/adapters/sqlite/types.d.ts +0 -207
  119. package/dist/adapters/sqlite/types.d.ts.map +0 -1
  120. package/dist/adapters/sqlite/types.js +0 -186
  121. package/dist/adapters/sqlite/types.js.map +0 -1
  122. package/dist/adapters/sqlite-native/NativeSqliteAdapter.d.ts +0 -163
  123. package/dist/adapters/sqlite-native/NativeSqliteAdapter.d.ts.map +0 -1
  124. package/dist/adapters/sqlite-native/NativeSqliteAdapter.js +0 -748
  125. package/dist/adapters/sqlite-native/NativeSqliteAdapter.js.map +0 -1
  126. package/dist/adapters/sqlite-native/index.d.ts +0 -11
  127. package/dist/adapters/sqlite-native/index.d.ts.map +0 -1
  128. package/dist/adapters/sqlite-native/index.js +0 -11
  129. package/dist/adapters/sqlite-native/index.js.map +0 -1
  130. package/dist/adapters/sqlite-native/tools/spatialite.d.ts +0 -19
  131. package/dist/adapters/sqlite-native/tools/spatialite.d.ts.map +0 -1
  132. package/dist/adapters/sqlite-native/tools/spatialite.js +0 -628
  133. package/dist/adapters/sqlite-native/tools/spatialite.js.map +0 -1
  134. package/dist/adapters/sqlite-native/tools/transactions.d.ts +0 -12
  135. package/dist/adapters/sqlite-native/tools/transactions.d.ts.map +0 -1
  136. package/dist/adapters/sqlite-native/tools/transactions.js +0 -255
  137. package/dist/adapters/sqlite-native/tools/transactions.js.map +0 -1
  138. package/dist/adapters/sqlite-native/tools/window.d.ts +0 -12
  139. package/dist/adapters/sqlite-native/tools/window.d.ts.map +0 -1
  140. package/dist/adapters/sqlite-native/tools/window.js +0 -370
  141. package/dist/adapters/sqlite-native/tools/window.js.map +0 -1
  142. package/dist/auth/AuthorizationServerDiscovery.d.ts +0 -90
  143. package/dist/auth/AuthorizationServerDiscovery.d.ts.map +0 -1
  144. package/dist/auth/AuthorizationServerDiscovery.js +0 -204
  145. package/dist/auth/AuthorizationServerDiscovery.js.map +0 -1
  146. package/dist/auth/OAuthResourceServer.d.ts +0 -65
  147. package/dist/auth/OAuthResourceServer.d.ts.map +0 -1
  148. package/dist/auth/OAuthResourceServer.js +0 -121
  149. package/dist/auth/OAuthResourceServer.js.map +0 -1
  150. package/dist/auth/TokenValidator.d.ts +0 -60
  151. package/dist/auth/TokenValidator.d.ts.map +0 -1
  152. package/dist/auth/TokenValidator.js +0 -235
  153. package/dist/auth/TokenValidator.js.map +0 -1
  154. package/dist/auth/errors.d.ts +0 -74
  155. package/dist/auth/errors.d.ts.map +0 -1
  156. package/dist/auth/errors.js +0 -133
  157. package/dist/auth/errors.js.map +0 -1
  158. package/dist/auth/index.d.ts +0 -13
  159. package/dist/auth/index.d.ts.map +0 -1
  160. package/dist/auth/index.js +0 -15
  161. package/dist/auth/index.js.map +0 -1
  162. package/dist/auth/middleware.d.ts +0 -81
  163. package/dist/auth/middleware.d.ts.map +0 -1
  164. package/dist/auth/middleware.js +0 -291
  165. package/dist/auth/middleware.js.map +0 -1
  166. package/dist/auth/scopes.d.ts +0 -136
  167. package/dist/auth/scopes.d.ts.map +0 -1
  168. package/dist/auth/scopes.js +0 -349
  169. package/dist/auth/scopes.js.map +0 -1
  170. package/dist/auth/types.d.ts +0 -257
  171. package/dist/auth/types.d.ts.map +0 -1
  172. package/dist/auth/types.js +0 -8
  173. package/dist/auth/types.js.map +0 -1
  174. package/dist/cli.d.ts.map +0 -1
  175. package/dist/cli.js.map +0 -1
  176. package/dist/constants/ServerInstructions.d.ts +0 -45
  177. package/dist/constants/ServerInstructions.d.ts.map +0 -1
  178. package/dist/constants/ServerInstructions.js +0 -356
  179. package/dist/constants/ServerInstructions.js.map +0 -1
  180. package/dist/filtering/ToolConstants.d.ts +0 -34
  181. package/dist/filtering/ToolConstants.d.ts.map +0 -1
  182. package/dist/filtering/ToolConstants.js +0 -174
  183. package/dist/filtering/ToolConstants.js.map +0 -1
  184. package/dist/filtering/ToolFilter.d.ts +0 -82
  185. package/dist/filtering/ToolFilter.d.ts.map +0 -1
  186. package/dist/filtering/ToolFilter.js +0 -296
  187. package/dist/filtering/ToolFilter.js.map +0 -1
  188. package/dist/index.d.ts.map +0 -1
  189. package/dist/index.js.map +0 -1
  190. package/dist/server/McpServer.d.ts +0 -61
  191. package/dist/server/McpServer.d.ts.map +0 -1
  192. package/dist/server/McpServer.js +0 -270
  193. package/dist/server/McpServer.js.map +0 -1
  194. package/dist/transports/http.d.ts +0 -134
  195. package/dist/transports/http.d.ts.map +0 -1
  196. package/dist/transports/http.js +0 -516
  197. package/dist/transports/http.js.map +0 -1
  198. package/dist/transports/index.d.ts +0 -5
  199. package/dist/transports/index.d.ts.map +0 -1
  200. package/dist/transports/index.js +0 -5
  201. package/dist/transports/index.js.map +0 -1
  202. package/dist/types/index.d.ts +0 -380
  203. package/dist/types/index.d.ts.map +0 -1
  204. package/dist/types/index.js +0 -68
  205. package/dist/types/index.js.map +0 -1
  206. package/dist/utils/annotations.d.ts +0 -44
  207. package/dist/utils/annotations.d.ts.map +0 -1
  208. package/dist/utils/annotations.js +0 -77
  209. package/dist/utils/annotations.js.map +0 -1
  210. package/dist/utils/errors.d.ts +0 -155
  211. package/dist/utils/errors.d.ts.map +0 -1
  212. package/dist/utils/errors.js +0 -329
  213. package/dist/utils/errors.js.map +0 -1
  214. package/dist/utils/identifiers.d.ts +0 -121
  215. package/dist/utils/identifiers.d.ts.map +0 -1
  216. package/dist/utils/identifiers.js +0 -319
  217. package/dist/utils/identifiers.js.map +0 -1
  218. package/dist/utils/index.d.ts +0 -7
  219. package/dist/utils/index.d.ts.map +0 -1
  220. package/dist/utils/index.js +0 -7
  221. package/dist/utils/index.js.map +0 -1
  222. package/dist/utils/insightsManager.d.ts +0 -39
  223. package/dist/utils/insightsManager.d.ts.map +0 -1
  224. package/dist/utils/insightsManager.js +0 -63
  225. package/dist/utils/insightsManager.js.map +0 -1
  226. package/dist/utils/logger.d.ts +0 -189
  227. package/dist/utils/logger.d.ts.map +0 -1
  228. package/dist/utils/logger.js +0 -394
  229. package/dist/utils/logger.js.map +0 -1
  230. package/dist/utils/progress-utils.d.ts +0 -54
  231. package/dist/utils/progress-utils.d.ts.map +0 -1
  232. package/dist/utils/progress-utils.js +0 -74
  233. package/dist/utils/progress-utils.js.map +0 -1
  234. package/dist/utils/resourceAnnotations.d.ts +0 -36
  235. package/dist/utils/resourceAnnotations.d.ts.map +0 -1
  236. package/dist/utils/resourceAnnotations.js +0 -57
  237. package/dist/utils/resourceAnnotations.js.map +0 -1
  238. package/dist/utils/where-clause.d.ts +0 -41
  239. package/dist/utils/where-clause.d.ts.map +0 -1
  240. package/dist/utils/where-clause.js +0 -116
  241. package/dist/utils/where-clause.js.map +0 -1
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # db-mcp (SQLite MCP Server)
2
2
 
3
- **Last Updated February 4, 2026**
4
-
5
- **SQLite MCP Server** with HTTP/SSE Transport, OAuth 2.1 authentication, smart tool filtering, granular access control, 122 specialized tools, 8 resources, and 10 prompts. Available in WASM and better-sqlite3 variants.
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.
6
4
 
7
5
  [![GitHub](https://img.shields.io/badge/GitHub-neverinfamous/db--mcp-blue?logo=github)](https://github.com/neverinfamous/db-mcp)
8
6
  [![GitHub Release](https://img.shields.io/github/v/release/neverinfamous/db-mcp)](https://github.com/neverinfamous/db-mcp/releases/latest)
@@ -13,81 +11,33 @@
13
11
  [![MCP Registry](https://img.shields.io/badge/MCP_Registry-Published-green)](https://registry.modelcontextprotocol.io/v0/servers?search=io.github.neverinfamous/db-mcp)
14
12
  [![Security](https://img.shields.io/badge/Security-Enhanced-green.svg)](SECURITY.md)
15
13
  [![TypeScript](https://img.shields.io/badge/TypeScript-Strict-blue.svg)](https://github.com/neverinfamous/db-mcp)
14
+ [![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)
16
18
 
17
- **[Wiki](https://github.com/neverinfamous/db-mcp/wiki)** • **[Changelog](CHANGELOG.md)** • **[Security](SECURITY.md)**
19
+ **[Wiki](https://github.com/neverinfamous/db-mcp/wiki)** • **[Changelog](CHANGELOG.md)**
18
20
 
19
21
  ---
20
22
 
21
- ## 📋 Table of Contents
22
-
23
- ### Quick Start
24
-
25
- - [✅ Quick Test - Verify Everything Works](#-quick-test---verify-everything-works)
26
- - [🚀 Quick Start](#-quick-start)
27
- - [⚡ Install to Cursor IDE](#-install-to-cursor-ide)
28
- - [🎛️ Tool Filtering](#️-tool-filtering) **Important for IDE users**
29
-
30
- ### Configuration & Usage
31
-
32
- - [📊 Tool Categories](#-tool-categories)
33
- - [📚 MCP Client Configuration](#-mcp-client-configuration)
34
-
35
- ### Features & Resources
36
-
37
- - [🔥 Core Capabilities](#-core-capabilities)
38
- - [🔐 OAuth 2.1 Implementation](#-oauth-21-implementation)
39
- - [🏆 Why Choose db-mcp?](#-why-choose-db-mcp)
40
-
41
- ---
42
-
43
- ## ✅ Quick Test - Verify Everything Works
44
-
45
- **Test the server in 30 seconds!**
46
-
47
- Build and run:
48
-
49
- ```bash
50
- npm run build
51
-
52
- # Option 1: Native backend (better-sqlite3)
53
- node dist/cli.js --transport stdio --sqlite-native :memory:
54
-
55
- # Option 2: WASM backend (sql.js)
56
- node dist/cli.js --transport stdio --sqlite :memory:
57
- ```
58
-
59
- Expected output (native):
60
-
61
- ```
62
- [db-mcp] Starting MCP server...
63
- [db-mcp] Registered adapter: Native SQLite Adapter (better-sqlite3) (sqlite:default)
64
- [db-mcp] Server started successfully
65
- ```
66
-
67
- Expected output (WASM):
68
-
69
- ```
70
- [db-mcp] Starting MCP server...
71
- [db-mcp] Registered adapter: WASM SQLite Adapter (sql.js) (sqlite:default)
72
- [db-mcp] Server started successfully
73
- ```
74
-
75
- Run the test suite:
76
-
77
- ```bash
78
- npm run test
79
- ```
80
-
81
- ### 🛡️ Security Features
82
-
83
- - ✅ **SQL Injection Prevention** - Parameter binding on all queries
84
- - ✅ **OAuth 2.1 Authentication** - RFC 9728/8414 compliant
85
- - ✅ **Scope-based Authorization** - Granular read/write/admin access
86
- - ✅ **Strict TypeScript** - Full type safety with no `any` types
87
-
88
- [⬆️ Back to Table of Contents](#-table-of-contents)
89
-
90
- ---
23
+ ## 🎯 What Sets Us Apart
24
+
25
+ | Feature | Description |
26
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
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` |
29
+ | **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. |
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 |
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, 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
+ | **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, resource priorities, and progress notifications |
91
41
 
92
42
  ## 🚀 Quick Start
93
43
 
@@ -144,24 +94,26 @@ node dist/cli.js --transport stdio --sqlite-native ./database.db
144
94
  node dist/cli.js --transport stdio --sqlite ./database.db
145
95
  ```
146
96
 
147
- > **Backend Choice:** Use `--sqlite-native` for full features (122 tools, transactions, window functions, SpatiaLite). Use `--sqlite` for WASM mode (102 tools, no native dependencies).
148
-
149
- [⬆️ Back to Table of Contents](#-table-of-contents)
150
-
151
- ---
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).
152
98
 
153
- ## Install to Cursor IDE
99
+ ### Verify It Works
154
100
 
155
- ### One-Click Installation
101
+ ```bash
102
+ node dist/cli.js --transport stdio --sqlite-native :memory:
103
+ ```
156
104
 
157
- Click the button below to install directly into Cursor:
105
+ Expected output:
158
106
 
159
- [![Install to Cursor](https://img.shields.io/badge/Install%20to%20Cursor-Click%20Here-blue?style=for-the-badge)](cursor://anysphere.cursor-deeplink/mcp/install?name=db-mcp-sqlite&config=eyJkYi1tY3Atc3FsaXRlIjp7ImFyZ3MiOlsicnVuIiwiLWkiLCItLXJtIiwiLXYiLCIkKHB3ZCk6L3dvcmtzcGFjZSIsIndyaXRlbm90ZW5vdy9kYi1tY3A6bGF0ZXN0IiwiLS1zcWxpdGUtbmF0aXZlIiwiL3dvcmtzcGFjZS9kYXRhYmFzZS5kYiJdLCJjb21tYW5kIjoiZG9ja2VyIn19)
107
+ ```
108
+ [db-mcp] Starting MCP server...
109
+ [db-mcp] Registered adapter: Native SQLite Adapter (better-sqlite3) (sqlite:default)
110
+ [db-mcp] Server started successfully
111
+ ```
160
112
 
161
- Or copy this deep link:
113
+ Run the test suite:
162
114
 
163
- ```
164
- cursor://anysphere.cursor-deeplink/mcp/install?name=db-mcp-sqlite&config=eyJkYi1tY3Atc3FsaXRlIjp7ImFyZ3MiOlsicnVuIiwiLWkiLCItLXJtIiwiLXYiLCIkKHB3ZCk6L3dvcmtzcGFjZSIsIndyaXRlbm90ZW5vdy9kYi1tY3A6bGF0ZXN0IiwiLS1zcWxpdGUtbmF0aXZlIiwiL3dvcmtzcGFjZS9kYXRhYmFzZS5kYiJdLCJjb21tYW5kIjoiZG9ja2VyIn19
115
+ ```bash
116
+ npm run test
165
117
  ```
166
118
 
167
119
  ### Prerequisites
@@ -169,20 +121,16 @@ cursor://anysphere.cursor-deeplink/mcp/install?name=db-mcp-sqlite&config=eyJkYi1
169
121
  - ✅ Docker installed and running (for Docker method)
170
122
  - ✅ Node.js 24+ (LTS) (for local installation)
171
123
 
172
- [⬆️ Back to Table of Contents](#-table-of-contents)
173
-
174
- ---
175
-
176
124
  ## 🎛️ Tool Filtering
177
125
 
178
126
  > [!IMPORTANT]
179
- > **AI-enabled IDEs like Cursor have tool limits.** With 122 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.
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.
180
128
 
181
129
  ### Quick Start: Recommended Configurations
182
130
 
183
- #### Option 1: Starter (48 tools) ⭐ Recommended
131
+ #### Recommended: Code Mode (Maximum Token Savings)
184
132
 
185
- Core + JSON + Text. Best for general development.
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%.
186
134
 
187
135
  ```json
188
136
  {
@@ -196,96 +144,65 @@ Core + JSON + Text. Best for general development.
196
144
  "--sqlite-native",
197
145
  "C:/path/to/database.db",
198
146
  "--tool-filter",
199
- "starter"
147
+ "codemode"
200
148
  ]
201
149
  }
202
150
  }
203
151
  }
204
152
  ```
205
153
 
206
- #### Option 2: Analytics (50 tools)
207
-
208
- Core + JSON + Stats + Window functions. For data analysis.
209
-
210
- ```json
211
- {
212
- "args": [
213
- "--transport",
214
- "stdio",
215
- "--sqlite-native",
216
- "C:/path/to/database.db",
217
- "--tool-filter",
218
- "analytics"
219
- ]
220
- }
221
- ```
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.
222
155
 
223
- #### Option 3: Search (36 tools)
156
+ #### Starter (50 tools)
224
157
 
225
- Core + Text + FTS5 + Vector. For search workloads.
158
+ If you prefer individual tool calls, `starter` provides Core + JSON + Text:
226
159
 
227
160
  ```json
228
161
  {
229
- "args": [
230
- "--transport",
231
- "stdio",
232
- "--sqlite-native",
233
- "C:/path/to/database.db",
234
- "--tool-filter",
235
- "search"
236
- ]
162
+ "args": ["--tool-filter", "starter"]
237
163
  }
238
164
  ```
239
165
 
240
- #### Option 4: Custom Groups
166
+ #### Custom Groups
241
167
 
242
168
  Specify exactly the groups you need:
243
169
 
244
170
  ```json
245
171
  {
246
- "args": [
247
- "--transport",
248
- "stdio",
249
- "--sqlite-native",
250
- "C:/path/to/database.db",
251
- "--tool-filter",
252
- "core,json,stats"
253
- ]
172
+ "args": ["--tool-filter", "core,json,stats"]
254
173
  }
255
174
  ```
256
175
 
257
- ---
258
-
259
176
  ### Shortcuts (Predefined Bundles)
260
177
 
261
- > **Note:** Native includes transactions (7), window functions (6), and SpatiaLite (7) not available in WASM.
262
-
263
- | Shortcut | WASM | Native | + Built-in | What's Included |
264
- | ----------- | ------ | ------ | ---------- | ------------------ |
265
- | `starter` | **48** | **48** | +3 | Core, JSON, Text |
266
- | `analytics` | 44 | 50 | +3 | Core, JSON, Stats |
267
- | `search` | 36 | 36 | +3 | Core, Text, Vector |
268
- | `spatial` | 23 | 30 | +3 | Core, Geo, Vector |
269
- | `minimal` | 8 | 8 | +3 | Core only |
270
- | `full` | 102 | 122 | +3 | Everything enabled |
271
-
272
- ---
273
-
274
- ### Tool Groups (7 Available)
275
-
276
- > **Note:** +3 built-in tools (server_info, server_health, list_adapters) are always included.
277
-
278
- | Group | WASM | Native | + Built-in | Description |
279
- | -------- | ---- | ------ | ---------- | ---------------------------------------- |
280
- | `core` | 8 | 8 | +3 | Basic CRUD, schema, tables |
281
- | `json` | 23 | 23 | +3 | JSON/JSONB operations, analysis |
282
- | `text` | 13 | 17 | +3 | Text processing + FTS5 + advanced search |
283
- | `stats` | 13 | 19 | +3 | Statistical analysis (+ window funcs) |
284
- | `vector` | 11 | 11 | +3 | Embeddings, similarity search |
285
- | `admin` | 26 | 33 | +3 | Backup, restore, virtual tables, pragma |
286
- | `geo` | 4 | 11 | +3 | Geospatial + SpatiaLite (Native only) |
287
-
288
- ---
178
+ > **Note:** Native includes FTS5 (4), window functions (6), transactions (7), and SpatiaLite (7) not available in WASM.
179
+
180
+ | Shortcut | WASM | Native | + Built-in | What's Included |
181
+ | ------------ | ------ | ------ | ---------- | ------------------------------ |
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 |
189
+
190
+ ### Tool Groups (10 Available)
191
+
192
+ > **Note:** +3 built-in tools (server_info, server_health, list_adapters) and +1 code mode are always included.
193
+
194
+ | Group | WASM | Native | + Built-in | Description |
195
+ | --------------- | ---- | ------ | ---------- | -------------------------------------------- |
196
+ | `codemode` | 1 | 1 | +3 | Code Mode (sandboxed code execution) 🌟 |
197
+ | `core` | 10 | 10 | +3 | Basic CRUD, schema, tables |
198
+ | `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) |
289
206
 
290
207
  ### Syntax Reference
291
208
 
@@ -293,24 +210,35 @@ Specify exactly the groups you need:
293
210
  | -------- | -------- | --------------- | --------------------------------------------- |
294
211
  | _(none)_ | Shortcut | `starter` | **Whitelist Mode:** Enable ONLY this shortcut |
295
212
  | _(none)_ | Group | `core` | **Whitelist Mode:** Enable ONLY this group |
213
+ | _(none)_ | Tool | `read_query` | **Whitelist Mode:** Enable ONLY this tool |
296
214
  | `+` | Group | `+vector` | Add tools from this group to current set |
297
215
  | `-` | Group | `-admin` | Remove tools in this group from current set |
298
216
  | `+` | Tool | `+fuzzy_search` | Add one specific tool |
299
217
  | `-` | Tool | `-drop_table` | Remove one specific tool |
300
218
 
219
+ ### Custom Tool Selection
220
+
221
+ You can list individual tool names (without `+` prefix) to create a fully custom whitelist — only the tools you specify will be enabled:
222
+
223
+ ```bash
224
+ # Enable exactly 3 tools (whitelist mode)
225
+ --tool-filter "read_query,write_query,list_tables"
226
+
227
+ # Mix tools from different groups
228
+ --tool-filter "read_query,fuzzy_search,vector_search"
229
+
230
+ # Combine with a shortcut or group
231
+ --tool-filter "starter,+vector_search,+fuzzy_search"
232
+ ```
233
+
234
+ This is useful for scripted or automated clients that need a minimal, precise set of capabilities.
235
+
301
236
  **Examples:**
302
237
 
303
238
  ```bash
304
- # Use a shortcut
305
239
  --tool-filter "starter"
306
-
307
- # Combine groups (whitelist mode)
308
240
  --tool-filter "core,json,text,fts5"
309
-
310
- # Extend a shortcut
311
241
  --tool-filter "starter,+stats"
312
-
313
- # Exclude from a shortcut
314
242
  --tool-filter "starter,-fts5"
315
243
  ```
316
244
 
@@ -318,69 +246,10 @@ Specify exactly the groups you need:
318
246
  If you start with a negative filter (e.g., `-vector,-geo`), it assumes you want to start with _all_ tools enabled and then subtract.
319
247
 
320
248
  ```bash
321
- # Legacy: start with all, exclude some
322
249
  --tool-filter "-stats,-vector,-geo,-backup,-monitoring,-transactions,-window"
323
250
  ```
324
251
 
325
- [⬆️ Back to Table of Contents](#-table-of-contents)
326
-
327
- ---
328
-
329
- ## 📊 Tool Categories
330
-
331
- | Category | WASM | Native | Description |
332
- | --------------------- | ------- | ------- | ---------------------------------------------- |
333
- | Core Database | 8 | 8 | CRUD, schema, indexes, views |
334
- | JSON Helpers | 8 | 8 | Simplified JSON operations, schema analysis |
335
- | JSON Operations | 15 | 15 | Full JSON manipulation, JSONB support |
336
- | Text Processing | 13 | 13 | Regex, fuzzy, phonetic, advanced search |
337
- | FTS5 Full-Text Search | 4 | 4 | Create, search, rebuild, optimize |
338
- | Statistical Analysis | 13 | 19 | Stats, outliers, regression + window functions |
339
- | Virtual Tables | 13 | 13 | CSV, R-Tree, series, views, vacuum, dbstat |
340
- | Vector/Semantic | 11 | 11 | Embeddings, similarity search |
341
- | Geospatial | 4 | 11 | Distance, bounding box + SpatiaLite GIS |
342
- | Admin/PRAGMA | 13 | 20 | Backup, restore, pragmas, transactions |
343
- | **Total** | **102** | **122** | |
344
-
345
- ### SQLite Backend Options
346
-
347
- Choose between two SQLite backends based on your needs:
348
-
349
- | Feature | WASM (sql.js) | Native (better-sqlite3) |
350
- | ------------------------- | ----------------- | ----------------------------- |
351
- | **Tools Available** | 102 | **122** |
352
- | **Transactions** | ❌ | ✅ 7 tools |
353
- | **Window Functions** | ❌ | ✅ 6 tools |
354
- | **FTS5 Full-Text Search** | ⚠️ Limited | ✅ Full |
355
- | **JSON1 Extension** | ⚠️ Limited | ✅ Full |
356
- | **Cross-platform** | ✅ No compilation | Requires Node.js native build |
357
- | **In-memory DBs** | ✅ | ✅ |
358
- | **File-based DBs** | ✅ | ✅ |
359
-
360
- Transaction Tools (7) - Native Only
361
-
362
- | Tool | Description |
363
- | -------------------------------- | ----------------------------------------------------- |
364
- | `sqlite_transaction_begin` | Start transaction (deferred/immediate/exclusive mode) |
365
- | `sqlite_transaction_commit` | Commit current transaction |
366
- | `sqlite_transaction_rollback` | Rollback current transaction |
367
- | `sqlite_transaction_savepoint` | Create a savepoint |
368
- | `sqlite_transaction_release` | Release a savepoint |
369
- | `sqlite_transaction_rollback_to` | Rollback to a savepoint |
370
- | `sqlite_transaction_execute` | Execute multiple statements atomically |
371
-
372
- Window Function Tools (6) - Native Only
373
-
374
- | Tool | Description |
375
- | ----------------------------- | ----------------------------------------------------- |
376
- | `sqlite_window_row_number` | Assign sequential row numbers |
377
- | `sqlite_window_rank` | Calculate RANK/DENSE_RANK/PERCENT_RANK |
378
- | `sqlite_window_lag_lead` | Access previous or next row values |
379
- | `sqlite_window_running_total` | Calculate cumulative sums |
380
- | `sqlite_window_moving_avg` | Calculate rolling averages |
381
- | `sqlite_window_ntile` | Divide rows into N buckets (quartiles, deciles, etc.) |
382
-
383
- ### SQLite Extensions
252
+ ## SQLite Extensions
384
253
 
385
254
  SQLite supports both **built-in** extensions (compiled into better-sqlite3) and **loadable** extensions (require separate binaries).
386
255
 
@@ -435,24 +304,42 @@ db-mcp --sqlite-native ./data.db --spatialite
435
304
 
436
305
  > **Note:** Extension binaries must match your platform and architecture. The server searches common paths automatically, or use the `CSV_EXTENSION_PATH` / `SPATIALITE_PATH` environment variables for custom locations.
437
306
 
438
- ### 📁 Resources (8)
439
-
440
- MCP resources provide read-only access to database metadata:
307
+ ## 📁 Resources
441
308
 
442
- | Resource | URI | Description | Min Config |
443
- | --------------------- | ------------------------------ | --------------------------------- | ------------- |
444
- | `sqlite_schema` | `sqlite://schema` | Full database schema | `minimal` |
445
- | `sqlite_tables` | `sqlite://tables` | List all tables | `minimal` |
446
- | `sqlite_table_schema` | `sqlite://table/{name}/schema` | Schema for a specific table | `minimal` |
447
- | `sqlite_indexes` | `sqlite://indexes` | All indexes in the database | `minimal` |
448
- | `sqlite_views` | `sqlite://views` | All views in the database | `core,admin` |
449
- | `sqlite_health` | `sqlite://health` | Database health and status | _(read-only)_ |
450
- | `sqlite_meta` | `sqlite://meta` | Database metadata and PRAGMAs | `core,admin` |
451
- | `sqlite_insights` | `memo://insights` | Business insights memo (analysis) | `core,admin` |
309
+ ### Data Resources (8)
452
310
 
453
- > **Efficiency Tip:** Resources are always **readable** regardless of tool configuration. The "Min Config" column shows the smallest configuration that provides tools to **act on** what the resource exposes. Use `--tool-filter "core,admin"` (~18 tools) instead of `full` (102+) when you only need resource-related functionality.
311
+ MCP resources provide read-only access to database metadata:
454
312
 
455
- ### 💬 Prompts (10)
313
+ | Resource | URI | Description | Min Config |
314
+ | --------------------- | ----------------------------------- | --------------------------------- | ------------- |
315
+ | `sqlite_schema` | `sqlite://schema` | Full database schema | `minimal` |
316
+ | `sqlite_tables` | `sqlite://tables` | List all tables | `minimal` |
317
+ | `sqlite_table_schema` | `sqlite://table/{tableName}/schema` | Schema for a specific table | `minimal` |
318
+ | `sqlite_indexes` | `sqlite://indexes` | All indexes in the database | `minimal` |
319
+ | `sqlite_views` | `sqlite://views` | All views in the database | `core,admin` |
320
+ | `sqlite_health` | `sqlite://health` | Database health and status | _(read-only)_ |
321
+ | `sqlite_meta` | `sqlite://meta` | Database metadata and PRAGMAs | `core,admin` |
322
+ | `sqlite_insights` | `memo://insights` | Business insights memo (analysis) | `core,admin` |
323
+
324
+ ### Help Resources (1 + up to 8)
325
+
326
+ On-demand tool reference documentation, filtered by `--tool-filter`:
327
+
328
+ | Resource | URI | Description | When Registered |
329
+ | --------------------------- | ----------------------------- | ----------------------------------------------------- | --------------------------- |
330
+ | `sqlite_help` | `sqlite://help` | Gotchas, WASM vs Native, Code Mode API | Always |
331
+ | `sqlite_help_json` | `sqlite://help/json` | JSON/JSONB operations reference | When json group on |
332
+ | `sqlite_help_text` | `sqlite://help/text` | Text processing + FTS5 reference | When text group on |
333
+ | `sqlite_help_stats` | `sqlite://help/stats` | Statistical analysis + window functions reference | When stats group on |
334
+ | `sqlite_help_vector` | `sqlite://help/vector` | Vector/semantic search reference | When vector group on |
335
+ | `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 |
337
+ | `sqlite_help_introspection` | `sqlite://help/introspection` | Schema introspection, FK graph, diagnostics reference | When introspection group on |
338
+ | `sqlite_help_migration` | `sqlite://help/migration` | Migration tracking, apply, rollback reference | When migration group on |
339
+
340
+ > **Efficiency Tip:** Data resources are always **readable** regardless of tool configuration. The "Min Config" column shows the smallest configuration that provides tools to **act on** what the resource exposes. Help resources are served on-demand — agents read them only when working with a specific tool group.
341
+
342
+ ## 💬 Prompts (10)
456
343
 
457
344
  MCP prompts provide AI-assisted database workflows:
458
345
 
@@ -469,108 +356,47 @@ MCP prompts provide AI-assisted database workflows:
469
356
  | `sqlite_hybrid_search_workflow` | Hybrid FTS5 + vector search workflow |
470
357
  | `sqlite_demo` | Interactive demo of MCP capabilities |
471
358
 
472
- [⬆️ Back to Table of Contents](#-table-of-contents)
359
+ ## 🔧 Configuration
473
360
 
474
- ---
475
-
476
- ## ⚡ Performance Tuning
477
-
478
- Schema metadata is cached to reduce repeated queries during tool/resource invocations.
361
+ ### Environment Variables
479
362
 
480
- | Variable | Default | Description |
481
- | ----------------------- | ------- | -------------------------------------------------- |
482
- | `METADATA_CACHE_TTL_MS` | `5000` | Cache TTL for schema metadata (milliseconds) |
483
- | `LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warning`, `error` |
363
+ | Variable | Default | Description |
364
+ | ----------------------- | --------- | -------------------------------------------------------------- |
365
+ | `MCP_HOST` | `0.0.0.0` | Host/IP to bind to (CLI: `--server-host`) |
366
+ | `SQLITE_DATABASE` | | SQLite database path (CLI: `--sqlite` / `--sqlite-native`) |
367
+ | `DB_MCP_TOOL_FILTER` | — | Tool filter string (CLI: `--tool-filter`) |
368
+ | `MCP_AUTH_TOKEN` | — | Simple bearer token for HTTP auth (CLI: `--auth-token`) |
369
+ | `OAUTH_ENABLED` | `false` | Enable OAuth 2.1 (CLI: `--oauth-enabled`) |
370
+ | `OAUTH_ISSUER` | — | Authorization server URL (CLI: `--oauth-issuer`) |
371
+ | `OAUTH_AUDIENCE` | — | Expected token audience (CLI: `--oauth-audience`) |
372
+ | `OAUTH_JWKS_URI` | — | JWKS URI, auto-discovered if omitted (CLI: `--oauth-jwks-uri`) |
373
+ | `OAUTH_CLOCK_TOLERANCE` | `60` | Clock tolerance in seconds (CLI: `--oauth-clock-tolerance`) |
374
+ | `LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warning`, `error` |
375
+ | `METADATA_CACHE_TTL_MS` | `5000` | Schema cache TTL in ms (auto-invalidated on DDL operations) |
376
+ | `CODEMODE_ISOLATION` | `worker` | Code Mode sandbox: `worker` (enhanced isolation) or `vm` |
377
+ | `MCP_RATE_LIMIT_MAX` | `100` | Max requests/minute per IP (HTTP transport) |
378
+ | `CSV_EXTENSION_PATH` | — | Custom path to CSV extension binary (native only) |
379
+ | `SPATIALITE_PATH` | — | Custom path to SpatiaLite extension binary (native only) |
484
380
 
485
381
  > **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).
486
382
 
487
- [⬆️ Back to Table of Contents](#-table-of-contents)
488
-
489
- ---
490
-
491
- ## 📚 MCP Client Configuration
492
-
493
- ### Cursor IDE (Native Backend)
494
-
495
- ```json
496
- {
497
- "mcpServers": {
498
- "db-mcp-sqlite": {
499
- "command": "node",
500
- "args": [
501
- "C:/path/to/db-mcp/dist/cli.js",
502
- "--transport",
503
- "stdio",
504
- "--sqlite-native",
505
- "C:/path/to/your/database.db"
506
- ]
507
- }
508
- }
509
- }
510
- ```
511
-
512
- ### Cursor IDE (WASM Backend)
513
-
514
- ```json
515
- {
516
- "mcpServers": {
517
- "db-mcp-sqlite": {
518
- "command": "node",
519
- "args": [
520
- "C:/path/to/db-mcp/dist/cli.js",
521
- "--transport",
522
- "stdio",
523
- "--sqlite",
524
- "C:/path/to/your/database.db"
525
- ]
526
- }
527
- }
528
- }
529
- ```
530
-
531
- ### Claude Desktop (Native)
383
+ ### CLI Reference
532
384
 
533
- ```json
534
- {
535
- "mcpServers": {
536
- "db-mcp-sqlite": {
537
- "command": "node",
538
- "args": [
539
- "/path/to/db-mcp/dist/cli.js",
540
- "--transport",
541
- "stdio",
542
- "--sqlite-native",
543
- "/path/to/database.db"
544
- ]
545
- }
546
- }
547
- }
548
385
  ```
386
+ db-mcp [options]
549
387
 
550
- ### Claude Desktop (WASM)
551
-
552
- ```json
553
- {
554
- "mcpServers": {
555
- "db-mcp-sqlite": {
556
- "command": "node",
557
- "args": [
558
- "/path/to/db-mcp/dist/cli.js",
559
- "--transport",
560
- "stdio",
561
- "--sqlite",
562
- "/path/to/database.db"
563
- ]
564
- }
565
- }
566
- }
388
+ Transport: --transport <stdio|http|sse> --port <N> --server-host <host> --stateless
389
+ Auth: --auth-token <token> | --oauth-enabled --oauth-issuer <url> --oauth-audience <aud>
390
+ Database: --sqlite <path> | --sqlite-native <path>
391
+ Extensions: --csv --spatialite (native only)
392
+ Server: --name <name> --version <ver> --tool-filter <filter>
567
393
  ```
568
394
 
569
- ### Native with Extensions (CSV + SpatiaLite)
395
+ > CLI flags override environment variables. Run `node dist/cli.js --help` for full details.
570
396
 
571
- To enable loadable extensions, add CLI flags and set environment variables for extension paths:
397
+ ## 📚 MCP Client Configuration
572
398
 
573
- **Windows:**
399
+ Add to your `~/.cursor/mcp.json`, Claude Desktop config, or equivalent:
574
400
 
575
401
  ```json
576
402
  {
@@ -582,140 +408,97 @@ To enable loadable extensions, add CLI flags and set environment variables for e
582
408
  "--transport",
583
409
  "stdio",
584
410
  "--sqlite-native",
585
- "C:/path/to/database.db",
586
- "--csv",
587
- "--spatialite",
411
+ "C:/path/to/your/database.db",
588
412
  "--tool-filter",
589
- "starter"
590
- ],
591
- "env": {
592
- "SPATIALITE_PATH": "C:/path/to/extensions/mod_spatialite.dll"
593
- }
594
- }
595
- }
596
- }
597
- ```
598
-
599
- **Linux/macOS:**
600
-
601
- ```json
602
- {
603
- "mcpServers": {
604
- "db-mcp-sqlite": {
605
- "command": "node",
606
- "args": [
607
- "/path/to/db-mcp/dist/cli.js",
608
- "--transport",
609
- "stdio",
610
- "--sqlite-native",
611
- "/path/to/database.db",
612
- "--csv",
613
- "--spatialite",
614
- "--tool-filter",
615
- "starter"
616
- ],
617
- "env": {
618
- "CSV_EXTENSION_PATH": "/path/to/extensions/csv.so",
619
- "SPATIALITE_PATH": "/usr/lib/x86_64-linux-gnu/mod_spatialite.so"
620
- }
621
- }
622
- }
623
- }
624
- ```
625
-
626
- > **Note:** Extension flags (`--csv`, `--spatialite`) are only available with the native backend (`--sqlite-native`). Set environment variables if extensions are not in standard system paths.
627
-
628
- ### Docker with Claude Desktop
629
-
630
- ```json
631
- {
632
- "mcpServers": {
633
- "db-mcp-sqlite": {
634
- "command": "docker",
635
- "args": [
636
- "run",
637
- "-i",
638
- "--rm",
639
- "-v",
640
- "/path/to/project:/workspace",
641
- "writenotenow/db-mcp:latest",
642
- "--sqlite-native",
643
- "/workspace/database.db"
413
+ "codemode"
644
414
  ]
645
415
  }
646
416
  }
647
417
  }
648
418
  ```
649
419
 
650
- ### In-Memory Database
420
+ **Variants** (modify the `args` array above):
651
421
 
652
- Use `:memory:` for a temporary in-memory database:
422
+ | Variant | Change |
423
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
424
+ | **WASM backend** | Replace `--sqlite-native` with `--sqlite` |
425
+ | **In-memory database** | Replace the database path with `:memory:` |
426
+ | **Starter preset** | Replace `"codemode"` with `"starter"` for individual tool calls |
427
+ | **CSV extension** | Add `"--csv"` before `"--tool-filter"` (native only) |
428
+ | **SpatiaLite** | Add `"--spatialite"` and set `env: { "SPATIALITE_PATH": "/path/to/mod_spatialite" }` (native only) |
429
+ | **Linux/macOS** | Use forward-slash Unix paths (e.g., `/path/to/db-mcp/dist/cli.js`) |
430
+ | **Docker** | Replace `"command": "node"` with `"command": "docker"` and wrap args in `run -i --rm -v ./data:/app/data writenotenow/db-mcp:latest` |
653
431
 
654
- ```json
655
- {
656
- "args": ["--transport", "stdio", "--sqlite-native", ":memory:"]
657
- }
658
- ```
432
+ > See [Tool Filtering](#️-tool-filtering) to customize which tools are exposed.
659
433
 
660
434
  ### HTTP/SSE Transport (Remote Access)
661
435
 
662
436
  For remote access, web-based clients, or MCP Inspector testing, run the server in HTTP mode:
663
437
 
664
438
  ```bash
665
- node dist/cli.js --transport http --port 3000 --sqlite-native ./database.db
439
+ node dist/cli.js --transport http --port 3000 --server-host 0.0.0.0 --sqlite-native ./database.db
666
440
  ```
667
441
 
668
442
  **Endpoints:**
669
443
 
670
- | Endpoint | Description |
671
- | ------------- | --------------------------------------------- |
672
- | `GET /` | Server info and available endpoints |
673
- | `POST /mcp` | JSON-RPC requests (initialize, tools/call) |
674
- | `GET /mcp` | SSE stream for server-to-client notifications |
675
- | `DELETE /mcp` | Session termination |
676
- | `GET /health` | Health check (always public) |
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 |
677
453
 
678
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.
679
455
 
456
+ **Security Features:**
457
+
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
466
+
680
467
  #### Stateless Mode (Serverless)
681
468
 
682
469
  For serverless deployments (AWS Lambda, Cloudflare Workers, Vercel), use stateless mode:
683
470
 
684
471
  ```bash
685
- node dist/cli.js --transport http --port 3000 --stateless --sqlite-native :memory:
472
+ node dist/cli.js --transport http --port 3000 --server-host 0.0.0.0 --stateless --sqlite-native :memory:
686
473
  ```
687
474
 
688
- | Mode | Progress Notifications | SSE Streaming | Serverless |
689
- | ------------------------- | ---------------------- | ------------- | ---------- |
690
- | Stateful (default) | ✅ Yes | ✅ Yes | ⚠️ Complex |
691
- | Stateless (`--stateless`) | ❌ No | ❌ No | ✅ Native |
475
+ | Mode | Progress Notifications | Legacy SSE | Serverless |
476
+ | ------------------------- | ---------------------- | ---------- | ---------- |
477
+ | Stateful (default) | ✅ Yes | ✅ Yes | ⚠️ Complex |
478
+ | Stateless (`--stateless`) | ❌ No | ❌ No | ✅ Native |
692
479
 
693
- [⬆️ Back to Table of Contents](#-table-of-contents)
480
+ ## 🔐 Authentication
694
481
 
695
- ---
482
+ db-mcp supports two authentication mechanisms for HTTP transport:
696
483
 
697
- ## 🔥 Core Capabilities
484
+ ### Simple Bearer Token (`--auth-token`)
698
485
 
699
- - 📊 **Statistical Analysis** - Descriptive stats, percentiles, time series analysis
700
- - 🔍 **Advanced Text Processing** - Regex, fuzzy matching, phonetic search, similarity
701
- - 🧠 **Vector/Semantic Search** - AI-native embeddings, cosine similarity, hybrid search
702
- - 🗺️ **Geospatial Operations** - Distance calculations, bounding boxes, spatial queries
703
- - 🔐 **Transaction Safety** - Full ACID compliance with savepoints (native backend)
704
- - 🎛️ **122 Specialized Tools** - Complete database administration and analytics suite
486
+ Lightweight authentication for development or single-tenant deployments:
705
487
 
706
- ### 🏢 Enterprise Features
488
+ ```bash
489
+ # CLI
490
+ node dist/cli.js --transport http --port 3000 --auth-token my-secret --sqlite-native ./database.db
707
491
 
708
- - 🔐 **OAuth 2.1 Authentication** - RFC 9728/8414 compliant token-based authentication
709
- - 🛡️ **Tool Filtering** - Control which database operations are exposed
710
- - 👥 **Access Control** - Granular scopes for read-only, write, and admin access
711
- - 🎯 **Full-Text Search (FTS5)** - Advanced search with BM25 ranking
712
- - ⚡ **Window Functions** - Row numbers, rankings, running totals, moving averages
492
+ # Environment variable
493
+ export MCP_AUTH_TOKEN=my-secret
494
+ node dist/cli.js --transport http --port 3000 --sqlite-native ./database.db
495
+ ```
713
496
 
714
- [⬆️ Back to Table of Contents](#-table-of-contents)
497
+ Clients must include `Authorization: Bearer my-secret` on all requests. `/health` and `/` are exempt. Unauthenticated requests receive `401` with `WWW-Authenticate: Bearer` headers per RFC 6750.
715
498
 
716
- ---
499
+ ### OAuth 2.1 (Enterprise)
717
500
 
718
- ## 🔐 OAuth 2.1 Implementation
501
+ Full OAuth 2.1 with RFC 9728/8414 compliance for production multi-tenant deployments:
719
502
 
720
503
  | Component | Status | Description |
721
504
  | --------------------------- | ------ | ------------------------------------------------ |
@@ -725,7 +508,7 @@ node dist/cli.js --transport http --port 3000 --stateless --sqlite-native :memor
725
508
  | Scope Enforcement | ✅ | Granular `read`, `write`, `admin` scopes |
726
509
  | HTTP Transport | ✅ | Streamable HTTP with OAuth middleware |
727
510
 
728
- ### Supported Scopes
511
+ #### Supported Scopes
729
512
 
730
513
  | Scope | Description |
731
514
  | -------------------- | -------------------------------------- |
@@ -735,108 +518,51 @@ node dist/cli.js --transport http --port 3000 --stateless --sqlite-native :memor
735
518
  | `db:{name}` | Access to specific database only |
736
519
  | `table:{db}:{table}` | Access to specific table only |
737
520
 
738
- ### Keycloak Integration
739
-
740
- See [docs/KEYCLOAK_SETUP.md](docs/KEYCLOAK_SETUP.md) for setting up Keycloak as your OAuth provider.
741
-
742
- ### Quick Start with OAuth
743
-
744
- **1. Start the server with OAuth enabled:**
521
+ #### Quick Start with OAuth CLI Flags
745
522
 
746
523
  ```bash
747
- # Set environment variables
748
- export KEYCLOAK_URL=http://localhost:8080
749
- export KEYCLOAK_REALM=db-mcp
750
- export KEYCLOAK_CLIENT_ID=db-mcp-server
751
-
752
- # Start server with HTTP transport and OAuth
753
- node dist/cli.js --transport http --port 3000 --sqlite-native ./database.db
754
- ```
755
-
756
- **2. Get an access token from Keycloak:**
757
-
758
- ```bash
759
- # Using cURL
760
- curl -X POST "http://localhost:8080/realms/db-mcp/protocol/openid-connect/token" \
761
- -H "Content-Type: application/x-www-form-urlencoded" \
762
- -d "client_id=db-mcp-server" \
763
- -d "client_secret=YOUR_SECRET" \
764
- -d "username=testuser" \
765
- -d "password=YOUR_PASSWORD" \
766
- -d "grant_type=password" \
767
- -d "scope=openid read write"
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
768
529
  ```
769
530
 
770
- **3. Make authenticated MCP requests:**
771
-
772
- ```bash
773
- # Initialize session with Bearer token
774
- curl -X POST "http://localhost:3000/mcp" \
775
- -H "Content-Type: application/json" \
776
- -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
777
- -d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{}},"id":1}'
778
- ```
779
-
780
- > **Note:** OAuth is automatically enabled when running in HTTP mode with OAuth environment variables configured. The `/.well-known/oauth-protected-resource` endpoint provides RFC 9728 metadata for client discovery.
781
-
782
- [⬆️ Back to Table of Contents](#-table-of-contents)
783
-
784
- ---
785
-
786
- ## 🏆 Why Choose db-mcp?
787
-
788
- ✅ **TypeScript Native** - Full type safety with strict mode, no `any` types
789
- ✅ **122 Specialized Tools** - Most comprehensive SQLite MCP server available
790
- ✅ **OAuth 2.1 Built-in** - Enterprise-grade authentication out of the box
791
- ✅ **Dual Backends** - WASM for portability, native for performance
792
- ✅ **Tool Filtering** - Stay within AI IDE tool limits with preset configurations
793
- ✅ **Window Functions** - Advanced analytics with ROW_NUMBER, RANK, LAG/LEAD
794
- ✅ **Transaction Support** - Full ACID compliance with savepoints
795
- ✅ **Modern Architecture** - Built on MCP SDK with clean, modular design
796
- ✅ **Active Development** - Regular updates and improvements
531
+ > **Additional flags:** `--oauth-jwks-uri <url>` (auto-discovered if omitted), `--oauth-clock-tolerance <seconds>` (default: 60).
797
532
 
798
- [⬆️ Back to Table of Contents](#-table-of-contents)
533
+ #### Keycloak Integration
799
534
 
800
- ---
801
-
802
- ## 📈 Project Stats
803
-
804
- - **122 Tools** in native backend (102 in WASM)
805
- - **13 Tool Groups** for flexible filtering
806
- - **Strict TypeScript** with full type coverage
807
- - **Multi-platform** support (Windows, Linux, macOS)
808
- - **Docker images** available for easy deployment
809
- - **OAuth 2.1** RFC-compliant authentication
810
- - **Active development** with regular updates
811
-
812
- [⬆️ Back to Table of Contents](#-table-of-contents)
535
+ See [docs/KEYCLOAK_SETUP.md](docs/KEYCLOAK_SETUP.md) for setting up Keycloak as your OAuth provider.
813
536
 
814
- ---
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.
815
538
 
816
- ## Configuration
539
+ ## 📊 Benchmarks
817
540
 
818
- ### Environment Variables
541
+ 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:
819
542
 
820
- Copy `.env.example` to `.env` and configure:
543
+ - **Tool dispatch:** ~11M ops/sec — Map-based lookup is effectively zero-cost
544
+ - **Auth scope checks:** 7–9M 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
821
549
 
822
550
  ```bash
823
- KEYCLOAK_URL=http://localhost:8080
824
- KEYCLOAK_REALM=db-mcp
825
- KEYCLOAK_CLIENT_ID=db-mcp-server
826
- KEYCLOAK_CLIENT_SECRET=your_secret_here
827
- DBMCP_PORT=3000
828
- DBMCP_OAUTH_ENABLED=true
829
- ```
830
-
831
- ### JSON Configuration
832
-
833
- See `config/db-mcp.keycloak.json` for a complete example.
834
-
835
- ---
836
-
837
- ## 🚧 Planned Improvements
838
-
839
- _No pending improvements. All features are up-to-date._
551
+ npm run bench # Run all benchmarks
552
+ npm run bench:verbose # Verbose mode with detailed timings
553
+ ```
554
+
555
+ | Benchmark | What It Measures |
556
+ | --------------------- | ----------------------------------------------------------------------- |
557
+ | Handler Dispatch | Tool lookup, error construction, progress notification overhead |
558
+ | Utilities | Identifier sanitization, WHERE clause validation, SQL validation |
559
+ | Tool Filtering | Filter parsing, group lookups, meta-group catalog generation |
560
+ | Schema Parsing | Zod schema validation for simple/complex/large payloads + failure paths |
561
+ | Logger & Sanitization | Log call overhead, message sanitization, sensitive data redaction |
562
+ | Transport & Auth | Token extraction, scope checking, error formatting, rate limiting |
563
+ | Code Mode | Sandbox creation, pool lifecycle, security validation, execution |
564
+ | Database Operations | PRAGMA ops, table metadata, query result processing, schema caching |
565
+ | Resource & Prompts | URI matching, content assembly, prompt generation, tool indexing |
840
566
 
841
567
  ---
842
568