db-mcp 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.gitleaks.toml +9 -0
  2. package/.trivyignore +8 -0
  3. package/README.md +193 -120
  4. package/dist/{chunk-TVIZ3XJH.js → chunk-5Y42NPBP.js} +4168 -2411
  5. package/dist/{chunk-AOUL5SHS.js → chunk-645ZEFLA.js} +70 -20
  6. package/dist/chunk-OKOVZ5QE.js +28 -0
  7. package/dist/chunk-SFJQCNG7.js +131 -0
  8. package/dist/{chunk-FW7UCRLN.js → chunk-VIDSICEL.js} +3 -0
  9. package/dist/chunk-WBER5YY4.js +2053 -0
  10. package/dist/{chunk-4IA3DB5C.js → chunk-X3MUUOWM.js} +19 -2
  11. package/dist/{chunk-Z2GFQU3G.js → chunk-Z7C2TM4L.js} +114 -21
  12. package/dist/cli.js +79 -5
  13. package/dist/{http-VSB7DBJR.js → http-6KF4ULDI.js} +199 -77
  14. package/dist/index.d.ts +231 -8
  15. package/dist/index.js +6 -5
  16. package/dist/{sqlite-26V3Y4MK.js → sqlite-U5KSYQXK.js} +62 -138
  17. package/dist/{sqlite-native-5O7FZJGB.js → sqlite-native-JXMCFQBA.js} +575 -113
  18. package/dist/worker-script.js +34 -10
  19. package/logs/.gitkeep +1 -0
  20. package/mcp-config-example.json +83 -0
  21. package/package.json +9 -8
  22. package/playwright.config.ts +1 -1
  23. package/scripts/update-badges.ts +99 -0
  24. package/server.json +7 -5
  25. package/test-server/README.md +20 -23
  26. package/test-server/code-map.md +45 -33
  27. package/test-server/reset-database.ps1 +59 -17
  28. package/test-server/scripts/README.md +27 -0
  29. package/test-server/{test-help-resources.mjs → scripts/test-help-resources.mjs} +12 -5
  30. package/test-server/scripts/test-prompts.mjs +251 -0
  31. package/test-server/{test-tool-annotations.mjs → scripts/test-tool-annotations.mjs} +9 -4
  32. package/test-server/test-advanced/README.md +70 -0
  33. package/test-server/test-advanced/test-codemode-advanced-admin.md +174 -0
  34. package/test-server/test-advanced/test-codemode-advanced-core.md +193 -0
  35. package/test-server/test-advanced/test-codemode-advanced-geo.md +157 -0
  36. package/test-server/test-advanced/test-codemode-advanced-introspection.md +171 -0
  37. package/test-server/test-advanced/test-codemode-advanced-json.md +169 -0
  38. package/test-server/test-advanced/test-codemode-advanced-migration.md +160 -0
  39. package/test-server/test-advanced/test-codemode-advanced-stats.md +185 -0
  40. package/test-server/test-advanced/test-codemode-advanced-text.md +183 -0
  41. package/test-server/test-advanced/test-codemode-advanced-transactions.md +136 -0
  42. package/test-server/test-advanced/test-codemode-advanced-vector.md +141 -0
  43. package/test-server/test-codemode/README.md +121 -0
  44. package/test-server/test-codemode/test-codemode-admin.md +223 -0
  45. package/test-server/test-codemode/test-codemode-core.md +286 -0
  46. package/test-server/test-codemode/test-codemode-geo.md +177 -0
  47. package/test-server/test-codemode/test-codemode-introspection.md +190 -0
  48. package/test-server/test-codemode/test-codemode-json.md +237 -0
  49. package/test-server/test-codemode/test-codemode-migration.md +278 -0
  50. package/test-server/test-codemode/test-codemode-sandbox.md +413 -0
  51. package/test-server/test-codemode/test-codemode-stats.md +232 -0
  52. package/test-server/test-codemode/test-codemode-text.md +237 -0
  53. package/test-server/test-codemode/test-codemode-transactions.md +236 -0
  54. package/test-server/test-codemode/test-codemode-vector.md +244 -0
  55. package/test-server/test-codemode/test-codemode-wasm-degradation.md +394 -0
  56. package/test-server/test-database.sql +37 -1
  57. package/test-server/test-resources.md +43 -16
  58. package/test-server/test-tool-groups/README.md +100 -0
  59. package/test-server/test-tool-groups/test-admin-core.md +165 -0
  60. package/test-server/test-tool-groups/test-admin-extensions.md +133 -0
  61. package/test-server/{test-tools.md → test-tool-groups/test-core-data.md} +103 -17
  62. package/test-server/test-tool-groups/test-core-schema.md +240 -0
  63. package/test-server/test-tool-groups/test-geo-haversine.md +130 -0
  64. package/test-server/test-tool-groups/test-geo-spatialite.md +110 -0
  65. package/test-server/test-tool-groups/test-introspection-diagnostics.md +123 -0
  66. package/test-server/test-tool-groups/test-introspection-schema.md +133 -0
  67. package/test-server/test-tool-groups/test-json-read.md +219 -0
  68. package/test-server/test-tool-groups/test-json-write.md +157 -0
  69. package/test-server/test-tool-groups/test-migration.md +193 -0
  70. package/test-server/test-tool-groups/test-stats-advanced.md +118 -0
  71. package/test-server/test-tool-groups/test-stats-basic.md +156 -0
  72. package/test-server/test-tool-groups/test-text-advanced.md +169 -0
  73. package/test-server/test-tool-groups/test-text-basic.md +177 -0
  74. package/test-server/test-tool-groups/test-transactions.md +179 -0
  75. package/test-server/test-tool-groups/test-vector-read.md +130 -0
  76. package/test-server/test-tool-groups/test-vector-write.md +115 -0
  77. package/test-server/tool-reference.md +79 -58
  78. package/tsconfig.build.json +6 -0
  79. package/dist/chunk-RHVEZ42P.js +0 -873
  80. package/test-server/test-agent-experience.md +0 -243
  81. package/test-server/test-group-tools.md +0 -861
  82. package/test-server/test-tools-advanced-1.md +0 -517
  83. package/test-server/test-tools-advanced-2.md +0 -487
  84. package/test-server/test-tools-codemode.md +0 -629
