@lightdash-tools/mcp 0.5.0 → 0.7.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 (271) hide show
  1. package/README.md +133 -58
  2. package/dist/audit/audit.d.ts +5 -0
  3. package/dist/{audit.js → audit/audit.js} +1 -2
  4. package/dist/audit/tool-audit-context.d.ts +6 -0
  5. package/dist/audit/tool-audit-context.js +12 -0
  6. package/dist/audit/tool-audit-context.test.d.ts +1 -0
  7. package/dist/audit/tool-audit-context.test.js +19 -0
  8. package/dist/auth/auth-mode.d.ts +4 -0
  9. package/dist/auth/auth-mode.js +6 -0
  10. package/dist/auth/bearer.d.ts +3 -0
  11. package/dist/auth/bearer.js +13 -0
  12. package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
  13. package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
  14. package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
  15. package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
  16. package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
  17. package/dist/auth/oauth-broker/as-metadata.js +20 -0
  18. package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
  19. package/dist/auth/oauth-broker/lightdash-token.js +76 -0
  20. package/dist/auth/oauth-broker/pending-store.d.ts +76 -0
  21. package/dist/auth/oauth-broker/pending-store.js +124 -0
  22. package/dist/auth/oauth-broker/pkce.d.ts +2 -0
  23. package/dist/auth/oauth-broker/pkce.js +17 -0
  24. package/dist/auth/oauth-broker/routes.d.ts +9 -0
  25. package/dist/auth/oauth-broker/routes.js +447 -0
  26. package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
  27. package/dist/auth/oauth-broker/routes.test.js +237 -0
  28. package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
  29. package/dist/auth/providers/bearer-context-provider.js +52 -0
  30. package/dist/auth/providers/env-context-provider.d.ts +13 -0
  31. package/dist/auth/providers/env-context-provider.js +19 -0
  32. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
  33. package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
  34. package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
  35. package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
  36. package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
  37. package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
  38. package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
  39. package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
  40. package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
  41. package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
  42. package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
  43. package/dist/auth/resource-server/shared-key-middleware.js +24 -0
  44. package/dist/auth/resource-server/token-scopes.d.ts +15 -0
  45. package/dist/auth/resource-server/token-scopes.js +76 -0
  46. package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
  47. package/dist/auth/resource-server/token-scopes.test.js +51 -0
  48. package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
  49. package/dist/auth/resource-server/token-validation-cache.js +44 -0
  50. package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
  51. package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
  52. package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
  53. package/dist/auth/resource-server/token-validation-error.js +13 -0
  54. package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
  55. package/dist/auth/resource-server/www-authenticate.js +24 -0
  56. package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
  57. package/dist/auth/resource-server/www-authenticate.test.js +64 -0
  58. package/dist/auth/token-hash.d.ts +2 -0
  59. package/dist/auth/token-hash.js +8 -0
  60. package/dist/bin.d.ts +0 -4
  61. package/dist/bin.js +41 -33
  62. package/dist/config/env.d.ts +50 -0
  63. package/dist/config/env.js +53 -0
  64. package/dist/config/load-mcp-config.d.ts +30 -0
  65. package/dist/config/load-mcp-config.js +282 -0
  66. package/dist/config/load-mcp-config.test.d.ts +1 -0
  67. package/dist/config/load-mcp-config.test.js +195 -0
  68. package/dist/config/normalize-url.d.ts +13 -0
  69. package/dist/config/normalize-url.js +52 -0
  70. package/dist/config/normalize-url.test.d.ts +1 -0
  71. package/dist/config/normalize-url.test.js +41 -0
  72. package/dist/config/public-url.d.ts +3 -0
  73. package/dist/config/public-url.js +10 -0
  74. package/dist/config/runtime.d.ts +15 -0
  75. package/dist/config/runtime.js +48 -0
  76. package/dist/config/runtime.test.d.ts +1 -0
  77. package/dist/config/runtime.test.js +69 -0
  78. package/dist/config/test-mcp-http-config.d.ts +3 -0
  79. package/dist/config/test-mcp-http-config.js +7 -0
  80. package/dist/governance/project-pin.d.ts +14 -0
  81. package/dist/governance/project-pin.js +44 -0
  82. package/dist/governance/project-pin.test.d.ts +1 -0
  83. package/dist/governance/project-pin.test.js +35 -0
  84. package/dist/http.d.ts +1 -2
  85. package/dist/http.integration.test.d.ts +1 -0
  86. package/dist/http.integration.test.js +688 -0
  87. package/dist/http.js +3 -170
  88. package/dist/http.test.d.ts +4 -0
  89. package/dist/http.test.js +131 -0
  90. package/dist/index.d.ts +2 -0
  91. package/dist/index.integration.test.js +73 -30
  92. package/dist/index.js +28 -27
  93. package/dist/index.test.js +3 -3
  94. package/dist/logging/structured.d.ts +27 -0
  95. package/dist/logging/structured.js +32 -0
  96. package/dist/logging/structured.test.d.ts +1 -0
  97. package/dist/logging/structured.test.js +33 -0
  98. package/dist/personas/index.d.ts +19 -0
  99. package/dist/personas/index.js +57 -0
  100. package/dist/personas/index.test.d.ts +1 -0
  101. package/dist/personas/index.test.js +58 -0
  102. package/dist/personas/organization-audit/v1/index.d.ts +8 -0
  103. package/dist/personas/organization-audit/v1/index.js +42 -0
  104. package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
  105. package/dist/personas/organization-audit/v1/prompts.js +111 -0
  106. package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
  107. package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
  108. package/dist/personas/organization-audit/v1/resources/playbook.d.ts +11 -0
  109. package/dist/personas/organization-audit/v1/resources/playbook.js +40 -0
  110. package/dist/personas/organization-audit/v1/resources/playbook.md +52 -0
  111. package/dist/personas/semantic-layer/v1/index.d.ts +8 -0
  112. package/dist/personas/semantic-layer/v1/index.js +32 -0
  113. package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
  114. package/dist/personas/semantic-layer/v1/prompts.js +107 -0
  115. package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +12 -0
  116. package/dist/personas/semantic-layer/v1/resources/playbook.js +42 -0
  117. package/dist/personas/semantic-layer/v1/resources/playbook.md +153 -0
  118. package/dist/personas/types.d.ts +19 -0
  119. package/dist/personas/types.js +5 -0
  120. package/dist/protocol-contract.test.d.ts +1 -0
  121. package/dist/protocol-contract.test.js +42 -0
  122. package/dist/server/capabilities.d.ts +15 -0
  123. package/dist/server/capabilities.js +19 -0
  124. package/dist/server/capabilities.test.d.ts +1 -0
  125. package/dist/server/capabilities.test.js +39 -0
  126. package/dist/server/errors.test.d.ts +1 -0
  127. package/dist/server/errors.test.js +53 -0
  128. package/dist/server/request-context.d.ts +13 -0
  129. package/dist/server/request-context.js +2 -0
  130. package/dist/server/server.d.ts +4 -0
  131. package/dist/server/server.js +17 -0
  132. package/dist/server/server.test.d.ts +1 -0
  133. package/dist/server/server.test.js +15 -0
  134. package/dist/server/version.d.ts +1 -0
  135. package/dist/server/version.js +7 -0
  136. package/dist/server/version.test.d.ts +1 -0
  137. package/dist/server/version.test.js +9 -0
  138. package/dist/stdio.process.test.d.ts +1 -0
  139. package/dist/stdio.process.test.js +126 -0
  140. package/dist/tools/index.d.ts +2 -4
  141. package/dist/tools/index.js +4 -30
  142. package/dist/tools/index.test.d.ts +1 -0
  143. package/dist/tools/index.test.js +72 -0
  144. package/dist/tools/lib/api-errors.d.ts +9 -0
  145. package/dist/tools/lib/api-errors.js +22 -0
  146. package/dist/tools/lib/api-shape.d.ts +16 -0
  147. package/dist/tools/lib/api-shape.js +47 -0
  148. package/dist/tools/lib/assert-safe.d.ts +13 -0
  149. package/dist/tools/lib/assert-safe.js +21 -0
  150. package/dist/tools/lib/assert-safe.test.d.ts +4 -0
  151. package/dist/tools/lib/assert-safe.test.js +32 -0
  152. package/dist/tools/lib/concurrency.d.ts +4 -0
  153. package/dist/tools/lib/concurrency.js +24 -0
  154. package/dist/tools/lib/contracts.d.ts +34 -0
  155. package/dist/tools/lib/contracts.js +30 -0
  156. package/dist/tools/lib/redaction.d.ts +107 -0
  157. package/dist/tools/lib/redaction.js +299 -0
  158. package/dist/tools/lib/redaction.test.d.ts +4 -0
  159. package/dist/tools/lib/redaction.test.js +216 -0
  160. package/dist/tools/lib/register-org-audit.d.ts +9 -0
  161. package/dist/tools/lib/register-org-audit.js +20 -0
  162. package/dist/tools/lib/schema-fields.d.ts +9 -0
  163. package/dist/tools/lib/schema-fields.js +19 -0
  164. package/dist/tools/organization/binding.d.ts +14 -0
  165. package/dist/tools/organization/binding.js +31 -0
  166. package/dist/tools/organization/invariants.test.d.ts +4 -0
  167. package/dist/tools/organization/invariants.test.js +28 -0
  168. package/dist/tools/organization/inventory.d.ts +10 -0
  169. package/dist/tools/organization/inventory.js +189 -0
  170. package/dist/tools/organization/roles.d.ts +10 -0
  171. package/dist/tools/organization/roles.js +213 -0
  172. package/dist/tools/project/content.d.ts +9 -0
  173. package/dist/tools/project/content.js +192 -0
  174. package/dist/tools/project/projects.d.ts +7 -0
  175. package/dist/tools/project/projects.js +42 -0
  176. package/dist/tools/project/projects.test.d.ts +1 -0
  177. package/dist/tools/project/projects.test.js +117 -0
  178. package/dist/tools/project/schedulers.d.ts +7 -0
  179. package/dist/tools/project/schedulers.js +115 -0
  180. package/dist/tools/registry.d.ts +104 -0
  181. package/dist/tools/registry.js +59 -0
  182. package/dist/tools/semantic/explore-helpers.d.ts +56 -0
  183. package/dist/tools/semantic/explore-helpers.js +115 -0
  184. package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
  185. package/dist/tools/semantic/explore-helpers.test.js +170 -0
  186. package/dist/tools/semantic/explores.d.ts +9 -0
  187. package/dist/tools/semantic/explores.js +80 -0
  188. package/dist/tools/semantic/metrics.d.ts +7 -0
  189. package/dist/tools/semantic/metrics.js +53 -0
  190. package/dist/tools/semantic/query.d.ts +6 -0
  191. package/dist/tools/semantic/query.js +42 -0
  192. package/dist/tools/semantic/schema-fields.d.ts +3 -0
  193. package/dist/tools/semantic/schema-fields.js +7 -0
  194. package/dist/tools/shared.d.ts +26 -13
  195. package/dist/tools/shared.js +112 -157
  196. package/dist/tools/shared.test.js +132 -183
  197. package/dist/tools/space/access.d.ts +66 -0
  198. package/dist/tools/space/access.js +322 -0
  199. package/dist/tools/space/access.test.d.ts +4 -0
  200. package/dist/tools/space/access.test.js +90 -0
  201. package/dist/transports/http-body.d.ts +5 -0
  202. package/dist/transports/http-body.js +50 -0
  203. package/dist/transports/http-request-utils.d.ts +2 -0
  204. package/dist/transports/http-request-utils.js +13 -0
  205. package/dist/transports/http-response.d.ts +6 -0
  206. package/dist/transports/http-response.js +56 -0
  207. package/dist/transports/session-store.d.ts +40 -0
  208. package/dist/transports/session-store.js +88 -0
  209. package/dist/transports/session-store.test.d.ts +1 -0
  210. package/dist/transports/session-store.test.js +111 -0
  211. package/dist/transports/streamable-http.d.ts +9 -0
  212. package/dist/transports/streamable-http.js +454 -0
  213. package/dist/transports/streamable-http.test.d.ts +1 -0
  214. package/dist/transports/streamable-http.test.js +95 -0
  215. package/package.json +25 -10
  216. package/dist/audit.d.ts +0 -6
  217. package/dist/config.d.ts +0 -47
  218. package/dist/config.js +0 -82
  219. package/dist/tools/ai-agents.d.ts +0 -6
  220. package/dist/tools/ai-agents.js +0 -388
  221. package/dist/tools/charts.d.ts +0 -6
  222. package/dist/tools/charts.js +0 -55
  223. package/dist/tools/content.d.ts +0 -6
  224. package/dist/tools/content.js +0 -37
  225. package/dist/tools/dashboards.d.ts +0 -6
  226. package/dist/tools/dashboards.js +0 -28
  227. package/dist/tools/explores.d.ts +0 -6
  228. package/dist/tools/explores.js +0 -65
  229. package/dist/tools/groups.d.ts +0 -6
  230. package/dist/tools/groups.js +0 -121
  231. package/dist/tools/metrics.d.ts +0 -6
  232. package/dist/tools/metrics.js +0 -45
  233. package/dist/tools/projects.d.ts +0 -6
  234. package/dist/tools/projects.js +0 -58
  235. package/dist/tools/query.d.ts +0 -6
  236. package/dist/tools/query.js +0 -34
  237. package/dist/tools/schedulers.d.ts +0 -6
  238. package/dist/tools/schedulers.js +0 -45
  239. package/dist/tools/spaces.d.ts +0 -6
  240. package/dist/tools/spaces.js +0 -128
  241. package/dist/tools/tags.d.ts +0 -6
  242. package/dist/tools/tags.js +0 -28
  243. package/dist/tools/users.d.ts +0 -6
  244. package/dist/tools/users.js +0 -50
  245. package/src/audit.ts +0 -6
  246. package/src/bin.ts +0 -58
  247. package/src/config.ts +0 -83
  248. package/src/errors.ts +0 -27
  249. package/src/http.ts +0 -187
  250. package/src/index.integration.test.ts +0 -57
  251. package/src/index.test.ts +0 -8
  252. package/src/index.ts +0 -31
  253. package/src/tools/ai-agents.ts +0 -759
  254. package/src/tools/charts.ts +0 -85
  255. package/src/tools/content.ts +0 -44
  256. package/src/tools/dashboards.ts +0 -25
  257. package/src/tools/explores.ts +0 -98
  258. package/src/tools/groups.ts +0 -180
  259. package/src/tools/index.ts +0 -35
  260. package/src/tools/metrics.ts +0 -42
  261. package/src/tools/projects.ts +0 -74
  262. package/src/tools/query.ts +0 -47
  263. package/src/tools/schedulers.ts +0 -42
  264. package/src/tools/shared.test.ts +0 -365
  265. package/src/tools/shared.ts +0 -274
  266. package/src/tools/spaces.ts +0 -217
  267. package/src/tools/tags.ts +0 -25
  268. package/src/tools/users.ts +0 -64
  269. package/tsconfig.json +0 -13
  270. /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
  271. /package/dist/{errors.js → server/errors.js} +0 -0
