@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.
- package/README.md +133 -58
- package/dist/audit/audit.d.ts +5 -0
- package/dist/{audit.js → audit/audit.js} +1 -2
- package/dist/audit/tool-audit-context.d.ts +6 -0
- package/dist/audit/tool-audit-context.js +12 -0
- package/dist/audit/tool-audit-context.test.d.ts +1 -0
- package/dist/audit/tool-audit-context.test.js +19 -0
- package/dist/auth/auth-mode.d.ts +4 -0
- package/dist/auth/auth-mode.js +6 -0
- package/dist/auth/bearer.d.ts +3 -0
- package/dist/auth/bearer.js +13 -0
- package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
- package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
- package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
- package/dist/auth/oauth-broker/as-metadata.js +20 -0
- package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
- package/dist/auth/oauth-broker/lightdash-token.js +76 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +76 -0
- package/dist/auth/oauth-broker/pending-store.js +124 -0
- package/dist/auth/oauth-broker/pkce.d.ts +2 -0
- package/dist/auth/oauth-broker/pkce.js +17 -0
- package/dist/auth/oauth-broker/routes.d.ts +9 -0
- package/dist/auth/oauth-broker/routes.js +447 -0
- package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
- package/dist/auth/oauth-broker/routes.test.js +237 -0
- package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
- package/dist/auth/providers/bearer-context-provider.js +52 -0
- package/dist/auth/providers/env-context-provider.d.ts +13 -0
- package/dist/auth/providers/env-context-provider.js +19 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
- package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
- package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
- package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
- package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
- package/dist/auth/resource-server/shared-key-middleware.js +24 -0
- package/dist/auth/resource-server/token-scopes.d.ts +15 -0
- package/dist/auth/resource-server/token-scopes.js +76 -0
- package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
- package/dist/auth/resource-server/token-scopes.test.js +51 -0
- package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
- package/dist/auth/resource-server/token-validation-cache.js +44 -0
- package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
- package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
- package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
- package/dist/auth/resource-server/token-validation-error.js +13 -0
- package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
- package/dist/auth/resource-server/www-authenticate.js +24 -0
- package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
- package/dist/auth/resource-server/www-authenticate.test.js +64 -0
- package/dist/auth/token-hash.d.ts +2 -0
- package/dist/auth/token-hash.js +8 -0
- package/dist/bin.d.ts +0 -4
- package/dist/bin.js +41 -33
- package/dist/config/env.d.ts +50 -0
- package/dist/config/env.js +53 -0
- package/dist/config/load-mcp-config.d.ts +30 -0
- package/dist/config/load-mcp-config.js +282 -0
- package/dist/config/load-mcp-config.test.d.ts +1 -0
- package/dist/config/load-mcp-config.test.js +195 -0
- package/dist/config/normalize-url.d.ts +13 -0
- package/dist/config/normalize-url.js +52 -0
- package/dist/config/normalize-url.test.d.ts +1 -0
- package/dist/config/normalize-url.test.js +41 -0
- package/dist/config/public-url.d.ts +3 -0
- package/dist/config/public-url.js +10 -0
- package/dist/config/runtime.d.ts +15 -0
- package/dist/config/runtime.js +48 -0
- package/dist/config/runtime.test.d.ts +1 -0
- package/dist/config/runtime.test.js +69 -0
- package/dist/config/test-mcp-http-config.d.ts +3 -0
- package/dist/config/test-mcp-http-config.js +7 -0
- package/dist/governance/project-pin.d.ts +14 -0
- package/dist/governance/project-pin.js +44 -0
- package/dist/governance/project-pin.test.d.ts +1 -0
- package/dist/governance/project-pin.test.js +35 -0
- package/dist/http.d.ts +1 -2
- package/dist/http.integration.test.d.ts +1 -0
- package/dist/http.integration.test.js +688 -0
- package/dist/http.js +3 -170
- package/dist/http.test.d.ts +4 -0
- package/dist/http.test.js +131 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.integration.test.js +73 -30
- package/dist/index.js +28 -27
- package/dist/index.test.js +3 -3
- package/dist/logging/structured.d.ts +27 -0
- package/dist/logging/structured.js +32 -0
- package/dist/logging/structured.test.d.ts +1 -0
- package/dist/logging/structured.test.js +33 -0
- package/dist/personas/index.d.ts +19 -0
- package/dist/personas/index.js +57 -0
- package/dist/personas/index.test.d.ts +1 -0
- package/dist/personas/index.test.js +58 -0
- package/dist/personas/organization-audit/v1/index.d.ts +8 -0
- package/dist/personas/organization-audit/v1/index.js +42 -0
- package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
- package/dist/personas/organization-audit/v1/prompts.js +111 -0
- package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
- package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
- package/dist/personas/organization-audit/v1/resources/playbook.d.ts +11 -0
- package/dist/personas/organization-audit/v1/resources/playbook.js +40 -0
- package/dist/personas/organization-audit/v1/resources/playbook.md +52 -0
- package/dist/personas/semantic-layer/v1/index.d.ts +8 -0
- package/dist/personas/semantic-layer/v1/index.js +32 -0
- package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
- package/dist/personas/semantic-layer/v1/prompts.js +107 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +12 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.js +42 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.md +153 -0
- package/dist/personas/types.d.ts +19 -0
- package/dist/personas/types.js +5 -0
- package/dist/protocol-contract.test.d.ts +1 -0
- package/dist/protocol-contract.test.js +42 -0
- package/dist/server/capabilities.d.ts +15 -0
- package/dist/server/capabilities.js +19 -0
- package/dist/server/capabilities.test.d.ts +1 -0
- package/dist/server/capabilities.test.js +39 -0
- package/dist/server/errors.test.d.ts +1 -0
- package/dist/server/errors.test.js +53 -0
- package/dist/server/request-context.d.ts +13 -0
- package/dist/server/request-context.js +2 -0
- package/dist/server/server.d.ts +4 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.test.d.ts +1 -0
- package/dist/server/server.test.js +15 -0
- package/dist/server/version.d.ts +1 -0
- package/dist/server/version.js +7 -0
- package/dist/server/version.test.d.ts +1 -0
- package/dist/server/version.test.js +9 -0
- package/dist/stdio.process.test.d.ts +1 -0
- package/dist/stdio.process.test.js +126 -0
- package/dist/tools/index.d.ts +2 -4
- package/dist/tools/index.js +4 -30
- package/dist/tools/index.test.d.ts +1 -0
- package/dist/tools/index.test.js +72 -0
- package/dist/tools/lib/api-errors.d.ts +9 -0
- package/dist/tools/lib/api-errors.js +22 -0
- package/dist/tools/lib/api-shape.d.ts +16 -0
- package/dist/tools/lib/api-shape.js +47 -0
- package/dist/tools/lib/assert-safe.d.ts +13 -0
- package/dist/tools/lib/assert-safe.js +21 -0
- package/dist/tools/lib/assert-safe.test.d.ts +4 -0
- package/dist/tools/lib/assert-safe.test.js +32 -0
- package/dist/tools/lib/concurrency.d.ts +4 -0
- package/dist/tools/lib/concurrency.js +24 -0
- package/dist/tools/lib/contracts.d.ts +34 -0
- package/dist/tools/lib/contracts.js +30 -0
- package/dist/tools/lib/redaction.d.ts +107 -0
- package/dist/tools/lib/redaction.js +299 -0
- package/dist/tools/lib/redaction.test.d.ts +4 -0
- package/dist/tools/lib/redaction.test.js +216 -0
- package/dist/tools/lib/register-org-audit.d.ts +9 -0
- package/dist/tools/lib/register-org-audit.js +20 -0
- package/dist/tools/lib/schema-fields.d.ts +9 -0
- package/dist/tools/lib/schema-fields.js +19 -0
- package/dist/tools/organization/binding.d.ts +14 -0
- package/dist/tools/organization/binding.js +31 -0
- package/dist/tools/organization/invariants.test.d.ts +4 -0
- package/dist/tools/organization/invariants.test.js +28 -0
- package/dist/tools/organization/inventory.d.ts +10 -0
- package/dist/tools/organization/inventory.js +189 -0
- package/dist/tools/organization/roles.d.ts +10 -0
- package/dist/tools/organization/roles.js +213 -0
- package/dist/tools/project/content.d.ts +9 -0
- package/dist/tools/project/content.js +192 -0
- package/dist/tools/project/projects.d.ts +7 -0
- package/dist/tools/project/projects.js +42 -0
- package/dist/tools/project/projects.test.d.ts +1 -0
- package/dist/tools/project/projects.test.js +117 -0
- package/dist/tools/project/schedulers.d.ts +7 -0
- package/dist/tools/project/schedulers.js +115 -0
- package/dist/tools/registry.d.ts +104 -0
- package/dist/tools/registry.js +59 -0
- package/dist/tools/semantic/explore-helpers.d.ts +56 -0
- package/dist/tools/semantic/explore-helpers.js +115 -0
- package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
- package/dist/tools/semantic/explore-helpers.test.js +170 -0
- package/dist/tools/semantic/explores.d.ts +9 -0
- package/dist/tools/semantic/explores.js +80 -0
- package/dist/tools/semantic/metrics.d.ts +7 -0
- package/dist/tools/semantic/metrics.js +53 -0
- package/dist/tools/semantic/query.d.ts +6 -0
- package/dist/tools/semantic/query.js +42 -0
- package/dist/tools/semantic/schema-fields.d.ts +3 -0
- package/dist/tools/semantic/schema-fields.js +7 -0
- package/dist/tools/shared.d.ts +26 -13
- package/dist/tools/shared.js +112 -157
- package/dist/tools/shared.test.js +132 -183
- package/dist/tools/space/access.d.ts +66 -0
- package/dist/tools/space/access.js +322 -0
- package/dist/tools/space/access.test.d.ts +4 -0
- package/dist/tools/space/access.test.js +90 -0
- package/dist/transports/http-body.d.ts +5 -0
- package/dist/transports/http-body.js +50 -0
- package/dist/transports/http-request-utils.d.ts +2 -0
- package/dist/transports/http-request-utils.js +13 -0
- package/dist/transports/http-response.d.ts +6 -0
- package/dist/transports/http-response.js +56 -0
- package/dist/transports/session-store.d.ts +40 -0
- package/dist/transports/session-store.js +88 -0
- package/dist/transports/session-store.test.d.ts +1 -0
- package/dist/transports/session-store.test.js +111 -0
- package/dist/transports/streamable-http.d.ts +9 -0
- package/dist/transports/streamable-http.js +454 -0
- package/dist/transports/streamable-http.test.d.ts +1 -0
- package/dist/transports/streamable-http.test.js +95 -0
- package/package.json +25 -10
- package/dist/audit.d.ts +0 -6
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -82
- package/dist/tools/ai-agents.d.ts +0 -6
- package/dist/tools/ai-agents.js +0 -388
- package/dist/tools/charts.d.ts +0 -6
- package/dist/tools/charts.js +0 -55
- package/dist/tools/content.d.ts +0 -6
- package/dist/tools/content.js +0 -37
- package/dist/tools/dashboards.d.ts +0 -6
- package/dist/tools/dashboards.js +0 -28
- package/dist/tools/explores.d.ts +0 -6
- package/dist/tools/explores.js +0 -65
- package/dist/tools/groups.d.ts +0 -6
- package/dist/tools/groups.js +0 -121
- package/dist/tools/metrics.d.ts +0 -6
- package/dist/tools/metrics.js +0 -45
- package/dist/tools/projects.d.ts +0 -6
- package/dist/tools/projects.js +0 -58
- package/dist/tools/query.d.ts +0 -6
- package/dist/tools/query.js +0 -34
- package/dist/tools/schedulers.d.ts +0 -6
- package/dist/tools/schedulers.js +0 -45
- package/dist/tools/spaces.d.ts +0 -6
- package/dist/tools/spaces.js +0 -128
- package/dist/tools/tags.d.ts +0 -6
- package/dist/tools/tags.js +0 -28
- package/dist/tools/users.d.ts +0 -6
- package/dist/tools/users.js +0 -50
- package/src/audit.ts +0 -6
- package/src/bin.ts +0 -58
- package/src/config.ts +0 -83
- package/src/errors.ts +0 -27
- package/src/http.ts +0 -187
- package/src/index.integration.test.ts +0 -57
- package/src/index.test.ts +0 -8
- package/src/index.ts +0 -31
- package/src/tools/ai-agents.ts +0 -759
- package/src/tools/charts.ts +0 -85
- package/src/tools/content.ts +0 -44
- package/src/tools/dashboards.ts +0 -25
- package/src/tools/explores.ts +0 -98
- package/src/tools/groups.ts +0 -180
- package/src/tools/index.ts +0 -35
- package/src/tools/metrics.ts +0 -42
- package/src/tools/projects.ts +0 -74
- package/src/tools/query.ts +0 -47
- package/src/tools/schedulers.ts +0 -42
- package/src/tools/shared.test.ts +0 -365
- package/src/tools/shared.ts +0 -274
- package/src/tools/spaces.ts +0 -217
- package/src/tools/tags.ts +0 -25
- package/src/tools/users.ts +0 -64
- package/tsconfig.json +0 -13
- /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
- /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
|
|
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) =>
|
|
8
|
+
vitest_1.vi.mock('@lightdash-tools/common', async (importOriginal) => {
|
|
18
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
const actual =
|
|
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
|
-
|
|
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.
|
|
39
|
-
|
|
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:
|
|
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 =
|
|
35
|
+
const result = await handler({});
|
|
54
36
|
(0, vitest_1.expect)(result.content[0].text).toBe('success');
|
|
55
|
-
})
|
|
56
|
-
(0, vitest_1.it)('
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(0,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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', () =>
|
|
84
|
-
(0,
|
|
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:
|
|
60
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
88
61
|
}, mockHandler);
|
|
89
62
|
const [, , handler] = mockServer.registerTool.mock.calls[0];
|
|
90
|
-
const result =
|
|
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
|
|
128
|
-
(0, vitest_1.it)('
|
|
129
|
-
(0,
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
(0,
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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.
|
|
189
|
-
(0,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
(0, vitest_1.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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;
|