@@ -6,6 +6,7 @@ var ALL_TOOL_GROUPS = [
6
6
  "stats",
7
7
  "vector",
8
8
  "admin",
9
+ "transactions",
9
10
  "geo",
10
11
  "introspection",
11
12
  "migration",
@@ -21,7 +22,12 @@ var TOOL_GROUPS = {
21
22
  "drop_table",
22
23
  "get_indexes",
23
24
  "create_index",
24
- "drop_index"
25
+ "drop_index",
26
+ "upsert",
27
+ "batch_insert",
28
+ "count",
29
+ "exists",
30
+ "truncate"
25
31
  ],
26
32
  json: [
27
33
  // CRUD + Query + Collection (8: crud.ts, query.ts, write.ts)
@@ -49,10 +55,12 @@ var TOOL_GROUPS = {
49
55
  // JSONB + Storage (3: write.ts, read.ts)
50
56
  "jsonb_convert",
51
57
  "json_storage_info",
52
- "json_normalize_column"
58
+ "json_normalize_column",
59
+ // Security (1: security.ts)
60
+ "json_security_scan"
53
61
  ],
54
62
  text: [
55
- // Text Tools (13 WASM)
63
+ // Text Tools (14 WASM)
56
64
  "regex_extract",
57
65
  "regex_match",
58
66
  "text_split",
@@ -66,14 +74,16 @@ var TOOL_GROUPS = {
66
74
  "text_normalize",
67
75
  "text_validate",
68
76
  "advanced_search",
69
- // FTS5 Tools (4 Native-only)
77
+ "text_sentiment",
78
+ // FTS5 Tools (5 Native-only)
70
79
  "fts_create",
71
80
  "fts_search",
72
81
  "fts_rebuild",
73
- "fts_match_info"
82
+ "fts_match_info",
83
+ "fts_headline"
74
84
  ],
75
85
  stats: [
76
- // Stats Tools (13 WASM)
86
+ // Stats Tools (16 WASM)
77
87
  "stats_basic",
78
88
  "stats_count",
79
89
  "stats_group_by",
@@ -87,6 +97,10 @@ var TOOL_GROUPS = {
87
97
  "stats_outliers",
88
98
  "stats_regression",
89
99
  "stats_hypothesis",
100
+ // Anomaly Detection (3 WASM)
101
+ "stats_detect_anomalies",
102
+ "stats_detect_bloat",
103
+ "stats_detect_schema_risks",
90
104
  // Window Tools (6 Native-only)
91
105
  "window_row_number",
92
106
  "window_rank",
@@ -136,9 +150,12 @@ var TOOL_GROUPS = {
136
150
  "create_csv_table",
137
151
  "analyze_csv_schema",
138
152
  "create_rtree_table",
139
- "create_series_table",
140
- // Transaction Tools (7 Native-only)
153
+ "create_series_table"
154
+ ],
155
+ transactions: [
156
+ // Transaction Tools (8 Native-only)
141
157
  "transaction_begin",
158
+ "transaction_status",
142
159
  "transaction_commit",
143
160
  "transaction_rollback",
144
161
  "transaction_savepoint",
@@ -185,19 +202,19 @@ var TOOL_GROUPS = {
185
202
  codemode: ["execute_code"]
186
203
  };
187
204
  var META_GROUPS = {
188
- // General development - Core + JSON + Text + Codemode (46 WASM / 50 Native)
205
+ // General development - Core + JSON + Text + Codemode (53 WASM / 58 Native)
189
206
  starter: ["core", "json", "text", "codemode"],
190
- // Data analysis - Core + JSON + Stats + Codemode (46 WASM / 52 Native)
207
+ // Data analysis - Core + JSON + Stats + Codemode (55 WASM / 61 Native)
191
208
  analytics: ["core", "json", "stats", "codemode"],
192
- // Search workloads - Core + Text + Vector + Codemode (34 WASM / 38 Native)
209
+ // Search workloads - Core + Text + Vector + Codemode (40 WASM / 45 Native)
193
210
  search: ["core", "text", "vector", "codemode"],
194
- // Geospatial workloads - Core + Geo + Vector + Codemode (25 WASM / 32 Native)
211
+ // Geospatial workloads - Core + Geo + Vector + Codemode (30 WASM / 37 Native)
195
212
  spatial: ["core", "geo", "vector", "codemode"],
196
- // Schema development - Core + Introspection + Migration + Codemode (25 tools)
213
+ // Schema development - Core + Introspection + Migration + Codemode (30 tools)
197
214
  "dev-schema": ["core", "introspection", "migration", "codemode"],
198
- // Bare minimum - Core + Codemode (10 tools)
215
+ // Bare minimum - Core + Codemode (15 tools)
199
216
  minimal: ["core", "codemode"],
200
- // All tools enabled (115 WASM / 139 Native)
217
+ // All tools enabled (125 WASM / 151 Native)
201
218
  full: [
202
219
  "core",
203
220
  "json",
@@ -205,6 +222,7 @@ var META_GROUPS = {
205
222
  "stats",
206
223
  "vector",
207
224
  "admin",
225
+ "transactions",
208
226
  "geo",
209
227
  "introspection",
210
228
  "migration",
@@ -446,7 +464,14 @@ var ERROR_SUGGESTIONS = [
446
464
  {
447
465
  pattern: /table .* already exists/i,
448
466
  suggestion: "Table already exists. Use CREATE TABLE IF NOT EXISTS or drop the existing table first.",
449
- category: "resource" /* RESOURCE */
467
+ category: "resource" /* RESOURCE */,
468
+ code: "TABLE_ALREADY_EXISTS"
469
+ },
470
+ {
471
+ pattern: /index .* already exists/i,
472
+ suggestion: "Index already exists. Use CREATE INDEX IF NOT EXISTS or drop the existing index first.",
473
+ category: "resource" /* RESOURCE */,
474
+ code: "INDEX_ALREADY_EXISTS"
450
475
  },
451
476
  // JSON-specific errors — often caused by wrong column name
452
477
  {
@@ -464,22 +489,26 @@ var ERROR_SUGGESTIONS = [
464
489
  {
465
490
  pattern: /UNIQUE constraint failed/i,
466
491
  suggestion: "A row with this value already exists. Use UPDATE to modify existing data or check for duplicates.",
467
- category: "query" /* QUERY */
492
+ category: "query" /* QUERY */,
493
+ code: "CONSTRAINT_VIOLATION"
468
494
  },
469
495
  {
470
496
  pattern: /FOREIGN KEY constraint failed/i,
471
497
  suggestion: "The referenced row does not exist. Ensure the parent record exists before inserting.",
472
- category: "query" /* QUERY */
498
+ category: "query" /* QUERY */,
499
+ code: "CONSTRAINT_VIOLATION"
473
500
  },
474
501
  {
475
502
  pattern: /NOT NULL constraint failed/i,
476
503
  suggestion: "A required column is missing a value. Provide a value or set a default.",
477
- category: "query" /* QUERY */
504
+ category: "query" /* QUERY */,
505
+ code: "CONSTRAINT_VIOLATION"
478
506
  },
479
507
  {
480
508
  pattern: /CHECK constraint failed/i,
481
509
  suggestion: "The value does not meet the column's check constraint requirements.",
482
- category: "query" /* QUERY */
510
+ category: "query" /* QUERY */,
511
+ code: "CONSTRAINT_VIOLATION"
483
512
  },
484
513
  {
485
514
  pattern: /incomplete input/i,
@@ -508,6 +537,18 @@ var ERROR_SUGGESTIONS = [
508
537
  category: "query" /* QUERY */,
509
538
  code: "TRANSACTION_CONFLICT"
510
539
  },
540
+ {
541
+ pattern: /no transaction is active/i,
542
+ suggestion: "No transaction is active. Start a transaction using sqlite_transaction_begin first.",
543
+ category: "query" /* QUERY */,
544
+ code: "TRANSACTION_NOT_ACTIVE"
545
+ },
546
+ {
547
+ pattern: /no such savepoint/i,
548
+ suggestion: "The specified savepoint does not exist. Verify the savepoint name and ensure it hasn't already been released or rolled back.",
549
+ category: "query" /* QUERY */,
550
+ code: "SAVEPOINT_NOT_FOUND"
551
+ },
511
552
  {
512
553
  pattern: /database is locked/i,
513
554
  suggestion: "Database is being used by another process. Wait and retry, or check for long-running transactions.",
@@ -544,6 +585,13 @@ var ERROR_SUGGESTIONS = [
544
585
  pattern: /sandbox.*not initialized/i,
545
586
  suggestion: "Internal sandbox error. Retry the operation.",
546
587
  category: "internal" /* INTERNAL */
588
+ },
589
+ // Extension errors
590
+ {
591
+ pattern: /extension.*not (available|installed|loaded|found)/i,
592
+ suggestion: "Extension is not available. Check CLI flags, environment variables, or platform compatibility.",
593
+ category: "config" /* CONFIGURATION */,
594
+ code: "EXTENSION_MISSING"
547
595
  }
548
596
  ];
549
597
  function findSuggestion(message) {
@@ -646,6 +694,8 @@ var ModuleLogger = class {
646
694
  this.parent = parent;
647
695
  this.module = module;
648
696
  }
697
+ parent;
698
+ module;
649
699
  withModule(context) {
650
700
  return { ...context, module: this.module };
651
701
  }
@@ -0,0 +1,28 @@
1
+ // src/codemode/auto-return.ts
2
+ var NON_RETURNABLE = /^\s*(return|throw|const |let |var |if\b|else\b|for\b|while\b|do\b|switch\b|try\b|catch\b|finally\b|class |function |\/\/|\/\*|\{|\})/;
3
+ function transformAutoReturn(code) {
4
+ const trimmed = code.trimEnd();
5
+ if (!trimmed) return code;
6
+ let depth = 0;
7
+ let splitIndex = -1;
8
+ for (let i = trimmed.length - 1; i >= 0; i--) {
9
+ const ch = trimmed.charAt(i);
10
+ if (ch === "}" || ch === "]" || ch === ")") depth++;
11
+ else if (ch === "{" || ch === "[" || ch === "(") depth--;
12
+ if (depth === 0 && (ch === ";" || ch === "\n")) {
13
+ splitIndex = i;
14
+ break;
15
+ }
16
+ }
17
+ const lastStmt = (splitIndex >= 0 ? trimmed.slice(splitIndex + 1) : trimmed).trim();
18
+ if (!lastStmt) return code;
19
+ if (NON_RETURNABLE.test(lastStmt)) return code;
20
+ if (splitIndex >= 0) {
21
+ const before = trimmed.slice(0, splitIndex + 1);
22
+ return `${before}
23
+ return ${lastStmt}`;
24
+ }
25
+ return `return ${trimmed}`;
26
+ }
27
+
28
+ export { transformAutoReturn };
@@ -0,0 +1,131 @@
1
+ import { AsyncLocalStorage } from 'async_hooks';
2
+
3
+ // src/auth/auth-context.ts
4
+ var authContextStorage = new AsyncLocalStorage();
5
+ function runWithAuthContext(context, fn) {
6
+ return authContextStorage.run(context, fn);
7
+ }
8
+ function getAuthContext() {
9
+ return authContextStorage.getStore();
10
+ }
11
+
12
+ // src/auth/scopes/constants.ts
13
+ var SCOPES = {
14
+ /** Read-only access to all databases */
15
+ READ: "read",
16
+ /** Read and write access to all databases */
17
+ WRITE: "write",
18
+ /** Administrative access */
19
+ ADMIN: "admin",
20
+ /** Unrestricted access to all operations */
21
+ FULL: "full"
22
+ };
23
+ var BASE_SCOPES = ["read", "write", "admin", "full"];
24
+ var SCOPE_PATTERNS = {
25
+ /** Read-only access */
26
+ READ: "read",
27
+ /** Read and write access */
28
+ WRITE: "write",
29
+ /** Administrative access */
30
+ ADMIN: "admin",
31
+ /** Unrestricted access */
32
+ FULL: "full",
33
+ /** Database-specific access pattern */
34
+ DATABASE: /^db:([a-zA-Z0-9_-]+)$/,
35
+ /** Table-specific access pattern */
36
+ TABLE: /^table:([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)$/
37
+ };
38
+ var SUPPORTED_SCOPES = [
39
+ "read",
40
+ "write",
41
+ "admin",
42
+ "full",
43
+ "db:{database}",
44
+ "table:{database}:{table}"
45
+ ];
46
+ function parseScopes(scopeString) {
47
+ return scopeString.split(/\s+/).map((s) => s.trim()).filter((s) => s.length > 0);
48
+ }
49
+
50
+ // src/auth/scopes/mapping.ts
51
+ var TOOL_GROUP_SCOPES = {
52
+ core: SCOPES.READ,
53
+ json: SCOPES.READ,
54
+ text: SCOPES.READ,
55
+ stats: SCOPES.READ,
56
+ vector: SCOPES.READ,
57
+ geo: SCOPES.READ,
58
+ introspection: SCOPES.READ,
59
+ migration: SCOPES.WRITE,
60
+ transactions: SCOPES.WRITE,
61
+ admin: SCOPES.ADMIN,
62
+ codemode: SCOPES.ADMIN
63
+ };
64
+ var groupsForScope = (maxScope) => {
65
+ const hierarchy = {
66
+ read: 0,
67
+ write: 1,
68
+ admin: 2,
69
+ full: 3
70
+ };
71
+ const maxLevel = hierarchy[maxScope];
72
+ return Object.entries(TOOL_GROUP_SCOPES).filter(([, scope]) => hierarchy[scope] <= maxLevel).map(([group]) => group);
73
+ };
74
+ groupsForScope(SCOPES.READ);
75
+ groupsForScope(SCOPES.WRITE);
76
+ groupsForScope(SCOPES.ADMIN);
77
+ var READ_ONLY_TOOLS = /* @__PURE__ */ new Set([
78
+ "execute_query",
79
+ // If used with SELECT only
80
+ "read_query",
81
+ "list_tables",
82
+ "describe_table",
83
+ "list_schemas",
84
+ "get_schema",
85
+ "health_check",
86
+ "connection_status",
87
+ "database_stats",
88
+ "active_queries",
89
+ "resource_usage",
90
+ "analyze_query",
91
+ "explain_query",
92
+ "query_plan"
93
+ ]);
94
+ var ADMIN_TOOLS = /* @__PURE__ */ new Set([
95
+ "vacuum_database",
96
+ "analyze_tables",
97
+ "pragma_get",
98
+ "pragma_set",
99
+ "extension_list",
100
+ "extension_install",
101
+ "optimize",
102
+ "backup_database",
103
+ "restore_database",
104
+ "backup_table",
105
+ "export_data"
106
+ ]);
107
+
108
+ // src/auth/scopes/enforcement.ts
109
+ function scopeGrantsToolAccess(scope, toolName) {
110
+ if (scope === "full") {
111
+ return true;
112
+ }
113
+ if (scope === "admin") {
114
+ return true;
115
+ }
116
+ if (scope === "write") {
117
+ if (ADMIN_TOOLS.has(toolName)) {
118
+ return false;
119
+ }
120
+ return true;
121
+ }
122
+ if (scope === "read") {
123
+ return READ_ONLY_TOOLS.has(toolName);
124
+ }
125
+ return false;
126
+ }
127
+ function scopesGrantToolAccess(scopes, toolName) {
128
+ return scopes.some((scope) => scopeGrantsToolAccess(scope, toolName));
129
+ }
130
+
131
+ export { BASE_SCOPES, SCOPES, SCOPE_PATTERNS, SUPPORTED_SCOPES, TOOL_GROUP_SCOPES, getAuthContext, parseScopes, runWithAuthContext, scopesGrantToolAccess };
@@ -23,6 +23,9 @@ var TOOL_GROUP_ICONS = {
23
23
  { src: `${MDI_BASE}/vector-polyline.svg`, mimeType: "image/svg+xml" }
24
24
  ],
25
25
  admin: [{ src: `${MDI_BASE}/cog.svg`, mimeType: "image/svg+xml" }],
26
+ transactions: [
27
+ { src: `${MDI_BASE}/swap-horizontal.svg`, mimeType: "image/svg+xml" }
28
+ ],
26
29
  geo: [{ src: `${MDI_BASE}/earth.svg`, mimeType: "image/svg+xml" }],
27
30
  introspection: [
28
31
  { src: `${MDI_BASE}/graph-outline.svg`, mimeType: "image/svg+xml" }