@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
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Space access and effective-access composition tools.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildSpaceAccessRows = buildSpaceAccessRows;
|
|
7
|
+
exports.composeEffectiveAccessRecords = composeEffectiveAccessRecords;
|
|
8
|
+
exports.registerListSpaceAccess = registerListSpaceAccess;
|
|
9
|
+
exports.registerResolveEffectiveAccess = registerResolveEffectiveAccess;
|
|
10
|
+
/* eslint-disable max-params, sonarjs/cognitive-complexity, sonarjs/cyclomatic-complexity --
|
|
11
|
+
* Access composition intentionally branches on principal/resource/path variants.
|
|
12
|
+
*/
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const project_pin_js_1 = require("../../governance/project-pin.js");
|
|
15
|
+
const api_errors_js_1 = require("../lib/api-errors.js");
|
|
16
|
+
const concurrency_js_1 = require("../lib/concurrency.js");
|
|
17
|
+
const contracts_js_1 = require("../lib/contracts.js");
|
|
18
|
+
const register_org_audit_js_1 = require("../lib/register-org-audit.js");
|
|
19
|
+
const schema_fields_js_1 = require("../lib/schema-fields.js");
|
|
20
|
+
const binding_js_1 = require("../organization/binding.js");
|
|
21
|
+
const shared_js_1 = require("../shared.js");
|
|
22
|
+
const SPACE_FETCH_CONCURRENCY = 5;
|
|
23
|
+
const MAX_SPACES_PER_PROJECT = 100;
|
|
24
|
+
/** Maps space ACL payloads into audit rows; optionally drops inherited-only users. */
|
|
25
|
+
function buildSpaceAccessRows(spaceList, includeInherited = true) {
|
|
26
|
+
const data = [];
|
|
27
|
+
for (const space of spaceList) {
|
|
28
|
+
const access = Array.isArray(space.access) ? space.access : [];
|
|
29
|
+
const groupsAccess = Array.isArray(space.groupsAccess) ? space.groupsAccess : [];
|
|
30
|
+
for (const entry of access) {
|
|
31
|
+
if (!entry || typeof entry !== 'object')
|
|
32
|
+
continue;
|
|
33
|
+
const row = entry;
|
|
34
|
+
if (!includeInherited && row.hasDirectAccess === false) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
data.push({
|
|
38
|
+
spaceUuid: space.uuid,
|
|
39
|
+
spaceName: space.name,
|
|
40
|
+
principalType: 'user',
|
|
41
|
+
principalUuid: row.userUuid,
|
|
42
|
+
role: row.role,
|
|
43
|
+
hasDirectAccess: row.hasDirectAccess,
|
|
44
|
+
inheritedFrom: includeInherited ? row.inheritedFrom : undefined,
|
|
45
|
+
inheritedRole: includeInherited ? row.inheritedRole : undefined,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
for (const entry of groupsAccess) {
|
|
49
|
+
if (!entry || typeof entry !== 'object')
|
|
50
|
+
continue;
|
|
51
|
+
const row = entry;
|
|
52
|
+
data.push({
|
|
53
|
+
spaceUuid: space.uuid,
|
|
54
|
+
spaceName: space.name,
|
|
55
|
+
principalType: 'group',
|
|
56
|
+
principalUuid: row.groupUuid,
|
|
57
|
+
role: row.spaceRole,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
async function loadSpaceAccess(client, projectUuid, spaceUuid, includeInherited = true) {
|
|
64
|
+
const warnings = [];
|
|
65
|
+
const inaccessibleScopes = [];
|
|
66
|
+
let truncated = false;
|
|
67
|
+
let spaceList = [];
|
|
68
|
+
try {
|
|
69
|
+
if (spaceUuid) {
|
|
70
|
+
spaceList = [await client.v1.spaces.getSpace(projectUuid, spaceUuid)];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const summaries = await client.v1.spaces.listSpacesInProject(projectUuid);
|
|
74
|
+
if (summaries.length > MAX_SPACES_PER_PROJECT) {
|
|
75
|
+
truncated = true;
|
|
76
|
+
warnings.push({
|
|
77
|
+
code: 'TRUNCATED',
|
|
78
|
+
message: `Space detail fetch capped at ${MAX_SPACES_PER_PROJECT} of ${summaries.length} spaces`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const capped = summaries.slice(0, MAX_SPACES_PER_PROJECT);
|
|
82
|
+
spaceList = await (0, concurrency_js_1.mapWithConcurrency)(capped, SPACE_FETCH_CONCURRENCY, async (summary) => {
|
|
83
|
+
try {
|
|
84
|
+
return await client.v1.spaces.getSpace(projectUuid, summary.uuid);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (!(0, api_errors_js_1.isForbiddenOrNotFound)(err)) {
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
warnings.push({
|
|
91
|
+
code: 'PARTIAL_VISIBILITY',
|
|
92
|
+
message: `Could not load space detail for ${summary.uuid}`,
|
|
93
|
+
resourceUuid: summary.uuid,
|
|
94
|
+
});
|
|
95
|
+
inaccessibleScopes.push({
|
|
96
|
+
scopeType: 'space',
|
|
97
|
+
scopeUuid: summary.uuid,
|
|
98
|
+
reason: (0, api_errors_js_1.visibilityFailureReason)(err),
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
uuid: summary.uuid,
|
|
102
|
+
name: summary.name,
|
|
103
|
+
access: summary.userAccess ? [summary.userAccess] : [],
|
|
104
|
+
groupsAccess: [],
|
|
105
|
+
inheritParentPermissions: summary.inheritParentPermissions,
|
|
106
|
+
inheritsFromOrgOrProject: summary.inheritsFromOrgOrProject,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
if (!(0, api_errors_js_1.isForbiddenOrNotFound)(err)) {
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
warnings.push({
|
|
117
|
+
code: 'PARTIAL_VISIBILITY',
|
|
118
|
+
message: spaceUuid
|
|
119
|
+
? `Could not load space ${spaceUuid}`
|
|
120
|
+
: `Could not list spaces for project ${projectUuid}`,
|
|
121
|
+
resourceUuid: spaceUuid !== null && spaceUuid !== void 0 ? spaceUuid : projectUuid,
|
|
122
|
+
});
|
|
123
|
+
inaccessibleScopes.push({
|
|
124
|
+
scopeType: spaceUuid ? 'space' : 'project',
|
|
125
|
+
scopeUuid: spaceUuid !== null && spaceUuid !== void 0 ? spaceUuid : projectUuid,
|
|
126
|
+
reason: (0, api_errors_js_1.visibilityFailureReason)(err),
|
|
127
|
+
});
|
|
128
|
+
return { data: [], warnings, inaccessibleScopes, truncated };
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
data: buildSpaceAccessRows(spaceList, includeInherited),
|
|
132
|
+
warnings,
|
|
133
|
+
inaccessibleScopes,
|
|
134
|
+
truncated,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** Pure helper for tests: merge observed access paths into records. */
|
|
138
|
+
function composeEffectiveAccessRecords(input) {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
const byKey = new Map();
|
|
141
|
+
const upsert = (principalType, principalUuid, resourceType, resourceUuid, path, complete, warning) => {
|
|
142
|
+
const key = `${principalType}:${principalUuid}:${resourceType}:${resourceUuid}`;
|
|
143
|
+
const existing = byKey.get(key);
|
|
144
|
+
if (existing) {
|
|
145
|
+
existing.accessPaths.push(path);
|
|
146
|
+
existing.complete = existing.complete && complete;
|
|
147
|
+
if (warning)
|
|
148
|
+
existing.warnings.push(warning);
|
|
149
|
+
if (!existing.effectiveRole && path.role)
|
|
150
|
+
existing.effectiveRole = path.role;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
byKey.set(key, {
|
|
154
|
+
principalType,
|
|
155
|
+
principalUuid,
|
|
156
|
+
resourceType,
|
|
157
|
+
resourceUuid,
|
|
158
|
+
effectiveRole: path.role,
|
|
159
|
+
accessPaths: [path],
|
|
160
|
+
complete,
|
|
161
|
+
warnings: warning ? [warning] : [],
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
for (const a of input.orgAssignments) {
|
|
165
|
+
if (a.assigneeType !== 'user' && a.assigneeType !== 'group')
|
|
166
|
+
continue;
|
|
167
|
+
upsert(a.assigneeType, a.assigneeId, 'organization', 'organization', { source: 'organization_role', role: (_a = a.roleName) !== null && _a !== void 0 ? _a : a.roleId }, true);
|
|
168
|
+
}
|
|
169
|
+
for (const a of input.projectAssignments) {
|
|
170
|
+
if (a.assigneeType !== 'user' && a.assigneeType !== 'group')
|
|
171
|
+
continue;
|
|
172
|
+
upsert(a.assigneeType, a.assigneeId, 'project', input.projectUuid, {
|
|
173
|
+
source: a.assigneeType === 'group' ? 'project_group' : 'project_direct',
|
|
174
|
+
role: (_b = a.roleName) !== null && _b !== void 0 ? _b : a.roleId,
|
|
175
|
+
}, false, 'Org-wide access may also grant project access');
|
|
176
|
+
}
|
|
177
|
+
for (const d of input.directAccess) {
|
|
178
|
+
upsert('user', d.userUuid, 'project', input.projectUuid, { source: 'project_direct', role: d.role }, false, 'Direct access list is incomplete for effective access');
|
|
179
|
+
}
|
|
180
|
+
for (const s of input.spaceAccess) {
|
|
181
|
+
if (!s.principalUuid)
|
|
182
|
+
continue;
|
|
183
|
+
if (s.principalType !== 'user' && s.principalType !== 'group')
|
|
184
|
+
continue;
|
|
185
|
+
const inherited = Boolean(s.inheritedFrom) && s.hasDirectAccess === false;
|
|
186
|
+
upsert(s.principalType, s.principalUuid, 'space', s.spaceUuid, {
|
|
187
|
+
source: inherited
|
|
188
|
+
? 'space_inherited'
|
|
189
|
+
: s.principalType === 'group'
|
|
190
|
+
? 'space_group'
|
|
191
|
+
: 'space_direct',
|
|
192
|
+
role: s.role,
|
|
193
|
+
sourceUuid: s.inheritedFrom,
|
|
194
|
+
}, true);
|
|
195
|
+
}
|
|
196
|
+
return [...byKey.values()];
|
|
197
|
+
}
|
|
198
|
+
function registerListSpaceAccess(server, contextProvider) {
|
|
199
|
+
(0, register_org_audit_js_1.registerOrgAuditTool)(server, 'list_space_access', {
|
|
200
|
+
title: 'List space access',
|
|
201
|
+
description: 'List direct and inherited space access by composing space list/get responses',
|
|
202
|
+
inputSchema: {
|
|
203
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)(),
|
|
204
|
+
spaceUuid: zod_1.z.string().optional(),
|
|
205
|
+
includeInherited: zod_1.z.boolean().optional(),
|
|
206
|
+
},
|
|
207
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
208
|
+
const session = await (0, binding_js_1.resolveSessionOrganization)(c);
|
|
209
|
+
const { data, warnings, inaccessibleScopes, truncated } = await loadSpaceAccess(c, args.projectUuid, args.spaceUuid, args.includeInherited !== false);
|
|
210
|
+
const complete = warnings.length === 0 && !truncated;
|
|
211
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
212
|
+
data,
|
|
213
|
+
pagination: {
|
|
214
|
+
returned: data.length,
|
|
215
|
+
complete,
|
|
216
|
+
truncatedReason: truncated ? 'max_results' : undefined,
|
|
217
|
+
},
|
|
218
|
+
coverage: Object.assign(Object.assign({}, (0, contracts_js_1.emptyCoverage)(session.organizationUuid, (0, project_pin_js_1.getPinnedProjectUuid)())), { projectUuids: [args.projectUuid], inaccessibleScopes,
|
|
219
|
+
complete, apiResolutions: [
|
|
220
|
+
{
|
|
221
|
+
capability: 'space_access',
|
|
222
|
+
selectedVersion: 'v1',
|
|
223
|
+
method: 'GET',
|
|
224
|
+
pathTemplate: '/api/v1/projects/{projectUuid}/spaces[/{spaceUuid}]',
|
|
225
|
+
reason: 'v2_unavailable',
|
|
226
|
+
},
|
|
227
|
+
] }),
|
|
228
|
+
warnings,
|
|
229
|
+
});
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
function registerResolveEffectiveAccess(server, contextProvider) {
|
|
233
|
+
(0, register_org_audit_js_1.registerOrgAuditTool)(server, 'resolve_effective_access', {
|
|
234
|
+
title: 'Resolve effective access',
|
|
235
|
+
description: 'Deterministically compose observable org/project/space access paths (completeness flagged)',
|
|
236
|
+
inputSchema: {
|
|
237
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)().optional(),
|
|
238
|
+
spaceUuid: zod_1.z.string().optional(),
|
|
239
|
+
maxPrincipals: zod_1.z.number().int().positive().optional(),
|
|
240
|
+
},
|
|
241
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async (args) => {
|
|
242
|
+
var _a;
|
|
243
|
+
const session = await (0, binding_js_1.resolveSessionOrganization)(c);
|
|
244
|
+
const pinned = (0, project_pin_js_1.getPinnedProjectUuid)();
|
|
245
|
+
const projectUuid = pinned !== null && pinned !== void 0 ? pinned : args.projectUuid;
|
|
246
|
+
if (!projectUuid) {
|
|
247
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
248
|
+
error: 'projectUuid is required when no X-Lightdash-Project pin is set',
|
|
249
|
+
isError: true,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
const warnings = [];
|
|
253
|
+
const inaccessibleScopes = [];
|
|
254
|
+
const settle = async (label, scopeType, promise) => {
|
|
255
|
+
try {
|
|
256
|
+
return await promise;
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
if (!(0, api_errors_js_1.isForbiddenOrNotFound)(err))
|
|
260
|
+
throw err;
|
|
261
|
+
warnings.push({
|
|
262
|
+
code: 'PARTIAL_VISIBILITY',
|
|
263
|
+
message: `Could not load ${label}`,
|
|
264
|
+
resourceUuid: scopeType === 'organization' ? session.organizationUuid : projectUuid,
|
|
265
|
+
});
|
|
266
|
+
inaccessibleScopes.push({
|
|
267
|
+
scopeType,
|
|
268
|
+
scopeUuid: scopeType === 'organization' ? session.organizationUuid : projectUuid,
|
|
269
|
+
reason: (0, api_errors_js_1.visibilityFailureReason)(err),
|
|
270
|
+
});
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const [orgAssignments, projectAssignments, directAccess, spaceResult] = await Promise.all([
|
|
275
|
+
settle('organization role assignments', 'organization', c.v2.organizationRoles.listRoleAssignments(session.organizationUuid)),
|
|
276
|
+
settle('project role assignments', 'project', c.v2.projectRoleAssignments.listAssignments(projectUuid)),
|
|
277
|
+
settle('project direct access', 'project', c.v1.projectAccess.listProjectAccess(projectUuid)),
|
|
278
|
+
loadSpaceAccess(c, projectUuid, args.spaceUuid, true),
|
|
279
|
+
]);
|
|
280
|
+
inaccessibleScopes.push(...spaceResult.inaccessibleScopes);
|
|
281
|
+
let records = composeEffectiveAccessRecords({
|
|
282
|
+
orgAssignments: orgAssignments !== null && orgAssignments !== void 0 ? orgAssignments : [],
|
|
283
|
+
projectAssignments: projectAssignments !== null && projectAssignments !== void 0 ? projectAssignments : [],
|
|
284
|
+
directAccess: directAccess !== null && directAccess !== void 0 ? directAccess : [],
|
|
285
|
+
spaceAccess: spaceResult.data,
|
|
286
|
+
projectUuid,
|
|
287
|
+
});
|
|
288
|
+
const maxPrincipals = (_a = args.maxPrincipals) !== null && _a !== void 0 ? _a : 500;
|
|
289
|
+
const principalsTruncated = records.length > maxPrincipals;
|
|
290
|
+
if (principalsTruncated)
|
|
291
|
+
records = records.slice(0, maxPrincipals);
|
|
292
|
+
const truncated = principalsTruncated || spaceResult.truncated;
|
|
293
|
+
return (0, shared_js_1.jsonToolResult)({
|
|
294
|
+
data: records,
|
|
295
|
+
pagination: {
|
|
296
|
+
returned: records.length,
|
|
297
|
+
complete: false,
|
|
298
|
+
truncatedReason: truncated ? 'max_results' : undefined,
|
|
299
|
+
},
|
|
300
|
+
coverage: Object.assign(Object.assign({}, (0, contracts_js_1.emptyCoverage)(session.organizationUuid, pinned)), { projectUuids: [projectUuid], inaccessibleScopes, complete: false }),
|
|
301
|
+
warnings: [
|
|
302
|
+
{
|
|
303
|
+
code: 'INCOMPLETE_EFFECTIVE_ACCESS',
|
|
304
|
+
message: 'Effective access is best-effort from observable APIs; role precedence is not invented when paths conflict',
|
|
305
|
+
},
|
|
306
|
+
...warnings,
|
|
307
|
+
...spaceResult.warnings,
|
|
308
|
+
...(truncated
|
|
309
|
+
? [
|
|
310
|
+
{
|
|
311
|
+
code: 'TRUNCATED',
|
|
312
|
+
message: principalsTruncated
|
|
313
|
+
? `Truncated to ${maxPrincipals} principals`
|
|
314
|
+
: 'Space inventory truncated during access composition',
|
|
315
|
+
},
|
|
316
|
+
]
|
|
317
|
+
: []),
|
|
318
|
+
],
|
|
319
|
+
});
|
|
320
|
+
}));
|
|
321
|
+
}
|
|
322
|
+
/* eslint-enable max-params, sonarjs/cognitive-complexity, sonarjs/cyclomatic-complexity */
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Effective-access composition golden tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const access_js_1 = require("./access.js");
|
|
8
|
+
(0, vitest_1.describe)('buildSpaceAccessRows', () => {
|
|
9
|
+
const space = {
|
|
10
|
+
uuid: 's1',
|
|
11
|
+
name: 'Sales',
|
|
12
|
+
access: [
|
|
13
|
+
{
|
|
14
|
+
userUuid: 'u-direct',
|
|
15
|
+
role: 'editor',
|
|
16
|
+
hasDirectAccess: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
userUuid: 'u-inherited',
|
|
20
|
+
role: 'viewer',
|
|
21
|
+
hasDirectAccess: false,
|
|
22
|
+
inheritedFrom: 'parent_space',
|
|
23
|
+
inheritedRole: 'viewer',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
groupsAccess: [{ groupUuid: 'g1', spaceRole: 'viewer' }],
|
|
27
|
+
};
|
|
28
|
+
(0, vitest_1.it)('includes inherited users and provenance when includeInherited is true', () => {
|
|
29
|
+
const rows = (0, access_js_1.buildSpaceAccessRows)([space], true);
|
|
30
|
+
(0, vitest_1.expect)(rows).toHaveLength(3);
|
|
31
|
+
(0, vitest_1.expect)(rows.find((r) => r.principalUuid === 'u-inherited')).toMatchObject({
|
|
32
|
+
inheritedFrom: 'parent_space',
|
|
33
|
+
inheritedRole: 'viewer',
|
|
34
|
+
hasDirectAccess: false,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)('excludes inherited-only users when includeInherited is false', () => {
|
|
38
|
+
var _a;
|
|
39
|
+
const rows = (0, access_js_1.buildSpaceAccessRows)([space], false);
|
|
40
|
+
(0, vitest_1.expect)(rows.map((r) => r.principalUuid).sort()).toEqual(['g1', 'u-direct']);
|
|
41
|
+
(0, vitest_1.expect)((_a = rows.find((r) => r.principalUuid === 'u-direct')) === null || _a === void 0 ? void 0 : _a.inheritedFrom).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.describe)('composeEffectiveAccessRecords', () => {
|
|
45
|
+
(0, vitest_1.it)('keeps org-wide and weaker project paths without inventing precedence', () => {
|
|
46
|
+
const records = (0, access_js_1.composeEffectiveAccessRecords)({
|
|
47
|
+
orgAssignments: [{ assigneeType: 'user', assigneeId: 'u1', roleName: 'admin' }],
|
|
48
|
+
projectAssignments: [{ assigneeType: 'user', assigneeId: 'u1', roleName: 'viewer' }],
|
|
49
|
+
directAccess: [],
|
|
50
|
+
spaceAccess: [],
|
|
51
|
+
projectUuid: 'p1',
|
|
52
|
+
});
|
|
53
|
+
const project = records.find((r) => r.resourceType === 'project' && r.principalUuid === 'u1');
|
|
54
|
+
const org = records.find((r) => r.resourceType === 'organization' && r.principalUuid === 'u1');
|
|
55
|
+
(0, vitest_1.expect)(org === null || org === void 0 ? void 0 : org.accessPaths).toHaveLength(1);
|
|
56
|
+
(0, vitest_1.expect)(project === null || project === void 0 ? void 0 : project.accessPaths.some((p) => p.source === 'project_direct')).toBe(true);
|
|
57
|
+
(0, vitest_1.expect)(project === null || project === void 0 ? void 0 : project.complete).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.it)('records group-derived project access', () => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const records = (0, access_js_1.composeEffectiveAccessRecords)({
|
|
62
|
+
orgAssignments: [],
|
|
63
|
+
projectAssignments: [{ assigneeType: 'group', assigneeId: 'g1', roleName: 'editor' }],
|
|
64
|
+
directAccess: [],
|
|
65
|
+
spaceAccess: [],
|
|
66
|
+
projectUuid: 'p1',
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.expect)((_b = (_a = records[0]) === null || _a === void 0 ? void 0 : _a.accessPaths[0]) === null || _b === void 0 ? void 0 : _b.source).toBe('project_group');
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.it)('marks inherited space access', () => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const records = (0, access_js_1.composeEffectiveAccessRecords)({
|
|
73
|
+
orgAssignments: [],
|
|
74
|
+
projectAssignments: [],
|
|
75
|
+
directAccess: [],
|
|
76
|
+
spaceAccess: [
|
|
77
|
+
{
|
|
78
|
+
spaceUuid: 's1',
|
|
79
|
+
principalType: 'user',
|
|
80
|
+
principalUuid: 'u1',
|
|
81
|
+
role: 'viewer',
|
|
82
|
+
inheritedFrom: 'parent_space',
|
|
83
|
+
hasDirectAccess: false,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
projectUuid: 'p1',
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.expect)((_b = (_a = records[0]) === null || _a === void 0 ? void 0 : _a.accessPaths[0]) === null || _b === void 0 ? void 0 : _b.source).toBe('space_inherited');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
/** Discards an unread request body after an early auth rejection. */
|
|
3
|
+
export declare function drainRequestBody(req: IncomingMessage): void;
|
|
4
|
+
export declare function readBody(req: IncomingMessage, res: ServerResponse, maxBodyBytes: number): Promise<Buffer | undefined>;
|
|
5
|
+
export declare function parseJsonBody(buffer: Buffer): unknown;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.drainRequestBody = drainRequestBody;
|
|
4
|
+
exports.readBody = readBody;
|
|
5
|
+
exports.parseJsonBody = parseJsonBody;
|
|
6
|
+
const http_response_js_1 = require("./http-response.js");
|
|
7
|
+
/** Discards an unread request body after an early auth rejection. */
|
|
8
|
+
function drainRequestBody(req) {
|
|
9
|
+
req.resume();
|
|
10
|
+
req.on('data', () => undefined);
|
|
11
|
+
}
|
|
12
|
+
function readBody(req, res, maxBodyBytes) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const chunks = [];
|
|
15
|
+
let size = 0;
|
|
16
|
+
let rejected = false;
|
|
17
|
+
req.on('data', (chunk) => {
|
|
18
|
+
if (rejected)
|
|
19
|
+
return;
|
|
20
|
+
size += chunk.length;
|
|
21
|
+
if (size > maxBodyBytes) {
|
|
22
|
+
rejected = true;
|
|
23
|
+
(0, http_response_js_1.sendJson)(res, 413, { error: 'Payload Too Large' });
|
|
24
|
+
req.on('data', () => undefined);
|
|
25
|
+
if (typeof req.resume === 'function') {
|
|
26
|
+
req.resume();
|
|
27
|
+
}
|
|
28
|
+
resolve(undefined);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
chunks.push(chunk);
|
|
32
|
+
});
|
|
33
|
+
req.on('end', () => {
|
|
34
|
+
if (!rejected)
|
|
35
|
+
resolve(Buffer.concat(chunks));
|
|
36
|
+
});
|
|
37
|
+
req.on('error', reject);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function parseJsonBody(buffer) {
|
|
41
|
+
const text = buffer.toString('utf-8');
|
|
42
|
+
if (!text.trim())
|
|
43
|
+
return undefined;
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(text);
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
throw new SyntaxError('Invalid JSON body');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInitializeMessage = isInitializeMessage;
|
|
4
|
+
/** Returns true when the JSON-RPC body is an MCP initialize request. */
|
|
5
|
+
function isInitializeMessage(body) {
|
|
6
|
+
if (body === undefined)
|
|
7
|
+
return false;
|
|
8
|
+
const msg = Array.isArray(body) ? body[0] : body;
|
|
9
|
+
return (typeof msg === 'object' &&
|
|
10
|
+
msg !== null &&
|
|
11
|
+
'method' in msg &&
|
|
12
|
+
msg.method === 'initialize');
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
|
2
|
+
export declare function timingSafeEqualString(a: string, b: string): boolean;
|
|
3
|
+
export declare function checkOrigin(origin: string | undefined, allowedOrigins: string[], dangerouslyAllowAnyOrigin?: boolean): boolean;
|
|
4
|
+
export declare function buildCorsHeaders(origin: string | undefined, allowedOrigins: string[], dangerouslyAllowAnyOrigin?: boolean): Record<string, string>;
|
|
5
|
+
export declare function applyResponseHeaders(res: ServerResponse, headers: Record<string, string>): void;
|
|
6
|
+
export declare function sendJson(res: ServerResponse, status: number, body: unknown, extraHeaders?: Record<string, string>): void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timingSafeEqualString = timingSafeEqualString;
|
|
4
|
+
exports.checkOrigin = checkOrigin;
|
|
5
|
+
exports.buildCorsHeaders = buildCorsHeaders;
|
|
6
|
+
exports.applyResponseHeaders = applyResponseHeaders;
|
|
7
|
+
exports.sendJson = sendJson;
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
function timingSafeEqualString(a, b) {
|
|
10
|
+
const bufA = Buffer.from(a);
|
|
11
|
+
const bufB = Buffer.from(b);
|
|
12
|
+
if (bufA.length !== bufB.length) {
|
|
13
|
+
(0, node_crypto_1.timingSafeEqual)(bufA, bufA);
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return (0, node_crypto_1.timingSafeEqual)(bufA, bufB);
|
|
17
|
+
}
|
|
18
|
+
function checkOrigin(origin, allowedOrigins, dangerouslyAllowAnyOrigin = false) {
|
|
19
|
+
if (!origin || typeof origin !== 'string')
|
|
20
|
+
return true;
|
|
21
|
+
if (allowedOrigins.length > 0)
|
|
22
|
+
return allowedOrigins.includes(origin);
|
|
23
|
+
return dangerouslyAllowAnyOrigin;
|
|
24
|
+
}
|
|
25
|
+
const CORS_ALLOW_HEADERS = 'Content-Type, Accept, Authorization, Mcp-Session-Id, MCP-Protocol-Version, X-API-Key, X-Lightdash-Project';
|
|
26
|
+
function corsReflectHeaders(origin) {
|
|
27
|
+
return {
|
|
28
|
+
'Access-Control-Allow-Origin': origin,
|
|
29
|
+
'Access-Control-Allow-Methods': 'GET, POST, DELETE, OPTIONS',
|
|
30
|
+
'Access-Control-Allow-Headers': CORS_ALLOW_HEADERS,
|
|
31
|
+
'Access-Control-Expose-Headers': 'Mcp-Session-Id, WWW-Authenticate',
|
|
32
|
+
Vary: 'Origin',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function buildCorsHeaders(origin, allowedOrigins, dangerouslyAllowAnyOrigin = false) {
|
|
36
|
+
if (!origin)
|
|
37
|
+
return {};
|
|
38
|
+
if (allowedOrigins.length > 0) {
|
|
39
|
+
if (!allowedOrigins.includes(origin))
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
else if (!dangerouslyAllowAnyOrigin) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
return corsReflectHeaders(origin);
|
|
46
|
+
}
|
|
47
|
+
function applyResponseHeaders(res, headers) {
|
|
48
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
49
|
+
res.setHeader(key, value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function sendJson(res, status, body, extraHeaders) {
|
|
53
|
+
res
|
|
54
|
+
.writeHead(status, Object.assign({ 'Content-Type': 'application/json' }, extraHeaders))
|
|
55
|
+
.end(JSON.stringify(body));
|
|
56
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { McpAuthMode } from '../auth/auth-mode.js';
|
|
2
|
+
import type { PersonaId } from '../personas/types.js';
|
|
3
|
+
import type { McpContextProvider } from '../server/request-context.js';
|
|
4
|
+
import type { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
|
|
5
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
+
export interface SessionAuthState {
|
|
7
|
+
mode: McpAuthMode;
|
|
8
|
+
tokenHash?: string;
|
|
9
|
+
subject?: string;
|
|
10
|
+
organizationUuid?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SessionEntry {
|
|
13
|
+
transport: NodeStreamableHTTPServerTransport;
|
|
14
|
+
server: McpServer;
|
|
15
|
+
lastAccessAt: number;
|
|
16
|
+
auth: SessionAuthState;
|
|
17
|
+
contextProvider?: McpContextProvider;
|
|
18
|
+
/** Persona that owns this session (must match request path). */
|
|
19
|
+
personaId: PersonaId;
|
|
20
|
+
}
|
|
21
|
+
export declare class SessionStore {
|
|
22
|
+
private readonly sessionTtlMs;
|
|
23
|
+
private readonly maxSessions;
|
|
24
|
+
/** `0` disables the per-subject cap (unlimited per subject; global maxSessions still applies). */
|
|
25
|
+
private readonly maxSessionsPerSubject;
|
|
26
|
+
private readonly sessions;
|
|
27
|
+
private readonly subjectSessionCounts;
|
|
28
|
+
constructor(sessionTtlMs: number, maxSessions: number,
|
|
29
|
+
/** `0` disables the per-subject cap (unlimited per subject; global maxSessions still applies). */
|
|
30
|
+
maxSessionsPerSubject: number);
|
|
31
|
+
get(sessionId: string): SessionEntry | undefined;
|
|
32
|
+
set(sessionId: string, entry: SessionEntry): void;
|
|
33
|
+
delete(sessionId: string): void;
|
|
34
|
+
private decrementSubjectCount;
|
|
35
|
+
touch(sessionId: string): void;
|
|
36
|
+
cleanupExpired(onClose: (entry: SessionEntry, sessionId: string) => void): void;
|
|
37
|
+
get size(): number;
|
|
38
|
+
canAcceptNewSession(subject: string | undefined, onClose: (entry: SessionEntry, sessionId: string) => void): boolean;
|
|
39
|
+
drainAll(onClose: (entry: SessionEntry, sessionId: string) => void): void;
|
|
40
|
+
}
|