@lightdash-tools/mcp 0.8.0 → 0.9.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 +108 -237
- package/dist/audit/server-persona.d.ts +10 -0
- package/dist/audit/server-persona.js +19 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +6 -7
- package/dist/auth/oauth-broker/pending-store.js +3 -4
- package/dist/auth/oauth-broker/pending-store.test.d.ts +2 -3
- package/dist/auth/oauth-broker/pending-store.test.js +2 -39
- package/dist/auth/oauth-broker/routes.d.ts +1 -1
- package/dist/auth/oauth-broker/routes.js +3 -3
- package/dist/auth/oauth-broker/routes.test.js +1 -1
- package/dist/auth/request-state-key.d.ts +19 -0
- package/dist/auth/request-state-key.js +49 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +0 -2
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +0 -19
- package/dist/auth/resource-server/www-authenticate.test.js +0 -2
- package/dist/bin.js +9 -2
- package/dist/config/env.d.ts +5 -15
- package/dist/config/env.js +6 -16
- package/dist/config/load-mcp-config.d.ts +0 -4
- package/dist/config/load-mcp-config.js +8 -9
- package/dist/config/normalize-url.test.js +14 -11
- package/dist/config/runtime.d.ts +3 -3
- package/dist/config/runtime.js +19 -23
- package/dist/config/runtime.test.js +23 -9
- package/dist/config/test-mcp-http-config.js +1 -1
- package/dist/destructive/content-promote.js +7 -1
- package/dist/destructive/promote-contract.test.js +106 -47
- package/dist/destructive/register-destructive-tool.js +6 -24
- package/dist/destructive/request-state.d.ts +2 -6
- package/dist/destructive/request-state.js +3 -38
- package/dist/destructive/types.d.ts +2 -1
- package/dist/governance/available-projects.d.ts +37 -0
- package/dist/governance/available-projects.js +132 -0
- package/dist/governance/available-projects.test.d.ts +4 -0
- package/dist/governance/available-projects.test.js +107 -0
- package/dist/governance/client-capabilities-cache.d.ts +44 -0
- package/dist/governance/client-capabilities-cache.js +142 -0
- package/dist/governance/client-capabilities-cache.test.js +148 -0
- package/dist/governance/mcp-client-session.d.ts +3 -2
- package/dist/governance/mcp-client-session.js +3 -2
- package/dist/governance/project-scope.d.ts +8 -22
- package/dist/governance/project-scope.js +36 -44
- package/dist/governance/project-scope.test.d.ts +1 -1
- package/dist/governance/project-scope.test.js +21 -44
- package/dist/governance/promote-allowlist.d.ts +18 -0
- package/dist/governance/promote-allowlist.js +66 -0
- package/dist/governance/promote-allowlist.test.d.ts +4 -0
- package/dist/governance/promote-allowlist.test.js +87 -0
- package/dist/http.integration.test.js +117 -262
- package/dist/http.test.js +0 -12
- package/dist/index.integration.test.js +0 -4
- package/dist/index.js +3 -1
- package/dist/personas/ai-agent-ops/v1/index.d.ts +8 -0
- package/dist/personas/ai-agent-ops/v1/index.js +41 -0
- package/dist/personas/ai-agent-ops/v1/prompts.d.ts +5 -0
- package/dist/personas/ai-agent-ops/v1/prompts.js +141 -0
- package/dist/personas/ai-agent-ops/v1/prompts.test.d.ts +4 -0
- package/dist/personas/ai-agent-ops/v1/prompts.test.js +26 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks.js +41 -0
- package/dist/personas/content-developer/v1/index.d.ts +1 -1
- package/dist/personas/content-developer/v1/index.js +1 -0
- package/dist/personas/content-developer/v1/prompts.d.ts +3 -0
- package/dist/personas/content-developer/v1/prompts.js +80 -61
- package/dist/personas/content-developer/v1/prompts.test.js +159 -3
- package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
- package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +13 -6
- package/dist/personas/content-developer/v1/resources/playbooks/core.md +91 -49
- package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +82 -34
- package/dist/personas/content-developer/v1/resources/playbooks/index.md +9 -7
- package/dist/personas/content-developer/v1/resources/playbooks.d.ts +1 -1
- package/dist/personas/content-developer/v1/resources/playbooks.js +29 -10
- package/dist/personas/content-governance/v1/resources/playbooks/core.md +1 -1
- package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +1 -1
- package/dist/personas/content-reader/v1/index.d.ts +1 -1
- package/dist/personas/content-reader/v1/index.js +1 -0
- package/dist/personas/content-reader/v1/prompts.js +64 -30
- package/dist/personas/content-reader/v1/resources/playbooks/compare.md +24 -9
- package/dist/personas/content-reader/v1/resources/playbooks/core.md +56 -29
- package/dist/personas/content-reader/v1/resources/playbooks/discover.md +27 -5
- package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +38 -8
- package/dist/personas/content-reader/v1/resources/playbooks/index.md +8 -8
- package/dist/personas/content-reader/v1/resources/playbooks.js +2 -2
- package/dist/personas/index.d.ts +1 -0
- package/dist/personas/index.js +27 -22
- package/dist/personas/index.test.js +68 -53
- package/dist/personas/lib/playbook-resources.d.ts +4 -3
- package/dist/personas/lib/playbook-resources.js +14 -10
- package/dist/personas/organization-audit/v1/prompts.js +68 -36
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +12 -4
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +13 -3
- package/dist/personas/organization-audit/v1/resources/playbooks/core.md +49 -16
- package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +8 -3
- package/dist/personas/organization-audit/v1/resources/playbooks/index.md +8 -8
- package/dist/personas/organization-audit/v1/resources/playbooks.js +1 -1
- package/dist/personas/persona.parity.test.js +14 -10
- package/dist/personas/semantic-layer/v1/prompts.js +50 -39
- package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +36 -31
- package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +53 -21
- package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +42 -39
- package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +6 -6
- package/dist/personas/semantic-layer/v1/resources/playbooks.js +2 -2
- package/dist/personas/types.d.ts +1 -1
- package/dist/policy/content-developer.d.ts +3 -3
- package/dist/policy/content-developer.js +3 -3
- package/dist/policy/content-developer.test.js +10 -4
- package/dist/policy/content-reader.d.ts +5 -1
- package/dist/policy/content-reader.js +18 -3
- package/dist/policy/content-reader.test.js +2 -1
- package/dist/policy/preview-ledger-fault.test.js +101 -426
- package/dist/policy/preview-ledger.d.ts +38 -74
- package/dist/policy/preview-ledger.js +108 -186
- package/dist/policy/preview-ledger.test.js +237 -111
- package/dist/policy/result-limits.d.ts +6 -1
- package/dist/policy/result-limits.js +28 -29
- package/dist/policy/result-limits.test.js +10 -1
- package/dist/server/capabilities.js +2 -0
- package/dist/server/capabilities.test.js +2 -0
- package/dist/server/server.js +12 -8
- package/dist/server/upstream-errors.d.ts +17 -0
- package/dist/server/upstream-errors.js +60 -0
- package/dist/server/upstream-errors.test.js +50 -0
- package/dist/stdio.process.test.js +4 -2
- package/dist/tools/ai-agents/agents.d.ts +7 -0
- package/dist/tools/ai-agents/agents.js +32 -0
- package/dist/tools/ai-agents/agents.test.js +176 -0
- package/dist/tools/ai-agents/discovery.d.ts +9 -0
- package/dist/tools/ai-agents/discovery.js +73 -0
- package/dist/tools/ai-agents/evaluations.d.ts +14 -0
- package/dist/tools/ai-agents/evaluations.js +177 -0
- package/dist/tools/ai-agents/helpers.d.ts +64 -0
- package/dist/tools/ai-agents/helpers.js +323 -0
- package/dist/tools/ai-agents/threads.d.ts +7 -0
- package/dist/tools/ai-agents/threads.js +40 -0
- package/dist/tools/organization/inventory.js +2 -1
- package/dist/tools/project/content.js +5 -1
- package/dist/tools/project/developer-content-preview.d.ts +2 -1
- package/dist/tools/project/developer-content-preview.js +40 -35
- package/dist/tools/project/developer-content-shared.d.ts +8 -2
- package/dist/tools/project/developer-content-shared.js +7 -3
- package/dist/tools/project/developer-content.d.ts +7 -8
- package/dist/tools/project/developer-content.js +72 -67
- package/dist/tools/project/developer-get-chart-as-code.d.ts +9 -0
- package/dist/tools/project/developer-get-chart-as-code.js +39 -0
- package/dist/tools/project/developer-get-chart-as-code.test.d.ts +4 -0
- package/dist/tools/project/developer-get-chart-as-code.test.js +70 -0
- package/dist/tools/project/developer-helpers.d.ts +1 -1
- package/dist/tools/project/developer-helpers.js +1 -1
- package/dist/tools/project/get-dashboard-promote-diff.js +12 -2
- package/dist/tools/project/invariants.test.js +5 -3
- package/dist/tools/project/projects.js +6 -4
- package/dist/tools/project/projects.test.js +44 -5
- package/dist/tools/project/reader-export-chart-image.d.ts +6 -0
- package/dist/tools/project/reader-export-chart-image.js +78 -0
- package/dist/tools/project/reader-export-chart-image.test.d.ts +4 -0
- package/dist/tools/project/reader-export-chart-image.test.js +149 -0
- package/dist/tools/query/bounded-saved-query.js +1 -1
- package/dist/tools/query/lifecycle.d.ts +1 -1
- package/dist/tools/query/lifecycle.js +17 -25
- package/dist/tools/query/query-ledger.d.ts +15 -8
- package/dist/tools/query/query-ledger.js +21 -15
- package/dist/tools/query/query-ledger.test.js +13 -11
- package/dist/tools/query/reader-tool-helpers.js +4 -6
- package/dist/tools/query/reader-tool-helpers.test.js +8 -4
- package/dist/tools/registry.d.ts +63 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/shared.d.ts +27 -8
- package/dist/tools/shared.js +61 -28
- package/dist/tools/shared.test.js +100 -4
- package/dist/transports/streamable-http.js +48 -206
- package/dist/transports/streamable-http.test.js +10 -3
- package/package.json +5 -6
- package/dist/destructive/confirmation-claim.d.ts +0 -21
- package/dist/destructive/confirmation-claim.js +0 -87
- package/dist/destructive/confirmation-claim.test.js +0 -50
- package/dist/store/config.d.ts +0 -11
- package/dist/store/config.js +0 -50
- package/dist/store/config.test.js +0 -56
- package/dist/store/create-oauth-broker-store.d.ts +0 -6
- package/dist/store/create-oauth-broker-store.js +0 -16
- package/dist/store/create-preview-store.d.ts +0 -10
- package/dist/store/create-preview-store.js +0 -30
- package/dist/store/create-session-store.d.ts +0 -19
- package/dist/store/create-session-store.js +0 -24
- package/dist/store/in-memory-preview-store.d.ts +0 -17
- package/dist/store/in-memory-preview-store.js +0 -72
- package/dist/store/redis-client.d.ts +0 -11
- package/dist/store/redis-client.js +0 -48
- package/dist/store/redis-oauth-broker-store.d.ts +0 -42
- package/dist/store/redis-oauth-broker-store.js +0 -167
- package/dist/store/redis-oauth-broker-store.test.js +0 -80
- package/dist/store/redis-preview-store.d.ts +0 -23
- package/dist/store/redis-preview-store.js +0 -94
- package/dist/store/redis-preview-store.test.d.ts +0 -1
- package/dist/store/redis-preview-store.test.js +0 -39
- package/dist/store/redis-session-index.d.ts +0 -33
- package/dist/store/redis-session-index.js +0 -49
- package/dist/store/types.d.ts +0 -13
- package/dist/store/types.js +0 -8
- package/dist/transports/http-request-utils.d.ts +0 -2
- package/dist/transports/http-request-utils.js +0 -13
- package/dist/transports/session-store.d.ts +0 -72
- package/dist/transports/session-store.js +0 -143
- package/dist/transports/session-store.test.d.ts +0 -1
- package/dist/transports/session-store.test.js +0 -111
- /package/dist/{destructive/confirmation-claim.test.d.ts → governance/client-capabilities-cache.test.d.ts} +0 -0
- /package/dist/{store/config.test.d.ts → server/upstream-errors.test.d.ts} +0 -0
- /package/dist/{store/redis-oauth-broker-store.test.d.ts → tools/ai-agents/agents.test.d.ts} +0 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared project allowlist unit tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const common_1 = require("@lightdash-tools/common");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const available_projects_js_1 = require("./available-projects.js");
|
|
9
|
+
const UUID_A = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
|
|
10
|
+
const UUID_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
|
|
11
|
+
const UUID_C = 'cccccccc-cccc-4ccc-8ccc-cccccccccccc';
|
|
12
|
+
const UUID_A_UPPER = 'AAAAAAAA-AAAA-4AAA-8AAA-AAAAAAAAAAAA';
|
|
13
|
+
function uuidsFromPolicy(env) {
|
|
14
|
+
const policy = (0, available_projects_js_1.getAvailableProjectsPolicy)(env);
|
|
15
|
+
return policy.restricted ? [...policy.list] : [];
|
|
16
|
+
}
|
|
17
|
+
(0, vitest_1.describe)('available-projects', () => {
|
|
18
|
+
(0, vitest_1.afterEach)(() => {
|
|
19
|
+
delete process.env[common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS];
|
|
20
|
+
delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
21
|
+
delete process.env.LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS;
|
|
22
|
+
(0, available_projects_js_1.resetAvailableProjectsCache)();
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.describe)('getAvailableProjectsPolicy', () => {
|
|
25
|
+
(0, vitest_1.it)('returns unrestricted when unset', () => {
|
|
26
|
+
(0, vitest_1.expect)((0, available_projects_js_1.getAvailableProjectsPolicy)({})).toEqual({ restricted: false });
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('parses ALLOWED_PROJECT_UUIDS with lowercasing', () => {
|
|
29
|
+
(0, vitest_1.expect)(uuidsFromPolicy({
|
|
30
|
+
[common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: ` ${UUID_A_UPPER} , ${UUID_B} `,
|
|
31
|
+
})).toEqual([UUID_A, UUID_B]);
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)('rejects empty segments', () => {
|
|
34
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.getAvailableProjectsPolicy)({ [common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: ',,,' })).toThrow(/empty segments/);
|
|
35
|
+
});
|
|
36
|
+
(0, vitest_1.it)('ignores removed MCP_AVAILABLE env when reading policy (validate catches it)', () => {
|
|
37
|
+
(0, vitest_1.expect)(uuidsFromPolicy({
|
|
38
|
+
LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS: UUID_A,
|
|
39
|
+
})).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.describe)('isProjectAvailable', () => {
|
|
43
|
+
(0, vitest_1.it)('allows any UUID when unrestricted', () => {
|
|
44
|
+
(0, vitest_1.expect)((0, available_projects_js_1.isProjectAvailable)(UUID_A, {})).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('allows members case-insensitively', () => {
|
|
47
|
+
const env = { [common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: `${UUID_A},${UUID_B}` };
|
|
48
|
+
(0, vitest_1.expect)((0, available_projects_js_1.isProjectAvailable)(UUID_A_UPPER, env)).toBe(true);
|
|
49
|
+
(0, vitest_1.expect)((0, available_projects_js_1.isProjectAvailable)(UUID_C, env)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
(0, vitest_1.describe)('findUnavailableProjectUuids / filter', () => {
|
|
53
|
+
(0, vitest_1.it)('returns unavailable UUIDs', () => {
|
|
54
|
+
const env = { [common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: `${UUID_A},${UUID_B}` };
|
|
55
|
+
(0, vitest_1.expect)((0, available_projects_js_1.findUnavailableProjectUuids)([UUID_A, UUID_C], env)).toEqual([UUID_C]);
|
|
56
|
+
});
|
|
57
|
+
(0, vitest_1.it)('filters projects', () => {
|
|
58
|
+
const env = { [common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: UUID_A };
|
|
59
|
+
const projects = [
|
|
60
|
+
{ projectUuid: UUID_A, name: 'a' },
|
|
61
|
+
{ projectUuid: UUID_C, name: 'c' },
|
|
62
|
+
];
|
|
63
|
+
(0, vitest_1.expect)((0, available_projects_js_1.filterProjectsByAvailability)(projects, env)).toEqual([
|
|
64
|
+
{ projectUuid: UUID_A, name: 'a' },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
(0, vitest_1.it)('returns the same array reference when unrestricted', () => {
|
|
68
|
+
const projects = [{ projectUuid: UUID_A, name: 'a' }];
|
|
69
|
+
(0, vitest_1.expect)((0, available_projects_js_1.filterProjectsByAvailability)(projects, {})).toBe(projects);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.describe)('resolveSearchProjectUuids', () => {
|
|
73
|
+
(0, vitest_1.it)('defaults to allowlist when restricted', () => {
|
|
74
|
+
const env = { [common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: `${UUID_A},${UUID_B}` };
|
|
75
|
+
(0, vitest_1.expect)((0, available_projects_js_1.resolveSearchProjectUuids)({}, env)).toEqual([UUID_A, UUID_B]);
|
|
76
|
+
});
|
|
77
|
+
(0, vitest_1.it)('returns undefined when unrestricted', () => {
|
|
78
|
+
(0, vitest_1.expect)((0, available_projects_js_1.resolveSearchProjectUuids)({}, {})).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.describe)('validateAvailableProjectsConfig', () => {
|
|
82
|
+
(0, vitest_1.it)('accepts valid allowlist', () => {
|
|
83
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.validateAvailableProjectsConfig)({
|
|
84
|
+
[common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: `${UUID_A},${UUID_B}`,
|
|
85
|
+
})).not.toThrow();
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)('rejects invalid UUID', () => {
|
|
88
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.validateAvailableProjectsConfig)({ [common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS]: 'bad' })).toThrow(available_projects_js_1.AvailableProjectsConfigError);
|
|
89
|
+
});
|
|
90
|
+
(0, vitest_1.it)('rejects removed MCP_AVAILABLE env', () => {
|
|
91
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.validateAvailableProjectsConfig)({
|
|
92
|
+
LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS: UUID_A,
|
|
93
|
+
})).toThrow(/no longer supported/);
|
|
94
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.validateAvailableProjectsConfig)({
|
|
95
|
+
LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS: UUID_A,
|
|
96
|
+
})).toThrow(/LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS/);
|
|
97
|
+
});
|
|
98
|
+
(0, vitest_1.it)('rejects removed ALLOWED_PROJECTS env', () => {
|
|
99
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.validateAvailableProjectsConfig)({
|
|
100
|
+
LIGHTDASH_TOOLS_ALLOWED_PROJECTS: UUID_A,
|
|
101
|
+
})).toThrow(/LIGHTDASH_TOOLS_ALLOWED_PROJECTS is no longer supported/);
|
|
102
|
+
(0, vitest_1.expect)(() => (0, available_projects_js_1.validateAvailableProjectsConfig)({
|
|
103
|
+
LIGHTDASH_TOOLS_ALLOWED_PROJECTS: UUID_A,
|
|
104
|
+
})).toThrow(/LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS/);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Principal- and persona-scoped, process-local client capabilities cache (ADR-0019).
|
|
3
|
+
*
|
|
4
|
+
* Sessionless HTTP creates a fresh McpServer per POST, so initialize-declared
|
|
5
|
+
* capabilities would otherwise be lost on tools/call. Cache is best-effort
|
|
6
|
+
* same-replica (like in-memory OAuth); clients may also send per-request
|
|
7
|
+
* `_meta[CLIENT_CAPABILITIES_META_KEY]`.
|
|
8
|
+
*
|
|
9
|
+
* Anonymous principals (shared-key / none with no subject or tokenHash) never
|
|
10
|
+
* use the cache — last-writer-wins would cross clients on one process.
|
|
11
|
+
*
|
|
12
|
+
* OAuth clients are keyed by tokenHash (not subject) so concurrent MCP hosts
|
|
13
|
+
* for the same user do not overwrite each other's capabilities. Per-request
|
|
14
|
+
* `_meta[CLIENT_CAPABILITIES_META_KEY]` remains the multi-replica escape hatch.
|
|
15
|
+
*/
|
|
16
|
+
import type { ToolAuditAuthContext } from '../audit/tool-audit-context.js';
|
|
17
|
+
import type { ClientCapabilities, McpServer } from '@modelcontextprotocol/server';
|
|
18
|
+
export declare const CLIENT_CAPABILITIES_CACHE_TTL_MS: number;
|
|
19
|
+
/** Same shape as tool-audit auth; tokenHash → subject → anonymous. */
|
|
20
|
+
export type CapabilitiesPrincipal = ToolAuditAuthContext;
|
|
21
|
+
export declare function resolveCapabilitiesPrincipalKey(principal: CapabilitiesPrincipal, scope?: string): string;
|
|
22
|
+
export declare function rememberClientCapabilities(principal: CapabilitiesPrincipal, clientCapabilities: ClientCapabilities, options?: {
|
|
23
|
+
ttlMs?: number;
|
|
24
|
+
scope?: string;
|
|
25
|
+
}): void;
|
|
26
|
+
export declare function getRememberedClientCapabilities(principal: CapabilitiesPrincipal, scope?: string): ClientCapabilities | undefined;
|
|
27
|
+
export declare function resetClientCapabilitiesCacheForTests(): void;
|
|
28
|
+
/** Capabilities from initialize params or per-request `_meta` envelope. */
|
|
29
|
+
export declare function extractClientCapabilitiesFromBody(body: unknown): {
|
|
30
|
+
clientCapabilities?: ClientCapabilities;
|
|
31
|
+
fromInitialize: boolean;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Seed connection-scoped client capabilities on a fresh per-request McpServer.
|
|
35
|
+
* Mirrors SDK-internal seedClientIdentityFromEnvelope (not public on 2.0.0).
|
|
36
|
+
*/
|
|
37
|
+
export declare function seedClientCapabilitiesOntoServer(mcpServer: McpServer, clientCapabilities: ClientCapabilities | undefined): void;
|
|
38
|
+
/**
|
|
39
|
+
* Remember initialize caps, or seed the fresh server from envelope meta / cache.
|
|
40
|
+
* Call after createLightdashMcpServer, before transport.handleRequest.
|
|
41
|
+
* On initialize, only cache — the SDK seeds this connection from params.
|
|
42
|
+
* `scope` (e.g. persona.path) isolates cache entries across HTTP personas.
|
|
43
|
+
*/
|
|
44
|
+
export declare function prepareServerClientCapabilities(mcpServer: McpServer, body: unknown, principal: CapabilitiesPrincipal, scope?: string): void;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Principal- and persona-scoped, process-local client capabilities cache (ADR-0019).
|
|
4
|
+
*
|
|
5
|
+
* Sessionless HTTP creates a fresh McpServer per POST, so initialize-declared
|
|
6
|
+
* capabilities would otherwise be lost on tools/call. Cache is best-effort
|
|
7
|
+
* same-replica (like in-memory OAuth); clients may also send per-request
|
|
8
|
+
* `_meta[CLIENT_CAPABILITIES_META_KEY]`.
|
|
9
|
+
*
|
|
10
|
+
* Anonymous principals (shared-key / none with no subject or tokenHash) never
|
|
11
|
+
* use the cache — last-writer-wins would cross clients on one process.
|
|
12
|
+
*
|
|
13
|
+
* OAuth clients are keyed by tokenHash (not subject) so concurrent MCP hosts
|
|
14
|
+
* for the same user do not overwrite each other's capabilities. Per-request
|
|
15
|
+
* `_meta[CLIENT_CAPABILITIES_META_KEY]` remains the multi-replica escape hatch.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CLIENT_CAPABILITIES_CACHE_TTL_MS = void 0;
|
|
19
|
+
exports.resolveCapabilitiesPrincipalKey = resolveCapabilitiesPrincipalKey;
|
|
20
|
+
exports.rememberClientCapabilities = rememberClientCapabilities;
|
|
21
|
+
exports.getRememberedClientCapabilities = getRememberedClientCapabilities;
|
|
22
|
+
exports.resetClientCapabilitiesCacheForTests = resetClientCapabilitiesCacheForTests;
|
|
23
|
+
exports.extractClientCapabilitiesFromBody = extractClientCapabilitiesFromBody;
|
|
24
|
+
exports.seedClientCapabilitiesOntoServer = seedClientCapabilitiesOntoServer;
|
|
25
|
+
exports.prepareServerClientCapabilities = prepareServerClientCapabilities;
|
|
26
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
27
|
+
exports.CLIENT_CAPABILITIES_CACHE_TTL_MS = 30 * 60000;
|
|
28
|
+
const ANONYMOUS_PRINCIPAL = 'anonymous';
|
|
29
|
+
const cache = new Map();
|
|
30
|
+
function resolveCapabilitiesPrincipalKey(principal, scope) {
|
|
31
|
+
let key;
|
|
32
|
+
if (typeof principal.tokenHash === 'string' && principal.tokenHash.length > 0) {
|
|
33
|
+
key = `token:${principal.tokenHash}`;
|
|
34
|
+
}
|
|
35
|
+
else if (typeof principal.subject === 'string' && principal.subject.length > 0) {
|
|
36
|
+
key = `subject:${principal.subject}`;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
key = ANONYMOUS_PRINCIPAL;
|
|
40
|
+
}
|
|
41
|
+
if (typeof scope === 'string' && scope.length > 0) {
|
|
42
|
+
return `${key}@${scope}`;
|
|
43
|
+
}
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
46
|
+
function hasCapabilitiesPrincipal(principal) {
|
|
47
|
+
return ((typeof principal.tokenHash === 'string' && principal.tokenHash.length > 0) ||
|
|
48
|
+
(typeof principal.subject === 'string' && principal.subject.length > 0));
|
|
49
|
+
}
|
|
50
|
+
function rememberClientCapabilities(principal, clientCapabilities, options) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (!hasCapabilitiesPrincipal(principal)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const key = resolveCapabilitiesPrincipalKey(principal, options === null || options === void 0 ? void 0 : options.scope);
|
|
56
|
+
const ttlMs = (_a = options === null || options === void 0 ? void 0 : options.ttlMs) !== null && _a !== void 0 ? _a : exports.CLIENT_CAPABILITIES_CACHE_TTL_MS;
|
|
57
|
+
cache.set(key, {
|
|
58
|
+
clientCapabilities,
|
|
59
|
+
expiresAt: Date.now() + ttlMs,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function getRememberedClientCapabilities(principal, scope) {
|
|
63
|
+
if (!hasCapabilitiesPrincipal(principal)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const key = resolveCapabilitiesPrincipalKey(principal, scope);
|
|
67
|
+
const entry = cache.get(key);
|
|
68
|
+
if (!entry) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
if (entry.expiresAt < Date.now()) {
|
|
72
|
+
cache.delete(key);
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return entry.clientCapabilities;
|
|
76
|
+
}
|
|
77
|
+
function resetClientCapabilitiesCacheForTests() {
|
|
78
|
+
cache.clear();
|
|
79
|
+
}
|
|
80
|
+
function asSingleJsonRpcRequest(body) {
|
|
81
|
+
// Streamable HTTP does not support JSON-RPC batches; ignore arrays here.
|
|
82
|
+
if (body === undefined || body === null || Array.isArray(body)) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (typeof body !== 'object') {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return body;
|
|
89
|
+
}
|
|
90
|
+
/** Capabilities from initialize params or per-request `_meta` envelope. */
|
|
91
|
+
function extractClientCapabilitiesFromBody(body) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
const msg = asSingleJsonRpcRequest(body);
|
|
94
|
+
if (!msg) {
|
|
95
|
+
return { fromInitialize: false };
|
|
96
|
+
}
|
|
97
|
+
if (msg.method === 'initialize') {
|
|
98
|
+
const caps = (_a = msg.params) === null || _a === void 0 ? void 0 : _a.capabilities;
|
|
99
|
+
return caps !== undefined
|
|
100
|
+
? { clientCapabilities: caps, fromInitialize: true }
|
|
101
|
+
: { fromInitialize: true };
|
|
102
|
+
}
|
|
103
|
+
const meta = (_b = msg.params) === null || _b === void 0 ? void 0 : _b._meta;
|
|
104
|
+
if (meta !== undefined && typeof meta === 'object') {
|
|
105
|
+
const fromMeta = Reflect.get(meta, server_1.CLIENT_CAPABILITIES_META_KEY);
|
|
106
|
+
if (fromMeta !== undefined) {
|
|
107
|
+
return { clientCapabilities: fromMeta, fromInitialize: false };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { fromInitialize: false };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Seed connection-scoped client capabilities on a fresh per-request McpServer.
|
|
114
|
+
* Mirrors SDK-internal seedClientIdentityFromEnvelope (not public on 2.0.0).
|
|
115
|
+
*/
|
|
116
|
+
function seedClientCapabilitiesOntoServer(mcpServer, clientCapabilities) {
|
|
117
|
+
if (clientCapabilities === undefined) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// SDK Server stores initialize-scoped identity privately; 2025-era elicitation
|
|
121
|
+
// shim reads `_clientCapabilities` via getClientCapabilities().
|
|
122
|
+
const lowLevel = mcpServer.server;
|
|
123
|
+
lowLevel._clientCapabilities = clientCapabilities;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Remember initialize caps, or seed the fresh server from envelope meta / cache.
|
|
127
|
+
* Call after createLightdashMcpServer, before transport.handleRequest.
|
|
128
|
+
* On initialize, only cache — the SDK seeds this connection from params.
|
|
129
|
+
* `scope` (e.g. persona.path) isolates cache entries across HTTP personas.
|
|
130
|
+
*/
|
|
131
|
+
function prepareServerClientCapabilities(mcpServer, body, principal, scope) {
|
|
132
|
+
var _a;
|
|
133
|
+
const extracted = extractClientCapabilitiesFromBody(body);
|
|
134
|
+
if (extracted.fromInitialize) {
|
|
135
|
+
if (extracted.clientCapabilities !== undefined) {
|
|
136
|
+
rememberClientCapabilities(principal, extracted.clientCapabilities, { scope });
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const caps = (_a = extracted.clientCapabilities) !== null && _a !== void 0 ? _a : getRememberedClientCapabilities(principal, scope);
|
|
141
|
+
seedClientCapabilitiesOntoServer(mcpServer, caps);
|
|
142
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const client_capabilities_cache_js_1 = require("./client-capabilities-cache.js");
|
|
6
|
+
(0, vitest_1.describe)('client-capabilities-cache', () => {
|
|
7
|
+
(0, vitest_1.beforeEach)(() => {
|
|
8
|
+
(0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.it)('resolves principal key preferring tokenHash then subject', () => {
|
|
11
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ subject: 'u1', tokenHash: 't1' })).toBe('token:t1');
|
|
12
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ tokenHash: 't1' })).toBe('token:t1');
|
|
13
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ subject: 'u1' })).toBe('subject:u1');
|
|
14
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({})).toBe('anonymous');
|
|
15
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.resolveCapabilitiesPrincipalKey)({ subject: 'u1' }, '/content-governance/v1/mcp')).toBe('subject:u1@/content-governance/v1/mcp');
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('isolates cache entries for same subject with different tokenHash', () => {
|
|
18
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1', tokenHash: 'token-a' }, { elicitation: { form: {} } });
|
|
19
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1', tokenHash: 'token-b' }, { roots: {} });
|
|
20
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1', tokenHash: 'token-a' })).toEqual({
|
|
21
|
+
elicitation: { form: {} },
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1', tokenHash: 'token-b' })).toEqual({
|
|
24
|
+
roots: {},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
(0, vitest_1.it)('skips cache for anonymous principals to avoid cross-client collision', () => {
|
|
28
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({}, { elicitation: { form: {} } });
|
|
29
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({})).toBeUndefined();
|
|
30
|
+
const server = new server_1.McpServer({ name: 't', version: '0.0.0' });
|
|
31
|
+
(0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, {
|
|
32
|
+
jsonrpc: '2.0',
|
|
33
|
+
method: 'initialize',
|
|
34
|
+
params: { capabilities: { elicitation: { form: {} } } },
|
|
35
|
+
id: 1,
|
|
36
|
+
}, {});
|
|
37
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({})).toBeUndefined();
|
|
38
|
+
(0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, {
|
|
39
|
+
jsonrpc: '2.0',
|
|
40
|
+
method: 'tools/call',
|
|
41
|
+
params: { name: 'x', arguments: {} },
|
|
42
|
+
id: 2,
|
|
43
|
+
}, {});
|
|
44
|
+
(0, vitest_1.expect)(readSeededClientCapabilities(server)).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('isolates cache entries by persona scope', () => {
|
|
47
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } }, { scope: '/content-governance/v1/mcp' });
|
|
48
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' }, '/semantic-layer/v1/mcp')).toBeUndefined();
|
|
49
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' }, '/content-governance/v1/mcp')).toEqual({ elicitation: { form: {} } });
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.it)('remembers and returns capabilities until TTL expires', () => {
|
|
52
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } }, { ttlMs: 60000 });
|
|
53
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' })).toEqual({
|
|
54
|
+
elicitation: { form: {} },
|
|
55
|
+
});
|
|
56
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } }, { ttlMs: -1 });
|
|
57
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' })).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.it)('overwrites capabilities on re-initialize for the same principal', () => {
|
|
60
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { roots: {} });
|
|
61
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { elicitation: { form: {} } });
|
|
62
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'u1' })).toEqual({
|
|
63
|
+
elicitation: { form: {} },
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
(0, vitest_1.it)('extracts capabilities from initialize and from _meta', () => {
|
|
67
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.extractClientCapabilitiesFromBody)({
|
|
68
|
+
jsonrpc: '2.0',
|
|
69
|
+
method: 'initialize',
|
|
70
|
+
params: {
|
|
71
|
+
capabilities: { elicitation: { form: {} } },
|
|
72
|
+
clientInfo: { name: 't', version: '1' },
|
|
73
|
+
},
|
|
74
|
+
id: 1,
|
|
75
|
+
})).toEqual({
|
|
76
|
+
fromInitialize: true,
|
|
77
|
+
clientCapabilities: { elicitation: { form: {} } },
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.extractClientCapabilitiesFromBody)({
|
|
80
|
+
jsonrpc: '2.0',
|
|
81
|
+
method: 'tools/call',
|
|
82
|
+
params: {
|
|
83
|
+
name: 'x',
|
|
84
|
+
arguments: {},
|
|
85
|
+
_meta: { [server_1.CLIENT_CAPABILITIES_META_KEY]: { elicitation: { form: {} } } },
|
|
86
|
+
},
|
|
87
|
+
id: 2,
|
|
88
|
+
})).toEqual({
|
|
89
|
+
fromInitialize: false,
|
|
90
|
+
clientCapabilities: { elicitation: { form: {} } },
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.extractClientCapabilitiesFromBody)([{ method: 'initialize' }])).toEqual({
|
|
93
|
+
fromInitialize: false,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.it)('seeds Server getClientCapabilities for elicitation shim', () => {
|
|
97
|
+
const server = new server_1.McpServer({ name: 'test', version: '0.0.0' });
|
|
98
|
+
(0, vitest_1.expect)(readSeededClientCapabilities(server)).toBeUndefined();
|
|
99
|
+
(0, client_capabilities_cache_js_1.seedClientCapabilitiesOntoServer)(server, { elicitation: { form: {} } });
|
|
100
|
+
(0, vitest_1.expect)(readSeededClientCapabilities(server)).toEqual({ elicitation: { form: {} } });
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.it)('prepare remembers initialize then seeds a fresh server from cache', () => {
|
|
103
|
+
const scope = '/content-governance/v1/mcp';
|
|
104
|
+
const first = new server_1.McpServer({ name: 'a', version: '0.0.0' });
|
|
105
|
+
(0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(first, {
|
|
106
|
+
jsonrpc: '2.0',
|
|
107
|
+
method: 'initialize',
|
|
108
|
+
params: {
|
|
109
|
+
protocolVersion: '2024-11-05',
|
|
110
|
+
capabilities: { elicitation: { form: {} } },
|
|
111
|
+
clientInfo: { name: 'c', version: '1' },
|
|
112
|
+
},
|
|
113
|
+
id: 1,
|
|
114
|
+
}, { subject: 'user-a' }, scope);
|
|
115
|
+
// Initialize path only remembers; SDK seeds this connection from params.
|
|
116
|
+
(0, vitest_1.expect)(readSeededClientCapabilities(first)).toBeUndefined();
|
|
117
|
+
(0, vitest_1.expect)((0, client_capabilities_cache_js_1.getRememberedClientCapabilities)({ subject: 'user-a' }, scope)).toEqual({
|
|
118
|
+
elicitation: { form: {} },
|
|
119
|
+
});
|
|
120
|
+
const second = new server_1.McpServer({ name: 'b', version: '0.0.0' });
|
|
121
|
+
(0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(second, {
|
|
122
|
+
jsonrpc: '2.0',
|
|
123
|
+
method: 'tools/call',
|
|
124
|
+
params: { name: 'lightdash_delete_chart', arguments: {} },
|
|
125
|
+
id: 2,
|
|
126
|
+
}, { subject: 'user-a' }, scope);
|
|
127
|
+
(0, vitest_1.expect)(readSeededClientCapabilities(second)).toEqual({ elicitation: { form: {} } });
|
|
128
|
+
});
|
|
129
|
+
(0, vitest_1.it)('prepare prefers per-request _meta over cache', () => {
|
|
130
|
+
(0, client_capabilities_cache_js_1.rememberClientCapabilities)({ subject: 'u1' }, { roots: {} });
|
|
131
|
+
const server = new server_1.McpServer({ name: 't', version: '0.0.0' });
|
|
132
|
+
(0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, {
|
|
133
|
+
jsonrpc: '2.0',
|
|
134
|
+
method: 'tools/call',
|
|
135
|
+
params: {
|
|
136
|
+
name: 'x',
|
|
137
|
+
arguments: {},
|
|
138
|
+
_meta: { [server_1.CLIENT_CAPABILITIES_META_KEY]: { elicitation: { form: {} } } },
|
|
139
|
+
},
|
|
140
|
+
id: 1,
|
|
141
|
+
}, { subject: 'u1' });
|
|
142
|
+
(0, vitest_1.expect)(readSeededClientCapabilities(server)).toEqual({ elicitation: { form: {} } });
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
/** Read seeded identity without calling deprecated getClientCapabilities(). */
|
|
146
|
+
function readSeededClientCapabilities(mcpServer) {
|
|
147
|
+
return mcpServer.server._clientCapabilities;
|
|
148
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP client session identity for content-reader ledger
|
|
3
|
-
*
|
|
2
|
+
* MCP client session identity for content-reader budget/ledger bookkeeping.
|
|
3
|
+
* Prefer auth subject for concurrency budgets (ADR-0019). `extra.sessionId` is used when
|
|
4
|
+
* present; otherwise fall back to a process-scoped id (stdio / sessionless HTTP).
|
|
4
5
|
*/
|
|
5
6
|
/** Resolve a per-client session id from MCP tool `extra`, or process-scoped stdio fallback. */
|
|
6
7
|
export declare function resolveMcpClientSessionId(extra?: unknown): string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* MCP client session identity for content-reader ledger
|
|
4
|
-
*
|
|
3
|
+
* MCP client session identity for content-reader budget/ledger bookkeeping.
|
|
4
|
+
* Prefer auth subject for concurrency budgets (ADR-0019). `extra.sessionId` is used when
|
|
5
|
+
* present; otherwise fall back to a process-scoped id (stdio / sessionless HTTP).
|
|
5
6
|
*/
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
8
|
exports.resolveMcpClientSessionId = resolveMcpClientSessionId;
|
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Project scope resolution (ADR-
|
|
2
|
+
* Project scope resolution (ADR-0008 / ADR-0012).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Pin-or-argument mode (content-governance):
|
|
8
|
-
* HTTP pin → tool arg → PROJECT_SCOPE_REQUIRED (ignores LIGHTDASH_TOOLS_PROJECT_UUID).
|
|
9
|
-
*
|
|
10
|
-
* Tool args cannot override pin or (in full mode) configured project.
|
|
4
|
+
* Precedence: X-Lightdash-Project pin → tool projectUuid → PROJECT_SCOPE_REQUIRED.
|
|
5
|
+
* When LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS is set, the resolved UUID must be a member.
|
|
11
6
|
*/
|
|
12
|
-
export
|
|
13
|
-
export type ProjectScopeErrorCode = 'PROJECT_SCOPE_MISMATCH' | 'PROJECT_SCOPE_REQUIRED';
|
|
7
|
+
export type ProjectScopeErrorCode = 'PROJECT_NOT_AVAILABLE' | 'PROJECT_SCOPE_MISMATCH' | 'PROJECT_SCOPE_REQUIRED';
|
|
14
8
|
export declare class ProjectScopeError extends Error {
|
|
15
9
|
readonly code: ProjectScopeErrorCode;
|
|
16
10
|
constructor(code: ProjectScopeErrorCode, message: string);
|
|
17
11
|
}
|
|
18
12
|
export type ResolvedProjectScope = {
|
|
19
13
|
projectUuid: string;
|
|
20
|
-
source: 'argument' | '
|
|
14
|
+
source: 'argument' | 'pin';
|
|
21
15
|
projectPinned: boolean;
|
|
22
16
|
};
|
|
23
|
-
/** Read and validate configured project UUID from env (empty → undefined). */
|
|
24
|
-
export declare function getConfiguredProjectUuid(env?: NodeJS.ProcessEnv): string | undefined;
|
|
25
|
-
export type ResolveProjectScopeOptions = {
|
|
26
|
-
/**
|
|
27
|
-
* When false, skip `LIGHTDASH_TOOLS_PROJECT_UUID` (content-governance).
|
|
28
|
-
* Default true for content-reader / content-developer.
|
|
29
|
-
*/
|
|
30
|
-
allowConfiguredEnv?: boolean;
|
|
31
|
-
};
|
|
32
17
|
/**
|
|
33
18
|
* Resolve exactly one project for scoped MCP tools.
|
|
34
|
-
*
|
|
19
|
+
* Pin wins; otherwise an explicit tool arg is required.
|
|
20
|
+
* When the shared allowlist is set, the resolved UUID must be a member.
|
|
35
21
|
*/
|
|
36
22
|
export declare function resolveProjectScope(input?: {
|
|
37
23
|
projectUuid?: string;
|
|
38
|
-
}
|
|
24
|
+
}): ResolvedProjectScope;
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Project scope resolution (ADR-
|
|
3
|
+
* Project scope resolution (ADR-0008 / ADR-0012).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Pin-or-argument mode (content-governance):
|
|
9
|
-
* HTTP pin → tool arg → PROJECT_SCOPE_REQUIRED (ignores LIGHTDASH_TOOLS_PROJECT_UUID).
|
|
10
|
-
*
|
|
11
|
-
* Tool args cannot override pin or (in full mode) configured project.
|
|
5
|
+
* Precedence: X-Lightdash-Project pin → tool projectUuid → PROJECT_SCOPE_REQUIRED.
|
|
6
|
+
* When LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS is set, the resolved UUID must be a member.
|
|
12
7
|
*/
|
|
13
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ProjectScopeError =
|
|
15
|
-
exports.getConfiguredProjectUuid = getConfiguredProjectUuid;
|
|
9
|
+
exports.ProjectScopeError = void 0;
|
|
16
10
|
exports.resolveProjectScope = resolveProjectScope;
|
|
17
11
|
const common_1 = require("@lightdash-tools/common");
|
|
12
|
+
const available_projects_js_1 = require("./available-projects.js");
|
|
18
13
|
const project_pin_js_1 = require("./project-pin.js");
|
|
19
|
-
exports.ENV_PROJECT_UUID = 'LIGHTDASH_TOOLS_PROJECT_UUID';
|
|
20
14
|
class ProjectScopeError extends Error {
|
|
21
15
|
constructor(code, message) {
|
|
22
16
|
super(message);
|
|
@@ -25,55 +19,53 @@ class ProjectScopeError extends Error {
|
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
exports.ProjectScopeError = ProjectScopeError;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (raw === undefined || raw.trim() === '') {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
return (0, common_1.validateUuid)(raw.trim());
|
|
36
|
-
}
|
|
37
|
-
catch (_a) {
|
|
38
|
-
throw new ProjectScopeError('PROJECT_SCOPE_REQUIRED', `${exports.ENV_PROJECT_UUID} must be a valid UUID when set`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function assertArgMatchesBound(explicit, bound, label) {
|
|
42
|
-
if (explicit && explicit !== bound) {
|
|
43
|
-
throw new ProjectScopeError('PROJECT_SCOPE_MISMATCH', `projectUuid '${explicit}' conflicts with ${label} project '${bound}'`);
|
|
22
|
+
function assertArgMatchesPin(explicit, pinned) {
|
|
23
|
+
if (explicit && explicit.toLowerCase() !== pinned.toLowerCase()) {
|
|
24
|
+
throw new ProjectScopeError('PROJECT_SCOPE_MISMATCH', `projectUuid '${explicit}' conflicts with pinned project '${pinned}'`);
|
|
44
25
|
}
|
|
45
26
|
}
|
|
46
27
|
function resolveExplicitArgument(explicit) {
|
|
47
28
|
try {
|
|
48
|
-
|
|
29
|
+
return {
|
|
30
|
+
projectUuid: (0, common_1.validateUuid)(explicit).toLowerCase(),
|
|
31
|
+
source: 'argument',
|
|
32
|
+
projectPinned: false,
|
|
33
|
+
};
|
|
49
34
|
}
|
|
50
35
|
catch (_a) {
|
|
51
36
|
throw new ProjectScopeError('PROJECT_SCOPE_REQUIRED', `projectUuid '${explicit}' is not a valid UUID`);
|
|
52
37
|
}
|
|
53
|
-
|
|
38
|
+
}
|
|
39
|
+
function assertAvailable(projectUuid) {
|
|
40
|
+
if (!(0, available_projects_js_1.isProjectAvailable)(projectUuid)) {
|
|
41
|
+
throw new ProjectScopeError('PROJECT_NOT_AVAILABLE', `projectUuid '${projectUuid}' is not in ${common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS}`);
|
|
42
|
+
}
|
|
54
43
|
}
|
|
55
44
|
/**
|
|
56
45
|
* Resolve exactly one project for scoped MCP tools.
|
|
57
|
-
*
|
|
46
|
+
* Pin wins; otherwise an explicit tool arg is required.
|
|
47
|
+
* When the shared allowlist is set, the resolved UUID must be a member.
|
|
58
48
|
*/
|
|
59
|
-
function resolveProjectScope(input
|
|
49
|
+
function resolveProjectScope(input) {
|
|
60
50
|
var _a;
|
|
61
|
-
const allowConfiguredEnv = (options === null || options === void 0 ? void 0 : options.allowConfiguredEnv) !== false;
|
|
62
51
|
const pinned = (0, project_pin_js_1.getPinnedProjectUuid)();
|
|
63
|
-
const
|
|
64
|
-
const explicit =
|
|
52
|
+
const trimmed = (_a = input === null || input === void 0 ? void 0 : input.projectUuid) === null || _a === void 0 ? void 0 : _a.trim();
|
|
53
|
+
const explicit = trimmed ? trimmed : undefined;
|
|
54
|
+
let resolved;
|
|
65
55
|
if (pinned) {
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
assertArgMatchesPin(explicit, pinned);
|
|
57
|
+
resolved = {
|
|
58
|
+
projectUuid: pinned.toLowerCase(),
|
|
59
|
+
source: 'pin',
|
|
60
|
+
projectPinned: true,
|
|
61
|
+
};
|
|
68
62
|
}
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
return { projectUuid: configured, source: 'configured', projectPinned: false };
|
|
63
|
+
else if (explicit) {
|
|
64
|
+
resolved = resolveExplicitArgument(explicit);
|
|
72
65
|
}
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
else {
|
|
67
|
+
throw new ProjectScopeError('PROJECT_SCOPE_REQUIRED', 'No project resolved. Set X-Lightdash-Project or pass projectUuid.');
|
|
75
68
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
: 'No project resolved. Set X-Lightdash-Project or pass projectUuid.');
|
|
69
|
+
assertAvailable(resolved.projectUuid);
|
|
70
|
+
return resolved;
|
|
79
71
|
}
|