@@ -1,24 +1,17 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const vitest_1 = require("vitest");
13
- const shared_1 = require("./shared");
14
3
  const common_1 = require("@lightdash-tools/common");
15
- const config_js_1 = require("../config.js");
4
+ const vitest_1 = require("vitest");
5
+ const project_pin_js_1 = require("../governance/project-pin.js");
6
+ const shared_js_1 = require("./shared.js");
16
7
  // Silence audit log output during tests
17
- vitest_1.vi.mock('@lightdash-tools/common', (importOriginal) => __awaiter(void 0, void 0, void 0, function* () {
8
+ vitest_1.vi.mock('@lightdash-tools/common', async (importOriginal) => {
18
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- const actual = yield importOriginal();
10
+ const actual = await importOriginal();
20
11
  return Object.assign(Object.assign({}, actual), { getSessionId: () => 'test-session', logAuditEntry: vitest_1.vi.fn(), initAuditLog: vitest_1.vi.fn() });
21
- }));
12
+ });
13
+ const PROJECT_A = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
14
+ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
22
15
  (0, vitest_1.describe)('registerToolSafe', () => {
23
16
  const mockServer = {
24
17
  registerTool: vitest_1.vi.fn(),
@@ -27,195 +20,151 @@ vitest_1.vi.mock('@lightdash-tools/common', (importOriginal) => __awaiter(void 0
27
20
  (0, vitest_1.beforeEach)(() => {
28
21
  mockServer.registerTool.mockClear();
29
22
  mockHandler.mockClear();
30
- // Reset globals to safe defaults
31
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.WRITE_DESTRUCTIVE);
32
- (0, config_js_1.setStaticAllowedProjectUuids)([]);
33
- (0, config_js_1.setDryRunMode)(false);
34
- process.env.LIGHTDASH_TOOLS_SAFETY_MODE = common_1.SafetyMode.WRITE_DESTRUCTIVE;
35
- delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
36
- delete process.env.LIGHTDASH_TOOLS_DRY_RUN;
23
+ vitest_1.vi.mocked(common_1.logAuditEntry).mockClear();
37
24
  });
38
- (0, vitest_1.afterEach)(() => {
39
- delete process.env.LIGHTDASH_TOOLS_SAFETY_MODE;
40
- });
41
- (0, vitest_1.it)('should allow read-only tool in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
42
- process.env.LIGHTDASH_TOOLS_SAFETY_MODE = common_1.SafetyMode.READ_ONLY;
43
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.WRITE_DESTRUCTIVE); // static = allow all
44
- (0, shared_1.registerToolSafe)(mockServer, 'test_tool', {
25
+ (0, vitest_1.it)('registers tools and invokes the handler', async () => {
26
+ (0, shared_js_1.registerToolSafe)(mockServer, 'test_tool', {
45
27
  description: 'Test description',
46
28
  inputSchema: {},
47
- annotations: shared_1.READ_ONLY_DEFAULT,
29
+ annotations: shared_js_1.READ_ONLY_DEFAULT,
48
30
  }, mockHandler);
49
31
  (0, vitest_1.expect)(mockServer.registerTool).toHaveBeenCalled();
50
32
  const [name, options, handler] = mockServer.registerTool.mock.calls[0];
51
33
  (0, vitest_1.expect)(name).toContain('test_tool');
52
34
  (0, vitest_1.expect)(options.description).toBe('Test description');
53
- const result = yield handler({});
35
+ const result = await handler({});
54
36
  (0, vitest_1.expect)(result.content[0].text).toBe('success');
55
- }));
56
- (0, vitest_1.it)('should block destructive tool in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
57
- process.env.LIGHTDASH_TOOLS_SAFETY_MODE = common_1.SafetyMode.READ_ONLY;
58
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.WRITE_DESTRUCTIVE);
59
- (0, shared_1.registerToolSafe)(mockServer, 'delete_tool', {
60
- description: 'Delete something',
61
- inputSchema: {},
62
- annotations: shared_1.WRITE_DESTRUCTIVE,
63
- }, mockHandler);
64
- const [, options, handler] = mockServer.registerTool.mock.calls[0];
65
- (0, vitest_1.expect)(options.description).toContain('[DISABLED in read-only mode]');
66
- const result = yield handler({});
67
- (0, vitest_1.expect)(result.isError).toBe(true);
68
- (0, vitest_1.expect)(result.content[0].text).toContain('disabled in read-only mode');
69
- }));
70
- (0, vitest_1.it)('should allow destructive tool in write-destructive mode', () => __awaiter(void 0, void 0, void 0, function* () {
71
- process.env.LIGHTDASH_TOOLS_SAFETY_MODE = common_1.SafetyMode.WRITE_DESTRUCTIVE;
72
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.WRITE_DESTRUCTIVE);
73
- (0, shared_1.registerToolSafe)(mockServer, 'delete_tool_2', {
74
- description: 'Delete something 2',
75
- inputSchema: {},
76
- annotations: shared_1.WRITE_DESTRUCTIVE,
77
- }, mockHandler);
78
- const [, options, handler] = mockServer.registerTool.mock.calls[0];
79
- (0, vitest_1.expect)(options.description).toBe('Delete something 2');
80
- const result = yield handler({});
37
+ });
38
+ (0, vitest_1.it)('allows tools when OAuth subject is present (no local JWT scope gate)', async () => {
39
+ const contextProvider = {
40
+ getContext: async () => ({
41
+ lightdashClient: {},
42
+ auth: {
43
+ mode: 'lightdash-oauth',
44
+ tokenHash: 'hash-abc',
45
+ subject: 'user-1',
46
+ },
47
+ }),
48
+ };
49
+ const wrapped = (0, shared_js_1.wrapTool)(contextProvider, () => async () => ({
50
+ content: [{ type: 'text', text: 'success' }],
51
+ }));
52
+ const result = await wrapped({});
53
+ (0, vitest_1.expect)(result.isError).toBeUndefined();
81
54
  (0, vitest_1.expect)(result.content[0].text).toBe('success');
82
- }));
83
- (0, vitest_1.it)('should reject invalid projectUuid before calling handler', () => __awaiter(void 0, void 0, void 0, function* () {
84
- (0, shared_1.registerToolSafe)(mockServer, 'list_tool', {
55
+ });
56
+ (0, vitest_1.it)('should reject invalid projectUuid before calling handler', async () => {
57
+ (0, shared_js_1.registerToolSafe)(mockServer, 'list_tool', {
85
58
  description: 'List something',
86
59
  inputSchema: {},
87
- annotations: shared_1.READ_ONLY_DEFAULT,
60
+ annotations: shared_js_1.READ_ONLY_DEFAULT,
88
61
  }, mockHandler);
89
62
  const [, , handler] = mockServer.registerTool.mock.calls[0];
90
- const result = yield handler({ projectUuid: 'uuid?fields=name' });
63
+ const result = await handler({ projectUuid: 'uuid?fields=name' });
91
64
  (0, vitest_1.expect)(mockHandler).not.toHaveBeenCalled();
92
65
  (0, vitest_1.expect)(result.isError).toBe(true);
93
66
  (0, vitest_1.expect)(result.content[0].text).toContain('Invalid resource ID');
94
- }));
95
- (0, vitest_1.describe)('static filtering (safety-mode)', () => {
96
- (0, vitest_1.it)('should skip registration if tool is more permissive than binded mode', () => {
97
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.READ_ONLY);
98
- mockServer.registerTool.mockClear();
99
- (0, shared_1.registerToolSafe)(mockServer, 'destructive_tool_static', {
100
- description: 'Destructive',
101
- inputSchema: {},
102
- annotations: shared_1.WRITE_DESTRUCTIVE,
103
- }, mockHandler);
104
- (0, vitest_1.expect)(mockServer.registerTool).not.toHaveBeenCalled();
105
- });
106
- (0, vitest_1.it)('should allow registration if tool matches binded mode', () => {
107
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.READ_ONLY);
108
- mockServer.registerTool.mockClear();
109
- (0, shared_1.registerToolSafe)(mockServer, 'readonly_tool_static', {
110
- description: 'Read-only',
111
- inputSchema: {},
112
- annotations: shared_1.READ_ONLY_DEFAULT,
113
- }, mockHandler);
114
- (0, vitest_1.expect)(mockServer.registerTool).toHaveBeenCalled();
115
- });
116
- (0, vitest_1.it)('should allow everything if binded mode is write-destructive', () => {
117
- (0, config_js_1.setStaticSafetyMode)(common_1.SafetyMode.WRITE_DESTRUCTIVE);
118
- mockServer.registerTool.mockClear();
119
- (0, shared_1.registerToolSafe)(mockServer, 'any_tool_static', {
120
- description: 'Any',
121
- inputSchema: {},
122
- annotations: shared_1.WRITE_DESTRUCTIVE,
123
- }, mockHandler);
124
- (0, vitest_1.expect)(mockServer.registerTool).toHaveBeenCalled();
125
- });
126
67
  });
127
- (0, vitest_1.describe)('project UUID allowlist', () => {
128
- (0, vitest_1.it)('should allow calls when allowlist is empty (all projects permitted)', () => __awaiter(void 0, void 0, void 0, function* () {
129
- (0, config_js_1.setStaticAllowedProjectUuids)([]);
130
- (0, shared_1.registerToolSafe)(mockServer, 'list_charts', { description: 'List charts', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
131
- const [, , handler] = mockServer.registerTool.mock.calls[0];
132
- const result = yield handler({ projectUuid: 'any-uuid' });
133
- (0, vitest_1.expect)(result.isError).toBeUndefined();
134
- (0, vitest_1.expect)(result.content[0].text).toBe('success');
135
- }));
136
- (0, vitest_1.it)('should allow calls for a singular projectUuid in the allowlist', () => __awaiter(void 0, void 0, void 0, function* () {
137
- (0, config_js_1.setStaticAllowedProjectUuids)(['uuid-allowed', 'uuid-other']);
138
- (0, shared_1.registerToolSafe)(mockServer, 'list_charts_allowed', { description: 'List charts', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
139
- const [, , handler] = mockServer.registerTool.mock.calls[0];
140
- const result = yield handler({ projectUuid: 'uuid-allowed' });
141
- (0, vitest_1.expect)(result.isError).toBeUndefined();
142
- (0, vitest_1.expect)(result.content[0].text).toBe('success');
143
- }));
144
- (0, vitest_1.it)('should block calls for a singular projectUuid not in the allowlist', () => __awaiter(void 0, void 0, void 0, function* () {
145
- (0, config_js_1.setStaticAllowedProjectUuids)(['uuid-allowed']);
146
- (0, shared_1.registerToolSafe)(mockServer, 'list_charts_blocked', { description: 'List charts', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
147
- const [, , handler] = mockServer.registerTool.mock.calls[0];
148
- const result = yield handler({ projectUuid: 'uuid-denied' });
149
- (0, vitest_1.expect)(result.isError).toBe(true);
150
- (0, vitest_1.expect)(result.content[0].text).toContain('not in the list of allowed projects');
151
- (0, vitest_1.expect)(result.content[0].text).toContain('uuid-denied');
152
- }));
153
- (0, vitest_1.it)('should allow calls with no projectUuid arg even when allowlist is set', () => __awaiter(void 0, void 0, void 0, function* () {
154
- (0, config_js_1.setStaticAllowedProjectUuids)(['uuid-allowed']);
155
- (0, shared_1.registerToolSafe)(mockServer, 'list_projects_no_uuid', { description: 'List projects', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
68
+ (0, vitest_1.describe)('HTTP project pin', () => {
69
+ (0, vitest_1.it)('allows matching projectUuid when pin is set', async () => {
70
+ (0, shared_js_1.registerToolSafe)(mockServer, 'pinned_ok', { description: 'Get project', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, mockHandler);
156
71
  const [, , handler] = mockServer.registerTool.mock.calls[0];
157
- // No projectUuid in args → allowlist does not apply
158
- const result = yield handler({});
159
- (0, vitest_1.expect)(result.isError).toBeUndefined();
160
- (0, vitest_1.expect)(result.content[0].text).toBe('success');
161
- }));
162
- (0, vitest_1.it)('should allow when all projectUuids[] are in the allowlist', () => __awaiter(void 0, void 0, void 0, function* () {
163
- (0, config_js_1.setStaticAllowedProjectUuids)(['uuid-a', 'uuid-b']);
164
- (0, shared_1.registerToolSafe)(mockServer, 'search_content_allowed', { description: 'Search content', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
165
- const [, , handler] = mockServer.registerTool.mock.calls[0];
166
- const result = yield handler({ projectUuids: ['uuid-a', 'uuid-b'] });
167
- (0, vitest_1.expect)(result.isError).toBeUndefined();
168
- (0, vitest_1.expect)(result.content[0].text).toBe('success');
169
- }));
170
- (0, vitest_1.it)('should block when any UUID in projectUuids[] is not in the allowlist', () => __awaiter(void 0, void 0, void 0, function* () {
171
- (0, config_js_1.setStaticAllowedProjectUuids)(['uuid-a']);
172
- (0, shared_1.registerToolSafe)(mockServer, 'search_content_blocked', { description: 'Search content', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
72
+ await (0, project_pin_js_1.runWithProjectPinAsync)(PROJECT_A, async () => {
73
+ const result = await handler({ projectUuid: PROJECT_A });
74
+ (0, vitest_1.expect)(result.isError).toBeUndefined();
75
+ (0, vitest_1.expect)(result.content[0].text).toBe('success');
76
+ });
77
+ });
78
+ (0, vitest_1.it)('blocks mismatched projectUuid when pin is set', async () => {
79
+ (0, shared_js_1.registerToolSafe)(mockServer, 'pinned_block', { description: 'Get project', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, mockHandler);
173
80
  const [, , handler] = mockServer.registerTool.mock.calls[0];
174
- const result = yield handler({ projectUuids: ['uuid-a', 'uuid-denied'] });
175
- (0, vitest_1.expect)(result.isError).toBe(true);
176
- (0, vitest_1.expect)(result.content[0].text).toContain('uuid-denied');
177
- (0, vitest_1.expect)(result.content[0].text).toContain('not in the list of allowed projects');
178
- }));
179
- (0, vitest_1.it)('should block when all projectUuids[] are outside the allowlist', () => __awaiter(void 0, void 0, void 0, function* () {
180
- (0, config_js_1.setStaticAllowedProjectUuids)(['uuid-allowed']);
181
- (0, shared_1.registerToolSafe)(mockServer, 'search_content_all_blocked', { description: 'Search content', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
81
+ await (0, project_pin_js_1.runWithProjectPinAsync)(PROJECT_A, async () => {
82
+ const result = await handler({ projectUuid: PROJECT_B });
83
+ (0, vitest_1.expect)(result.isError).toBe(true);
84
+ (0, vitest_1.expect)(result.content[0].text).toContain('do not match the pinned project');
85
+ (0, vitest_1.expect)(result.content[0].text).toContain(PROJECT_A);
86
+ (0, vitest_1.expect)(result.content[0].text).toContain(PROJECT_B);
87
+ (0, vitest_1.expect)('_lightdashBlocked' in result).toBe(false);
88
+ (0, vitest_1.expect)(common_1.logAuditEntry).toHaveBeenCalledWith(vitest_1.expect.objectContaining({ status: 'blocked', tool: `${shared_js_1.TOOL_PREFIX}pinned_block` }));
89
+ });
90
+ (0, vitest_1.expect)(mockHandler).not.toHaveBeenCalled();
91
+ });
92
+ (0, vitest_1.it)('allows tools with no projectUuid when pin is set', async () => {
93
+ (0, shared_js_1.registerToolSafe)(mockServer, 'pinned_no_uuid', { description: 'List', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, mockHandler);
182
94
  const [, , handler] = mockServer.registerTool.mock.calls[0];
183
- const result = yield handler({ projectUuids: ['uuid-x', 'uuid-y'] });
184
- (0, vitest_1.expect)(result.isError).toBe(true);
185
- (0, vitest_1.expect)(result.content[0].text).toContain('not in the list of allowed projects');
186
- }));
95
+ await (0, project_pin_js_1.runWithProjectPinAsync)(PROJECT_A, async () => {
96
+ const result = await handler({});
97
+ (0, vitest_1.expect)(result.isError).toBeUndefined();
98
+ (0, vitest_1.expect)(result.content[0].text).toBe('success');
99
+ });
100
+ });
187
101
  });
188
- (0, vitest_1.describe)('dry-run mode', () => {
189
- (0, vitest_1.it)('should not affect read-only tools in dry-run mode', () => __awaiter(void 0, void 0, void 0, function* () {
190
- (0, config_js_1.setDryRunMode)(true);
191
- (0, shared_1.registerToolSafe)(mockServer, 'list_things_dry', { description: 'List things', inputSchema: {}, annotations: shared_1.READ_ONLY_DEFAULT }, mockHandler);
192
- const [, options, handler] = mockServer.registerTool.mock.calls[0];
193
- (0, vitest_1.expect)(options.description).not.toContain('[DRY-RUN]');
194
- const result = yield handler({});
195
- (0, vitest_1.expect)(result.content[0].text).toBe('success');
196
- }));
197
- (0, vitest_1.it)('should simulate write-idempotent tools in dry-run mode', () => __awaiter(void 0, void 0, void 0, function* () {
198
- (0, config_js_1.setDryRunMode)(true);
199
- process.env.LIGHTDASH_TOOLS_SAFETY_MODE = common_1.SafetyMode.WRITE_DESTRUCTIVE;
200
- (0, shared_1.registerToolSafe)(mockServer, 'upsert_thing_dry', { description: 'Upsert thing', inputSchema: {}, annotations: shared_1.WRITE_IDEMPOTENT }, mockHandler);
201
- const [, options, handler] = mockServer.registerTool.mock.calls[0];
202
- (0, vitest_1.expect)(options.description).toContain('[DRY-RUN]');
203
- const result = yield handler({ projectUuid: 'uuid-x', slug: 'my-chart' });
204
- (0, vitest_1.expect)(result.isError).toBeUndefined();
205
- (0, vitest_1.expect)(result.content[0].text).toContain('[DRY-RUN]');
206
- (0, vitest_1.expect)(result.content[0].text).toContain('No changes were made');
207
- // Verify the underlying handler was NOT called
208
- (0, vitest_1.expect)(mockHandler).not.toHaveBeenCalled();
209
- }));
210
- (0, vitest_1.it)('should simulate destructive tools in dry-run mode', () => __awaiter(void 0, void 0, void 0, function* () {
211
- (0, config_js_1.setDryRunMode)(true);
212
- process.env.LIGHTDASH_TOOLS_SAFETY_MODE = common_1.SafetyMode.WRITE_DESTRUCTIVE;
213
- (0, shared_1.registerToolSafe)(mockServer, 'delete_thing_dry', { description: 'Delete thing', inputSchema: {}, annotations: shared_1.WRITE_DESTRUCTIVE }, mockHandler);
214
- const [, options, handler] = mockServer.registerTool.mock.calls[0];
215
- (0, vitest_1.expect)(options.description).toContain('[DRY-RUN]');
216
- const result = yield handler({ projectUuid: 'uuid-x' });
217
- (0, vitest_1.expect)(result.content[0].text).toContain('No changes were made');
218
- (0, vitest_1.expect)(mockHandler).not.toHaveBeenCalled();
219
- }));
102
+ (0, vitest_1.it)('should reject invalid slug before calling handler', async () => {
103
+ (0, shared_js_1.registerToolSafe)(mockServer, 'slug_tool', { description: 'Uses slug', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, mockHandler);
104
+ const [, , handler] = mockServer.registerTool.mock.calls[0];
105
+ const result = await handler({ slug: 'bad?slug' });
106
+ (0, vitest_1.expect)(mockHandler).not.toHaveBeenCalled();
107
+ (0, vitest_1.expect)(result.isError).toBe(true);
108
+ (0, vitest_1.expect)(result.content[0].text).toContain('Slug must');
109
+ (0, vitest_1.expect)(common_1.logAuditEntry).toHaveBeenCalledWith(vitest_1.expect.objectContaining({ status: 'blocked', tool: `${shared_js_1.TOOL_PREFIX}slug_tool` }));
110
+ });
111
+ (0, vitest_1.it)('should reject invalid projectUuids array entries before calling handler', async () => {
112
+ (0, shared_js_1.registerToolSafe)(mockServer, 'plural_uuid_tool', { description: 'Uses projectUuids', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, mockHandler);
113
+ const [, , handler] = mockServer.registerTool.mock.calls[0];
114
+ const result = await handler({ projectUuids: [PROJECT_A, 'not-a-uuid'] });
115
+ (0, vitest_1.expect)(mockHandler).not.toHaveBeenCalled();
116
+ (0, vitest_1.expect)(result.isError).toBe(true);
117
+ (0, vitest_1.expect)(result.content[0].text).toContain('Invalid UUID');
118
+ (0, vitest_1.expect)(common_1.logAuditEntry).toHaveBeenCalledWith(vitest_1.expect.objectContaining({ status: 'blocked', tool: `${shared_js_1.TOOL_PREFIX}plural_uuid_tool` }));
119
+ });
120
+ (0, vitest_1.it)('should rethrow when the audited handler throws', async () => {
121
+ const failingHandler = vitest_1.vi.fn().mockRejectedValue(new Error('boom'));
122
+ (0, shared_js_1.registerToolSafe)(mockServer, 'throws_tool', { description: 'Throws', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, failingHandler);
123
+ const [, , handler] = mockServer.registerTool.mock.calls[0];
124
+ await (0, vitest_1.expect)(handler({})).rejects.toThrow('boom');
125
+ });
126
+ (0, vitest_1.it)('should mark audit status error when handler returns isError', async () => {
127
+ const errorHandler = vitest_1.vi.fn().mockResolvedValue({
128
+ content: [{ type: 'text', text: 'failed' }],
129
+ isError: true,
130
+ });
131
+ (0, shared_js_1.registerToolSafe)(mockServer, 'error_result_tool', { description: 'Returns error', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, errorHandler);
132
+ const [, , handler] = mockServer.registerTool.mock.calls[0];
133
+ const result = await handler({});
134
+ (0, vitest_1.expect)(result.isError).toBe(true);
135
+ });
136
+ (0, vitest_1.it)('should attach structuredContent when handler returns JSON text', async () => {
137
+ const jsonHandler = vitest_1.vi.fn().mockResolvedValue({
138
+ content: [{ type: 'text', text: JSON.stringify({ ok: true }) }],
139
+ });
140
+ (0, shared_js_1.registerToolSafe)(mockServer, 'json_tool', { description: 'Returns JSON', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, jsonHandler);
141
+ const [, , handler] = mockServer.registerTool.mock.calls[0];
142
+ const result = await handler({});
143
+ (0, vitest_1.expect)(result.structuredContent).toEqual({ ok: true });
144
+ (0, vitest_1.expect)(JSON.parse(result.content[0].text)).toEqual({ ok: true });
145
+ });
146
+ (0, vitest_1.it)('should wrap array JSON in structuredContent.data', async () => {
147
+ const jsonHandler = vitest_1.vi.fn().mockResolvedValue({
148
+ content: [{ type: 'text', text: JSON.stringify([{ id: 'a' }]) }],
149
+ });
150
+ (0, shared_js_1.registerToolSafe)(mockServer, 'json_array_tool', { description: 'Returns JSON array', inputSchema: {}, annotations: shared_js_1.READ_ONLY_DEFAULT }, jsonHandler);
151
+ const [, , handler] = mockServer.registerTool.mock.calls[0];
152
+ const result = await handler({});
153
+ (0, vitest_1.expect)(result.structuredContent).toEqual({ data: [{ id: 'a' }] });
154
+ (0, vitest_1.expect)(JSON.parse(result.content[0].text)).toEqual([{ id: 'a' }]);
155
+ });
156
+ (0, vitest_1.it)('wrapTool returns a safe error message when the inner handler throws', async () => {
157
+ const contextProvider = {
158
+ getContext: async () => ({
159
+ lightdashClient: {},
160
+ auth: { mode: 'none' },
161
+ }),
162
+ };
163
+ const wrapped = (0, shared_js_1.wrapTool)(contextProvider, () => async () => {
164
+ throw new Error('boom');
165
+ });
166
+ const result = await wrapped({});
167
+ (0, vitest_1.expect)(result.isError).toBe(true);
168
+ (0, vitest_1.expect)(result.content[0].text).toBe('boom');
220
169
  });
221
170
  });
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Space access and effective-access composition tools.
3
+ */
4
+ import type { McpContextProvider } from '../../server/request-context.js';
5
+ import type { McpServer } from '@modelcontextprotocol/server';
6
+ export type SpaceAccessRow = {
7
+ spaceUuid: string;
8
+ spaceName?: string;
9
+ principalType: 'group' | 'user';
10
+ principalUuid?: string;
11
+ role?: string;
12
+ hasDirectAccess?: boolean;
13
+ inheritedFrom?: string;
14
+ inheritedRole?: string;
15
+ };
16
+ /** Maps space ACL payloads into audit rows; optionally drops inherited-only users. */
17
+ export declare function buildSpaceAccessRows(spaceList: Array<{
18
+ uuid: string;
19
+ name?: string;
20
+ access?: unknown;
21
+ groupsAccess?: unknown;
22
+ }>, includeInherited?: boolean): SpaceAccessRow[];
23
+ export type EffectiveAccessRecord = {
24
+ principalType: 'group' | 'user';
25
+ principalUuid: string;
26
+ resourceType: 'organization' | 'project' | 'space';
27
+ resourceUuid: string;
28
+ effectiveRole?: string;
29
+ accessPaths: Array<{
30
+ source: 'organization_role' | 'project_direct' | 'project_group' | 'space_direct' | 'space_group' | 'space_inherited';
31
+ sourceUuid?: string;
32
+ role?: string;
33
+ }>;
34
+ complete: boolean;
35
+ warnings: string[];
36
+ };
37
+ /** Pure helper for tests: merge observed access paths into records. */
38
+ export declare function composeEffectiveAccessRecords(input: {
39
+ orgAssignments: Array<{
40
+ assigneeType: string;
41
+ assigneeId: string;
42
+ roleName?: string;
43
+ roleId?: string;
44
+ }>;
45
+ projectAssignments: Array<{
46
+ assigneeType: string;
47
+ assigneeId: string;
48
+ roleName?: string;
49
+ roleId?: string;
50
+ }>;
51
+ directAccess: Array<{
52
+ userUuid: string;
53
+ role?: string;
54
+ }>;
55
+ spaceAccess: Array<{
56
+ spaceUuid: string;
57
+ principalType: string;
58
+ principalUuid?: string;
59
+ role?: string;
60
+ inheritedFrom?: string;
61
+ hasDirectAccess?: boolean;
62
+ }>;
63
+ projectUuid: string;
64
+ }): EffectiveAccessRecord[];
65
+ export declare function registerListSpaceAccess(server: McpServer, contextProvider: McpContextProvider): void;
66
+ export declare function registerResolveEffectiveAccess(server: McpServer, contextProvider: McpContextProvider): void;