@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
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStreamableHttpServer = createStreamableHttpServer;
|
|
4
4
|
exports.startStreamableHttpServer = startStreamableHttpServer;
|
|
5
|
-
const node_crypto_1 = require("node:crypto");
|
|
6
5
|
const node_http_1 = require("node:http");
|
|
7
6
|
const node_1 = require("@modelcontextprotocol/node");
|
|
8
7
|
const audit_js_1 = require("../audit/audit.js");
|
|
@@ -11,22 +10,20 @@ const auth_mode_js_1 = require("../auth/auth-mode.js");
|
|
|
11
10
|
const routes_js_1 = require("../auth/oauth-broker/routes.js");
|
|
12
11
|
const bearer_context_provider_js_1 = require("../auth/providers/bearer-context-provider.js");
|
|
13
12
|
const env_context_provider_js_1 = require("../auth/providers/env-context-provider.js");
|
|
13
|
+
const request_state_key_js_1 = require("../auth/request-state-key.js");
|
|
14
14
|
const lightdash_oauth_middleware_js_1 = require("../auth/resource-server/lightdash-oauth-middleware.js");
|
|
15
15
|
const oauth_protected_resource_js_1 = require("../auth/resource-server/oauth-protected-resource.js");
|
|
16
16
|
const shared_key_middleware_js_1 = require("../auth/resource-server/shared-key-middleware.js");
|
|
17
17
|
const token_hash_js_1 = require("../auth/token-hash.js");
|
|
18
18
|
const load_mcp_config_js_1 = require("../config/load-mcp-config.js");
|
|
19
19
|
const runtime_js_1 = require("../config/runtime.js");
|
|
20
|
+
const available_projects_js_1 = require("../governance/available-projects.js");
|
|
21
|
+
const client_capabilities_cache_js_1 = require("../governance/client-capabilities-cache.js");
|
|
20
22
|
const project_pin_js_1 = require("../governance/project-pin.js");
|
|
21
23
|
const index_js_1 = require("../personas/index.js");
|
|
22
24
|
const server_js_1 = require("../server/server.js");
|
|
23
|
-
const config_js_1 = require("../store/config.js");
|
|
24
|
-
const create_oauth_broker_store_js_1 = require("../store/create-oauth-broker-store.js");
|
|
25
|
-
const create_session_store_js_1 = require("../store/create-session-store.js");
|
|
26
25
|
const http_body_js_1 = require("./http-body.js");
|
|
27
|
-
const http_request_utils_js_1 = require("./http-request-utils.js");
|
|
28
26
|
const http_response_js_1 = require("./http-response.js");
|
|
29
|
-
const ERROR_SESSION_NOT_FOUND = 'Session not found';
|
|
30
27
|
function listen(server, port, host) {
|
|
31
28
|
return new Promise((resolve, reject) => {
|
|
32
29
|
server.once('error', reject);
|
|
@@ -59,55 +56,12 @@ function resolveHttpConfig(config, listenPort) {
|
|
|
59
56
|
const listenHost = resolveListenHost(config.host);
|
|
60
57
|
return Object.assign(Object.assign({}, config), { publicUrl: resolvePublicUrl(config.publicUrl, listenHost, listenPort) });
|
|
61
58
|
}
|
|
62
|
-
function getSessionId(req) {
|
|
63
|
-
const sessionId = req.headers['mcp-session-id'];
|
|
64
|
-
return typeof sessionId === 'string' ? sessionId : sessionId === null || sessionId === void 0 ? void 0 : sessionId[0];
|
|
65
|
-
}
|
|
66
59
|
function createEnvContextProvider(config) {
|
|
67
60
|
return new env_context_provider_js_1.EnvContextProvider({
|
|
68
61
|
mode: config.authMode === auth_mode_js_1.MCP_AUTH_MODE_SHARED_KEY ? auth_mode_js_1.MCP_AUTH_MODE_SHARED_KEY : auth_mode_js_1.MCP_AUTH_MODE_NONE,
|
|
69
62
|
client: (0, runtime_js_1.getClient)(),
|
|
70
63
|
});
|
|
71
64
|
}
|
|
72
|
-
function closeSessionEntry(entry, sessionId, reason) {
|
|
73
|
-
void Promise.all([entry.transport.close(), entry.server.close()]).catch((err) => {
|
|
74
|
-
console.error(`Failed to close MCP session ${sessionId} (${reason}):`, err);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function createSessionTransport(contextProvider, sessionStore, auth, persona) {
|
|
78
|
-
const holder = {
|
|
79
|
-
server: (0, server_js_1.createLightdashMcpServer)(contextProvider, { persona }),
|
|
80
|
-
};
|
|
81
|
-
const transport = new node_1.NodeStreamableHTTPServerTransport({
|
|
82
|
-
sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(),
|
|
83
|
-
onsessioninitialized: (sessionId) => {
|
|
84
|
-
sessionStore.set(sessionId, {
|
|
85
|
-
transport,
|
|
86
|
-
server: holder.server,
|
|
87
|
-
lastAccessAt: Date.now(),
|
|
88
|
-
auth: {
|
|
89
|
-
mode: auth.mode,
|
|
90
|
-
tokenHash: auth.tokenHash,
|
|
91
|
-
subject: auth.subject,
|
|
92
|
-
organizationUuid: auth.organizationUuid,
|
|
93
|
-
},
|
|
94
|
-
contextProvider,
|
|
95
|
-
personaId: persona.id,
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
onsessionclosed: (sessionId) => {
|
|
99
|
-
const entry = sessionStore.get(sessionId);
|
|
100
|
-
sessionStore.delete(sessionId);
|
|
101
|
-
if (entry) {
|
|
102
|
-
closeSessionEntry(entry, sessionId, 'closed');
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
holder.server.connect(transport).catch((err) => {
|
|
107
|
-
console.error('MCP server connect error:', err);
|
|
108
|
-
});
|
|
109
|
-
return transport;
|
|
110
|
-
}
|
|
111
65
|
function handleHealth(path, res, config) {
|
|
112
66
|
if (path === '/health/live') {
|
|
113
67
|
(0, http_response_js_1.sendJson)(res, 200, { status: 'ok' });
|
|
@@ -157,103 +111,33 @@ function getOAuthAuditContext(req) {
|
|
|
157
111
|
subject: oauth.user.userUuid,
|
|
158
112
|
};
|
|
159
113
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (!(oauth === null || oauth === void 0 ? void 0 : oauth.accessToken)) {
|
|
167
|
-
(0, lightdash_oauth_middleware_js_1.writeOAuthAuthFailure)(res, (0, lightdash_oauth_middleware_js_1.buildBearerRequiredFailure)(config, mcpPath));
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
if (entry.auth.subject && entry.auth.subject !== oauth.user.userUuid) {
|
|
171
|
-
(0, lightdash_oauth_middleware_js_1.writeOAuthAuthFailure)(res, (0, lightdash_oauth_middleware_js_1.buildInvalidTokenFailure)(config, mcpPath, 'Session subject mismatch'));
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
const previousOrg = (_a = entry.auth.organizationUuid) !== null && _a !== void 0 ? _a : null;
|
|
175
|
-
const nextOrg = (_b = oauth.user.organizationUuid) !== null && _b !== void 0 ? _b : null;
|
|
176
|
-
if (previousOrg !== nextOrg) {
|
|
177
|
-
(0, lightdash_oauth_middleware_js_1.writeOAuthAuthFailure)(res, (0, lightdash_oauth_middleware_js_1.buildInvalidTokenFailure)(config, mcpPath, 'Session organization mismatch'));
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
const nextTokenHash = (0, token_hash_js_1.hashToken)(oauth.accessToken);
|
|
181
|
-
if (entry.auth.tokenHash !== nextTokenHash) {
|
|
182
|
-
entry.auth.tokenHash = nextTokenHash;
|
|
183
|
-
if (entry.contextProvider instanceof bearer_context_provider_js_1.BearerContextProvider) {
|
|
184
|
-
entry.contextProvider.updateAccessToken(oauth.accessToken);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
async function handleExistingSessionPost(ctx, sid, body) {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
const { req, res, config, sessionStore, persona } = ctx;
|
|
192
|
-
const entry = sessionStore.get(sid);
|
|
193
|
-
if (!entry) {
|
|
194
|
-
(0, http_response_js_1.sendJson)(res, 404, { error: ERROR_SESSION_NOT_FOUND });
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (entry.personaId !== persona.id) {
|
|
198
|
-
(0, http_response_js_1.sendJson)(res, 404, { error: ERROR_SESSION_NOT_FOUND });
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (!verifySessionAuth(req, res, config, persona.path, entry))
|
|
202
|
-
return;
|
|
203
|
-
sessionStore.touch(sid);
|
|
204
|
-
const auditAuth = getOAuthAuditContext(req);
|
|
205
|
-
await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)({
|
|
206
|
-
tokenHash: (_a = auditAuth.tokenHash) !== null && _a !== void 0 ? _a : entry.auth.tokenHash,
|
|
207
|
-
subject: (_b = auditAuth.subject) !== null && _b !== void 0 ? _b : entry.auth.subject,
|
|
208
|
-
}, () => entry.transport.handleRequest(req, res, body));
|
|
209
|
-
}
|
|
210
|
-
async function handleInitializePost(ctx, body) {
|
|
211
|
-
const { req, res, config, sessionStore, persona } = ctx;
|
|
212
|
-
const oauth = config.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH
|
|
213
|
-
? req.lightdashOAuth
|
|
214
|
-
: undefined;
|
|
215
|
-
const sessionSubject = (oauth === null || oauth === void 0 ? void 0 : oauth.ok) ? oauth.user.userUuid : undefined;
|
|
216
|
-
if (!sessionStore.canAcceptNewSession(sessionSubject, (entry, sessionId) => {
|
|
217
|
-
closeSessionEntry(entry, sessionId, 'expired');
|
|
218
|
-
})) {
|
|
219
|
-
(0, http_response_js_1.sendJson)(res, 503, { error: 'Service Unavailable: max sessions reached' });
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
114
|
+
/**
|
|
115
|
+
* Creates a fresh context provider for the current request.
|
|
116
|
+
* For OAuth, uses the bearer token from this request directly.
|
|
117
|
+
* For shared-key/none, uses the env-based provider.
|
|
118
|
+
*/
|
|
119
|
+
function createContextProviderForRequest(config, req) {
|
|
222
120
|
if (config.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
121
|
+
const oauth = req.lightdashOAuth;
|
|
122
|
+
if (oauth === null || oauth === void 0 ? void 0 : oauth.ok) {
|
|
123
|
+
return (0, bearer_context_provider_js_1.createOAuthBearerProvider)(config, {
|
|
124
|
+
accessToken: oauth.accessToken,
|
|
125
|
+
subject: oauth.user.userUuid,
|
|
126
|
+
});
|
|
227
127
|
}
|
|
228
|
-
|
|
229
|
-
accessToken: oauth.accessToken,
|
|
230
|
-
subject: oauth.user.userUuid,
|
|
231
|
-
});
|
|
232
|
-
const transport = createSessionTransport(contextProvider, sessionStore, {
|
|
233
|
-
mode: auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH,
|
|
234
|
-
tokenHash: contextProvider.getTokenHash(),
|
|
235
|
-
subject: oauth.user.userUuid,
|
|
236
|
-
organizationUuid: oauth.user.organizationUuid,
|
|
237
|
-
}, persona);
|
|
238
|
-
await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)({
|
|
239
|
-
tokenHash: contextProvider.getTokenHash(),
|
|
240
|
-
subject: oauth.user.userUuid,
|
|
241
|
-
}, () => transport.handleRequest(req, res, body));
|
|
242
|
-
return;
|
|
128
|
+
throw new Error('OAuth auth mode requires authenticated request context');
|
|
243
129
|
}
|
|
244
|
-
|
|
245
|
-
mode: config.authMode,
|
|
246
|
-
}, persona);
|
|
247
|
-
await transport.handleRequest(req, res, body);
|
|
130
|
+
return createEnvContextProvider(config);
|
|
248
131
|
}
|
|
249
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Handles a MCP POST by creating a fresh stateless transport + server per request.
|
|
134
|
+
* No session affinity — each POST is independent (ADR-0019).
|
|
135
|
+
*/
|
|
136
|
+
async function handleMcpPost(ctx) {
|
|
250
137
|
const { req, res, config, persona } = ctx;
|
|
251
|
-
if (config
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
(0, http_body_js_1.drainRequestBody)(req);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
138
|
+
if (!(await ensureEndpointAuth(req, res, config, persona.path))) {
|
|
139
|
+
(0, http_body_js_1.drainRequestBody)(req);
|
|
140
|
+
return;
|
|
257
141
|
}
|
|
258
142
|
const raw = await (0, http_body_js_1.readBody)(req, res, config.maxBodyBytes);
|
|
259
143
|
if (raw === undefined)
|
|
@@ -268,64 +152,32 @@ async function handleMcpPost(ctx, sid) {
|
|
|
268
152
|
return;
|
|
269
153
|
}
|
|
270
154
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
(0, http_response_js_1.sendJson)(res, 400, {
|
|
280
|
-
error: 'Bad Request: Mcp-Session-Id required for non-initialize requests',
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
async function handleMcpGetOrDelete(ctx, sid) {
|
|
284
|
-
var _a, _b;
|
|
285
|
-
const { req, res, config, sessionStore, persona } = ctx;
|
|
286
|
-
if (!sid) {
|
|
287
|
-
(0, http_response_js_1.sendJson)(res, 400, { error: 'Bad Request: Mcp-Session-Id required' });
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (config.authMode !== auth_mode_js_1.MCP_AUTH_MODE_NONE) {
|
|
291
|
-
if (!(await ensureEndpointAuth(req, res, config, persona.path)))
|
|
292
|
-
return;
|
|
155
|
+
const contextProvider = createContextProviderForRequest(config, req);
|
|
156
|
+
const transport = new node_1.NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
157
|
+
const server = (0, server_js_1.createLightdashMcpServer)(contextProvider, { persona });
|
|
158
|
+
const auditAuth = getOAuthAuditContext(req);
|
|
159
|
+
(0, client_capabilities_cache_js_1.prepareServerClientCapabilities)(server, body, auditAuth, persona.path);
|
|
160
|
+
try {
|
|
161
|
+
await server.connect(transport);
|
|
162
|
+
await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)(auditAuth, () => transport.handleRequest(req, res, body));
|
|
293
163
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return;
|
|
164
|
+
finally {
|
|
165
|
+
await transport.close().catch(() => undefined);
|
|
166
|
+
await server.close().catch(() => undefined);
|
|
298
167
|
}
|
|
299
|
-
if (!verifySessionAuth(req, res, config, persona.path, entry))
|
|
300
|
-
return;
|
|
301
|
-
sessionStore.touch(sid);
|
|
302
|
-
const auditAuth = getOAuthAuditContext(req);
|
|
303
|
-
await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)({
|
|
304
|
-
tokenHash: (_a = auditAuth.tokenHash) !== null && _a !== void 0 ? _a : entry.auth.tokenHash,
|
|
305
|
-
subject: (_b = auditAuth.subject) !== null && _b !== void 0 ? _b : entry.auth.subject,
|
|
306
|
-
}, () => entry.transport.handleRequest(req, res));
|
|
307
168
|
}
|
|
308
169
|
async function createStreamableHttpServer(config) {
|
|
309
170
|
var _a;
|
|
310
171
|
const inputConfig = config !== null && config !== void 0 ? config : (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
311
172
|
(0, load_mcp_config_js_1.emitMcpHttpSecurityWarnings)(inputConfig);
|
|
173
|
+
(0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
|
|
174
|
+
(0, available_projects_js_1.validateAvailableProjectsConfig)();
|
|
175
|
+
(0, request_state_key_js_1.assertHttpSignedStateKeyConfigured)();
|
|
312
176
|
(0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
|
|
313
|
-
const ephemeralStoreConfig = (0, config_js_1.resolveEphemeralStoreConfig)();
|
|
314
|
-
const sessionStore = (0, create_session_store_js_1.createSessionStore)(ephemeralStoreConfig, {
|
|
315
|
-
sessionTtlMs: inputConfig.sessionTtlMs,
|
|
316
|
-
maxSessions: inputConfig.maxSessions,
|
|
317
|
-
maxSessionsPerSubject: inputConfig.maxSessionsPerSubject,
|
|
318
|
-
});
|
|
319
177
|
let httpConfig = inputConfig;
|
|
320
|
-
const cleanupTimer = setInterval(() => {
|
|
321
|
-
sessionStore.cleanupExpired((entry, sessionId) => {
|
|
322
|
-
closeSessionEntry(entry, sessionId, 'expired');
|
|
323
|
-
});
|
|
324
|
-
}, inputConfig.sessionCleanupMs);
|
|
325
|
-
cleanupTimer.unref();
|
|
326
178
|
let oauthBroker;
|
|
327
179
|
const server = (0, node_http_1.createServer)((req, res) => {
|
|
328
|
-
handleHttpRequest(req, res, httpConfig,
|
|
180
|
+
handleHttpRequest(req, res, httpConfig, oauthBroker).catch((err) => {
|
|
329
181
|
console.error('MCP HTTP handler error:', err);
|
|
330
182
|
if (!res.headersSent) {
|
|
331
183
|
(0, http_response_js_1.sendJson)(res, 500, { error: 'Internal Server Error' });
|
|
@@ -338,17 +190,13 @@ async function createStreamableHttpServer(config) {
|
|
|
338
190
|
httpConfig = resolveHttpConfig(inputConfig, port);
|
|
339
191
|
const baseUrl = (_a = httpConfig.publicUrl) !== null && _a !== void 0 ? _a : `http://${resolveListenHost(httpConfig.host)}:${port}`;
|
|
340
192
|
if (httpConfig.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
341
|
-
oauthBroker = (0, routes_js_1.createOAuthBroker)(httpConfig
|
|
193
|
+
oauthBroker = (0, routes_js_1.createOAuthBroker)(httpConfig);
|
|
342
194
|
}
|
|
343
195
|
return {
|
|
344
196
|
port,
|
|
345
197
|
baseUrl,
|
|
346
198
|
config: httpConfig,
|
|
347
199
|
close: () => new Promise((resolve, reject) => {
|
|
348
|
-
clearInterval(cleanupTimer);
|
|
349
|
-
sessionStore.drainAll((entry, sessionId) => {
|
|
350
|
-
closeSessionEntry(entry, sessionId, 'shutdown');
|
|
351
|
-
});
|
|
352
200
|
server.close((err) => {
|
|
353
201
|
if (err)
|
|
354
202
|
reject(err);
|
|
@@ -430,7 +278,7 @@ async function handlePublicHttpPaths(req, res, config, path, oauthBroker) {
|
|
|
430
278
|
}
|
|
431
279
|
return false;
|
|
432
280
|
}
|
|
433
|
-
async function handleHttpRequest(req, res, config,
|
|
281
|
+
async function handleHttpRequest(req, res, config, oauthBroker) {
|
|
434
282
|
var _a, _b;
|
|
435
283
|
const path = (_b = ((_a = req.url) !== null && _a !== void 0 ? _a : '').split('?')[0]) !== null && _b !== void 0 ? _b : '';
|
|
436
284
|
if (await handlePublicHttpPaths(req, res, config, path, oauthBroker)) {
|
|
@@ -445,17 +293,11 @@ async function handleHttpRequest(req, res, config, sessionStore, oauthBroker) {
|
|
|
445
293
|
(0, http_response_js_1.sendJson)(res, 404, { error: 'Not Found' });
|
|
446
294
|
return;
|
|
447
295
|
}
|
|
448
|
-
|
|
296
|
+
// Sessionless: only POST is supported on persona MCP paths.
|
|
297
|
+
if (req.method !== 'POST') {
|
|
298
|
+
res.writeHead(405, { Allow: 'POST' }).end();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
449
301
|
const pinnedProjectUuid = (0, project_pin_js_1.extractPinnedProjectFromRequest)(req);
|
|
450
|
-
await (0, project_pin_js_1.runWithProjectPinAsync)(pinnedProjectUuid,
|
|
451
|
-
if (req.method === 'POST') {
|
|
452
|
-
await handleMcpPost({ req, res, config, sessionStore, persona }, sid);
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
if (req.method === 'GET' || req.method === 'DELETE') {
|
|
456
|
-
await handleMcpGetOrDelete({ req, res, config, sessionStore, persona }, sid);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
res.writeHead(405, { Allow: 'GET, POST, DELETE' }).end();
|
|
460
|
-
});
|
|
302
|
+
await (0, project_pin_js_1.runWithProjectPinAsync)(pinnedProjectUuid, () => handleMcpPost({ req, res, config, persona }));
|
|
461
303
|
}
|
|
@@ -14,9 +14,6 @@ const streamable_http_js_1 = require("./streamable-http.js");
|
|
|
14
14
|
const oauthConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
15
15
|
port: 0,
|
|
16
16
|
oauthClientId: 'client-id',
|
|
17
|
-
sessionTtlMs: 10000,
|
|
18
|
-
maxSessions: 1000,
|
|
19
|
-
maxSessionsPerSubject: 50,
|
|
20
17
|
validateToken: false,
|
|
21
18
|
tokenValidationCacheTtlMs: 60000,
|
|
22
19
|
});
|
|
@@ -97,4 +94,14 @@ function clearMcpEnv() {
|
|
|
97
94
|
(0, vitest_1.it)('exports createStreamableHttpServer', () => {
|
|
98
95
|
(0, vitest_1.expect)(typeof streamable_http_js_1.createStreamableHttpServer).toBe('function');
|
|
99
96
|
});
|
|
97
|
+
(0, vitest_1.it)('rejects HTTP startup when request-state key is missing in production', async () => {
|
|
98
|
+
const savedVitest = process.env.VITEST;
|
|
99
|
+
delete process.env.VITEST;
|
|
100
|
+
process.env.NODE_ENV = 'production';
|
|
101
|
+
delete process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY];
|
|
102
|
+
await (0, vitest_1.expect)((0, streamable_http_js_1.createStreamableHttpServer)((0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({ port: 0 }))).rejects.toThrow(/LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY/);
|
|
103
|
+
if (savedVitest !== undefined) {
|
|
104
|
+
process.env.VITEST = savedVitest;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
100
107
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer,
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, and ai-agent-ops personas.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -23,10 +23,9 @@
|
|
|
23
23
|
"@modelcontextprotocol/server": "2.0.0",
|
|
24
24
|
"commander": "^15.0.0",
|
|
25
25
|
"hono": "^4.12.32",
|
|
26
|
-
"redis": "^6.2.0",
|
|
27
26
|
"zod": "^4.4.3",
|
|
28
|
-
"@lightdash-tools/client": "0.
|
|
29
|
-
"@lightdash-tools/common": "0.
|
|
27
|
+
"@lightdash-tools/client": "0.9.0",
|
|
28
|
+
"@lightdash-tools/common": "0.9.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@modelcontextprotocol/client": "2.0.0",
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
"access": "public"
|
|
37
36
|
},
|
|
38
37
|
"scripts": {
|
|
39
|
-
"build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance; do mkdir -p dist/personas/$p/v1/resources/playbooks && cp -R src/personas/$p/v1/resources/playbooks/. dist/personas/$p/v1/resources/playbooks/; done",
|
|
38
|
+
"build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance ai-agent-ops; do mkdir -p dist/personas/$p/v1/resources/playbooks && cp -R src/personas/$p/v1/resources/playbooks/. dist/personas/$p/v1/resources/playbooks/; done",
|
|
40
39
|
"start": "node dist/index.js",
|
|
41
40
|
"start:http": "node dist/http.js",
|
|
42
41
|
"test": "pnpm --dir ../.. exec vitest run packages/mcp/src"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One-shot claim for non-idempotent elicitation confirmations (e.g. promote).
|
|
3
|
-
* Memory Map by default; Redis SET NX when LIGHTDASH_TOOLS_MCP_STORE=redis (ADR-0016).
|
|
4
|
-
* Releases are compare-and-delete so a late cleanup cannot erase a newer claimant.
|
|
5
|
-
*/
|
|
6
|
-
import type { DestructiveRequestState } from './types.js';
|
|
7
|
-
export type ConfirmationClaimHandle = {
|
|
8
|
-
key: string;
|
|
9
|
-
token: string;
|
|
10
|
-
};
|
|
11
|
-
/** Stable key for a verified confirmation binding. */
|
|
12
|
-
export declare function confirmationClaimKey(state: DestructiveRequestState): string;
|
|
13
|
-
/**
|
|
14
|
-
* Claim a confirmation key for one apply. Returns undefined if already claimed
|
|
15
|
-
* within TTL (concurrent/replayed accept).
|
|
16
|
-
*/
|
|
17
|
-
export declare function claimConfirmationKey(key: string, ttlMs?: number): Promise<ConfirmationClaimHandle | undefined>;
|
|
18
|
-
/** Release only if this handle still owns the claim (compare-and-delete). */
|
|
19
|
-
export declare function releaseConfirmationKey(handle: ConfirmationClaimHandle): Promise<void>;
|
|
20
|
-
/** Reset memory claims (tests only). */
|
|
21
|
-
export declare function resetConfirmationClaimsForTests(): void;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* One-shot claim for non-idempotent elicitation confirmations (e.g. promote).
|
|
4
|
-
* Memory Map by default; Redis SET NX when LIGHTDASH_TOOLS_MCP_STORE=redis (ADR-0016).
|
|
5
|
-
* Releases are compare-and-delete so a late cleanup cannot erase a newer claimant.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.confirmationClaimKey = confirmationClaimKey;
|
|
9
|
-
exports.claimConfirmationKey = claimConfirmationKey;
|
|
10
|
-
exports.releaseConfirmationKey = releaseConfirmationKey;
|
|
11
|
-
exports.resetConfirmationClaimsForTests = resetConfirmationClaimsForTests;
|
|
12
|
-
const node_crypto_1 = require("node:crypto");
|
|
13
|
-
const config_js_1 = require("../store/config.js");
|
|
14
|
-
const redis_client_js_1 = require("../store/redis-client.js");
|
|
15
|
-
/** Longer than requestState TTL so an in-flight promote cannot be reclaimed mid-call. */
|
|
16
|
-
const DEFAULT_TTL_MS = 30 * 60 * 1000;
|
|
17
|
-
const REDIS_KEY_PREFIX = 'lightdash-mcp:confirm-claim:';
|
|
18
|
-
/** Compare-and-delete: only remove if the value still matches our claim token. */
|
|
19
|
-
const REDIS_RELEASE_LUA = `
|
|
20
|
-
if redis.call('GET', KEYS[1]) == ARGV[1] then
|
|
21
|
-
return redis.call('DEL', KEYS[1])
|
|
22
|
-
end
|
|
23
|
-
return 0
|
|
24
|
-
`;
|
|
25
|
-
const memoryClaims = new Map();
|
|
26
|
-
function purgeExpiredMemory(now) {
|
|
27
|
-
for (const [key, claim] of memoryClaims) {
|
|
28
|
-
if (claim.expiresAt <= now) {
|
|
29
|
-
memoryClaims.delete(key);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function redisClaimKey(key) {
|
|
34
|
-
return `${REDIS_KEY_PREFIX}${key}`;
|
|
35
|
-
}
|
|
36
|
-
/** Stable key for a verified confirmation binding. */
|
|
37
|
-
function confirmationClaimKey(state) {
|
|
38
|
-
return [
|
|
39
|
-
state.sessionId,
|
|
40
|
-
state.operationId,
|
|
41
|
-
state.resourceType,
|
|
42
|
-
state.resourceId,
|
|
43
|
-
state.projectUuid,
|
|
44
|
-
state.preconditionDigest,
|
|
45
|
-
].join('\0');
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Claim a confirmation key for one apply. Returns undefined if already claimed
|
|
49
|
-
* within TTL (concurrent/replayed accept).
|
|
50
|
-
*/
|
|
51
|
-
async function claimConfirmationKey(key, ttlMs = DEFAULT_TTL_MS) {
|
|
52
|
-
const token = (0, node_crypto_1.randomUUID)();
|
|
53
|
-
const config = (0, config_js_1.resolveEphemeralStoreConfig)();
|
|
54
|
-
if (config.backend === 'redis') {
|
|
55
|
-
const redis = await (0, redis_client_js_1.getSharedRedisClient)(config);
|
|
56
|
-
const result = await redis.set(redisClaimKey(key), token, { NX: true, PX: ttlMs });
|
|
57
|
-
return result === 'OK' ? { key, token } : undefined;
|
|
58
|
-
}
|
|
59
|
-
const now = Date.now();
|
|
60
|
-
purgeExpiredMemory(now);
|
|
61
|
-
const existing = memoryClaims.get(key);
|
|
62
|
-
if (existing !== undefined && existing.expiresAt > now) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
memoryClaims.set(key, { token, expiresAt: now + ttlMs });
|
|
66
|
-
return { key, token };
|
|
67
|
-
}
|
|
68
|
-
/** Release only if this handle still owns the claim (compare-and-delete). */
|
|
69
|
-
async function releaseConfirmationKey(handle) {
|
|
70
|
-
const config = (0, config_js_1.resolveEphemeralStoreConfig)();
|
|
71
|
-
if (config.backend === 'redis') {
|
|
72
|
-
const redis = await (0, redis_client_js_1.getSharedRedisClient)(config);
|
|
73
|
-
await redis.eval(REDIS_RELEASE_LUA, {
|
|
74
|
-
keys: [redisClaimKey(handle.key)],
|
|
75
|
-
arguments: [handle.token],
|
|
76
|
-
});
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const current = memoryClaims.get(handle.key);
|
|
80
|
-
if ((current === null || current === void 0 ? void 0 : current.token) === handle.token) {
|
|
81
|
-
memoryClaims.delete(handle.key);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/** Reset memory claims (tests only). */
|
|
85
|
-
function resetConfirmationClaimsForTests() {
|
|
86
|
-
memoryClaims.clear();
|
|
87
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const confirmation_claim_js_1 = require("./confirmation-claim.js");
|
|
5
|
-
const state = {
|
|
6
|
-
operationId: 'content-governance.dashboards.promote',
|
|
7
|
-
resourceType: 'dashboard',
|
|
8
|
-
resourceId: 'd1',
|
|
9
|
-
projectUuid: 'p1',
|
|
10
|
-
preconditionDigest: 'digest-a',
|
|
11
|
-
sessionId: 's1',
|
|
12
|
-
resourceName: 'Board',
|
|
13
|
-
};
|
|
14
|
-
(0, vitest_1.describe)('confirmation-claim', () => {
|
|
15
|
-
(0, vitest_1.afterEach)(() => {
|
|
16
|
-
(0, confirmation_claim_js_1.resetConfirmationClaimsForTests)();
|
|
17
|
-
});
|
|
18
|
-
(0, vitest_1.it)('allows the first claim and rejects a concurrent replay', async () => {
|
|
19
|
-
const key = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
|
|
20
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toEqual(vitest_1.expect.objectContaining({ key, token: vitest_1.expect.any(String) }));
|
|
21
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toBeUndefined();
|
|
22
|
-
});
|
|
23
|
-
(0, vitest_1.it)('releases a claim so a confirmed no-write failure can retry', async () => {
|
|
24
|
-
const key = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
|
|
25
|
-
const handle = await (0, confirmation_claim_js_1.claimConfirmationKey)(key);
|
|
26
|
-
(0, vitest_1.expect)(handle).toBeDefined();
|
|
27
|
-
await (0, confirmation_claim_js_1.releaseConfirmationKey)(handle);
|
|
28
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toEqual(vitest_1.expect.objectContaining({ key, token: vitest_1.expect.any(String) }));
|
|
29
|
-
});
|
|
30
|
-
(0, vitest_1.it)('does not release when the handle token no longer owns the claim', async () => {
|
|
31
|
-
const key = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
|
|
32
|
-
const first = await (0, confirmation_claim_js_1.claimConfirmationKey)(key);
|
|
33
|
-
(0, vitest_1.expect)(first).toBeDefined();
|
|
34
|
-
// Simulate TTL expiry + re-claim by a newer request.
|
|
35
|
-
(0, confirmation_claim_js_1.resetConfirmationClaimsForTests)();
|
|
36
|
-
const second = await (0, confirmation_claim_js_1.claimConfirmationKey)(key);
|
|
37
|
-
(0, vitest_1.expect)(second).toBeDefined();
|
|
38
|
-
await (0, confirmation_claim_js_1.releaseConfirmationKey)(first);
|
|
39
|
-
// Newer claim must still block a third acquire.
|
|
40
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toBeUndefined();
|
|
41
|
-
await (0, confirmation_claim_js_1.releaseConfirmationKey)(second);
|
|
42
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toBeDefined();
|
|
43
|
-
});
|
|
44
|
-
(0, vitest_1.it)('treats distinct precondition digests as distinct claims', async () => {
|
|
45
|
-
const keyA = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
|
|
46
|
-
const keyB = (0, confirmation_claim_js_1.confirmationClaimKey)(Object.assign(Object.assign({}, state), { preconditionDigest: 'digest-b' }));
|
|
47
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(keyA)).toBeDefined();
|
|
48
|
-
(0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(keyB)).toBeDefined();
|
|
49
|
-
});
|
|
50
|
-
});
|
package/dist/store/config.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve LIGHTDASH_TOOLS_MCP_STORE (+ REDIS_URL) for ephemeral MCP state (ADR-0016).
|
|
3
|
-
*/
|
|
4
|
-
import type { EphemeralStoreConfig } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Parse store backend env. Fail closed when `redis` is selected without a URL.
|
|
7
|
-
* Default is memory (stdio/tests and single-instance HTTP).
|
|
8
|
-
*/
|
|
9
|
-
export declare function resolveEphemeralStoreConfig(env?: NodeJS.ProcessEnv): EphemeralStoreConfig;
|
|
10
|
-
/** Warn when HTTP uses in-memory ephemeral state (multi-instance / restart loss). */
|
|
11
|
-
export declare function emitEphemeralStoreHttpWarning(config?: EphemeralStoreConfig): void;
|
package/dist/store/config.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Resolve LIGHTDASH_TOOLS_MCP_STORE (+ REDIS_URL) for ephemeral MCP state (ADR-0016).
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveEphemeralStoreConfig = resolveEphemeralStoreConfig;
|
|
7
|
-
exports.emitEphemeralStoreHttpWarning = emitEphemeralStoreHttpWarning;
|
|
8
|
-
const env_js_1 = require("../config/env.js");
|
|
9
|
-
function readEnv(name, env) {
|
|
10
|
-
// eslint-disable-next-line security/detect-object-injection -- env var names are fixed constants
|
|
11
|
-
const value = env[name];
|
|
12
|
-
if (value == null) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
const trimmed = value.trim();
|
|
16
|
-
return trimmed.length > 0 ? trimmed : undefined;
|
|
17
|
-
}
|
|
18
|
-
function parseStoreBackend(raw) {
|
|
19
|
-
if (raw == null || raw === 'memory') {
|
|
20
|
-
return 'memory';
|
|
21
|
-
}
|
|
22
|
-
if (raw === 'redis') {
|
|
23
|
-
return 'redis';
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE} must be 'memory' or 'redis' (got '${raw}').`);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Parse store backend env. Fail closed when `redis` is selected without a URL.
|
|
29
|
-
* Default is memory (stdio/tests and single-instance HTTP).
|
|
30
|
-
*/
|
|
31
|
-
function resolveEphemeralStoreConfig(env = process.env) {
|
|
32
|
-
const backend = parseStoreBackend(readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE, env));
|
|
33
|
-
if (backend === 'memory') {
|
|
34
|
-
return { backend: 'memory' };
|
|
35
|
-
}
|
|
36
|
-
const redisUrl = readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL, env);
|
|
37
|
-
if (!redisUrl) {
|
|
38
|
-
throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL} is required when ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE}=redis.`);
|
|
39
|
-
}
|
|
40
|
-
return { backend: 'redis', redisUrl };
|
|
41
|
-
}
|
|
42
|
-
/** Warn when HTTP uses in-memory ephemeral state (multi-instance / restart loss). */
|
|
43
|
-
function emitEphemeralStoreHttpWarning(config = resolveEphemeralStoreConfig()) {
|
|
44
|
-
if (config.backend === 'memory') {
|
|
45
|
-
console.warn(`Warning: MCP HTTP ephemeral store is in-memory (${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE}=memory). ` +
|
|
46
|
-
'Preview ledger, transport sessions, and OAuth pending state are lost on process restart ' +
|
|
47
|
-
'and are not shared across instances. Use sticky routing or set ' +
|
|
48
|
-
`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE}=redis with ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL} for horizontal scale.`);
|
|
49
|
-
}
|
|
50
|
-
}
|