@lightdash-tools/mcp 0.7.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 +113 -170
- 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 +69 -19
- package/dist/auth/oauth-broker/pending-store.js +52 -26
- package/dist/auth/oauth-broker/pending-store.test.d.ts +5 -0
- package/dist/auth/oauth-broker/pending-store.test.js +109 -0
- package/dist/auth/oauth-broker/routes.d.ts +6 -2
- package/dist/auth/oauth-broker/routes.js +25 -20
- package/dist/auth/oauth-broker/routes.test.js +33 -28
- 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 +12 -8
- package/dist/bin.js +30 -2
- package/dist/config/env.d.ts +5 -8
- package/dist/config/env.js +6 -9
- package/dist/config/load-mcp-config.d.ts +0 -4
- package/dist/config/load-mcp-config.js +8 -5
- package/dist/config/load-mcp-config.test.js +7 -0
- package/dist/config/normalize-url.test.js +16 -7
- 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/capability.d.ts +13 -0
- package/dist/destructive/capability.js +37 -0
- package/dist/destructive/capability.test.js +46 -0
- package/dist/destructive/confirmation.d.ts +58 -0
- package/dist/destructive/confirmation.js +99 -0
- package/dist/destructive/confirmation.test.d.ts +1 -0
- package/dist/destructive/confirmation.test.js +75 -0
- package/dist/destructive/content-promote.d.ts +8 -0
- package/dist/destructive/content-promote.js +150 -0
- package/dist/destructive/content-soft-delete.d.ts +7 -0
- package/dist/destructive/content-soft-delete.js +106 -0
- package/dist/destructive/destructive-contract.test.d.ts +1 -0
- package/dist/destructive/destructive-contract.test.js +269 -0
- package/dist/destructive/precondition.d.ts +14 -0
- package/dist/destructive/precondition.js +31 -0
- package/dist/destructive/precondition.test.d.ts +1 -0
- package/dist/destructive/precondition.test.js +72 -0
- package/dist/destructive/promote-contract.test.d.ts +1 -0
- package/dist/destructive/promote-contract.test.js +398 -0
- package/dist/destructive/register-destructive-tool.d.ts +54 -0
- package/dist/destructive/register-destructive-tool.js +283 -0
- package/dist/destructive/request-state.d.ts +12 -0
- package/dist/destructive/request-state.js +41 -0
- package/dist/destructive/types.d.ts +65 -0
- package/dist/destructive/types.js +10 -0
- 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.d.ts +1 -0
- package/dist/governance/client-capabilities-cache.test.js +148 -0
- package/dist/governance/mcp-client-session.d.ts +10 -0
- package/dist/governance/mcp-client-session.js +31 -0
- package/dist/governance/mcp-client-session.test.d.ts +1 -0
- package/dist/governance/mcp-client-session.test.js +31 -0
- package/dist/governance/project-scope.d.ts +24 -0
- package/dist/governance/project-scope.js +71 -0
- package/dist/governance/project-scope.test.d.ts +4 -0
- package/dist/governance/project-scope.test.js +80 -0
- 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 +151 -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 +10 -0
- package/dist/personas/content-developer/v1/index.js +52 -0
- package/dist/personas/content-developer/v1/prompts.d.ts +8 -0
- package/dist/personas/content-developer/v1/prompts.js +157 -0
- package/dist/personas/content-developer/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-developer/v1/prompts.test.js +231 -0
- package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
- package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +22 -0
- package/dist/personas/content-developer/v1/resources/playbooks/core.md +105 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +103 -0
- package/dist/personas/content-developer/v1/resources/playbooks/index.md +15 -0
- package/dist/personas/content-developer/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-developer/v1/resources/playbooks.js +63 -0
- package/dist/personas/content-governance/v1/index.d.ts +9 -0
- package/dist/personas/content-governance/v1/index.js +29 -0
- package/dist/personas/content-governance/v1/prompts.d.ts +5 -0
- package/dist/personas/content-governance/v1/prompts.js +87 -0
- package/dist/personas/content-governance/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-governance/v1/prompts.test.js +75 -0
- package/dist/personas/content-governance/v1/resources/playbooks/charts.md +29 -0
- package/dist/personas/content-governance/v1/resources/playbooks/core.md +52 -0
- package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +48 -0
- package/dist/personas/content-governance/v1/resources/playbooks/index.md +13 -0
- package/dist/personas/content-governance/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-governance/v1/resources/playbooks.js +41 -0
- package/dist/personas/content-reader/v1/index.d.ts +8 -0
- package/dist/personas/content-reader/v1/index.js +38 -0
- package/dist/personas/content-reader/v1/prompts.d.ts +5 -0
- package/dist/personas/content-reader/v1/prompts.js +162 -0
- package/dist/personas/content-reader/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-reader/v1/prompts.test.js +25 -0
- package/dist/personas/content-reader/v1/resources/playbooks/compare.md +36 -0
- package/dist/personas/content-reader/v1/resources/playbooks/core.md +67 -0
- package/dist/personas/content-reader/v1/resources/playbooks/discover.md +35 -0
- package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +49 -0
- package/dist/personas/content-reader/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/content-reader/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-reader/v1/resources/playbooks.js +49 -0
- package/dist/personas/index.d.ts +4 -0
- package/dist/personas/index.js +31 -10
- package/dist/personas/index.test.js +92 -26
- package/dist/personas/lib/playbook-resources.d.ts +80 -0
- package/dist/personas/lib/playbook-resources.js +169 -0
- package/dist/personas/organization-audit/v1/index.js +2 -2
- package/dist/personas/organization-audit/v1/prompts.js +79 -66
- package/dist/personas/organization-audit/v1/prompts.test.js +4 -4
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +21 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +19 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/core.md +69 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +14 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/organization-audit/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/organization-audit/v1/resources/playbooks.js +41 -0
- package/dist/personas/persona.parity.test.d.ts +1 -0
- package/dist/personas/persona.parity.test.js +30 -0
- package/dist/personas/semantic-layer/v1/index.js +2 -2
- package/dist/personas/semantic-layer/v1/prompts.js +56 -67
- package/dist/personas/semantic-layer/v1/prompts.test.d.ts +4 -0
- package/dist/personas/semantic-layer/v1/prompts.test.js +19 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +60 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +71 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +79 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +13 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks.d.ts +13 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks.js +39 -0
- package/dist/personas/types.d.ts +1 -1
- package/dist/policy/content-developer.d.ts +35 -0
- package/dist/policy/content-developer.js +91 -0
- package/dist/policy/content-developer.test.d.ts +4 -0
- package/dist/policy/content-developer.test.js +54 -0
- package/dist/policy/content-reader.d.ts +28 -0
- package/dist/policy/content-reader.js +67 -0
- package/dist/policy/content-reader.test.d.ts +4 -0
- package/dist/policy/content-reader.test.js +23 -0
- package/dist/policy/envelope.d.ts +31 -0
- package/dist/policy/envelope.js +24 -0
- package/dist/policy/preview-ledger-fault.test.d.ts +1 -0
- package/dist/policy/preview-ledger-fault.test.js +202 -0
- package/dist/policy/preview-ledger.d.ts +82 -0
- package/dist/policy/preview-ledger.js +165 -0
- package/dist/policy/preview-ledger.test.d.ts +1 -0
- package/dist/policy/preview-ledger.test.js +393 -0
- package/dist/policy/result-limits.d.ts +32 -0
- package/dist/policy/result-limits.js +106 -0
- package/dist/policy/result-limits.test.d.ts +4 -0
- package/dist/policy/result-limits.test.js +37 -0
- package/dist/server/capabilities.js +3 -1
- package/dist/server/capabilities.test.js +5 -1
- package/dist/server/server.js +16 -1
- package/dist/server/upstream-errors.d.ts +17 -0
- package/dist/server/upstream-errors.js +60 -0
- package/dist/server/upstream-errors.test.d.ts +1 -0
- package/dist/server/upstream-errors.test.js +50 -0
- package/dist/stdio.process.test.js +150 -0
- 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.d.ts +1 -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/composition/explain-content.d.ts +6 -0
- package/dist/tools/composition/explain-content.js +108 -0
- package/dist/tools/lib/api-errors.d.ts +2 -0
- package/dist/tools/lib/api-errors.js +5 -0
- package/dist/tools/lib/stable-stringify.d.ts +9 -0
- package/dist/tools/lib/stable-stringify.js +35 -0
- package/dist/tools/organization/inventory.js +2 -1
- package/dist/tools/project/content.js +5 -1
- package/dist/tools/project/delete-chart.d.ts +4 -0
- package/dist/tools/project/delete-chart.js +8 -0
- package/dist/tools/project/delete-dashboard.d.ts +4 -0
- package/dist/tools/project/delete-dashboard.js +8 -0
- package/dist/tools/project/developer-content-preview.d.ts +13 -0
- package/dist/tools/project/developer-content-preview.js +291 -0
- package/dist/tools/project/developer-content-shared.d.ts +24 -0
- package/dist/tools/project/developer-content-shared.js +50 -0
- package/dist/tools/project/developer-content-shared.test.d.ts +1 -0
- package/dist/tools/project/developer-content-shared.test.js +25 -0
- package/dist/tools/project/developer-content.d.ts +38 -0
- package/dist/tools/project/developer-content.js +589 -0
- 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 +180 -0
- package/dist/tools/project/developer-helpers.js +484 -0
- package/dist/tools/project/developer-helpers.test.d.ts +1 -0
- package/dist/tools/project/developer-helpers.test.js +509 -0
- package/dist/tools/project/get-dashboard-promote-diff.d.ts +6 -0
- package/dist/tools/project/get-dashboard-promote-diff.js +52 -0
- package/dist/tools/project/invariants.test.d.ts +4 -0
- package/dist/tools/project/invariants.test.js +44 -0
- package/dist/tools/project/parameters.d.ts +7 -0
- package/dist/tools/project/parameters.js +74 -0
- package/dist/tools/project/projects.d.ts +4 -1
- package/dist/tools/project/projects.js +68 -6
- package/dist/tools/project/projects.test.js +77 -1
- package/dist/tools/project/promote-dashboard.d.ts +4 -0
- package/dist/tools/project/promote-dashboard.js +8 -0
- package/dist/tools/project/reader-content.d.ts +9 -0
- package/dist/tools/project/reader-content.js +208 -0
- package/dist/tools/project/reader-execution.d.ts +7 -0
- package/dist/tools/project/reader-execution.js +214 -0
- 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/project/schemas/chart-upsert.d.ts +33 -0
- package/dist/tools/project/schemas/chart-upsert.js +66 -0
- package/dist/tools/project/schemas/dashboard-tile.d.ts +29 -0
- package/dist/tools/project/schemas/dashboard-tile.js +57 -0
- package/dist/tools/project/schemas/dashboard.d.ts +70 -0
- package/dist/tools/project/schemas/dashboard.js +101 -0
- package/dist/tools/project/schemas/duplicate.d.ts +30 -0
- package/dist/tools/project/schemas/duplicate.js +86 -0
- package/dist/tools/project/schemas/index.d.ts +7 -0
- package/dist/tools/project/schemas/index.js +26 -0
- package/dist/tools/project/schemas/parse-helpers.d.ts +14 -0
- package/dist/tools/project/schemas/parse-helpers.js +34 -0
- package/dist/tools/project/schemas/payload-schemas.test.d.ts +1 -0
- package/dist/tools/project/schemas/payload-schemas.test.js +204 -0
- package/dist/tools/project/spaces.d.ts +7 -0
- package/dist/tools/project/spaces.js +101 -0
- package/dist/tools/query/bounded-saved-query.d.ts +37 -0
- package/dist/tools/query/bounded-saved-query.js +80 -0
- package/dist/tools/query/bounded-saved-query.test.d.ts +4 -0
- package/dist/tools/query/bounded-saved-query.test.js +82 -0
- package/dist/tools/query/chart-source.d.ts +10 -0
- package/dist/tools/query/chart-source.js +36 -0
- package/dist/tools/query/chart-source.test.d.ts +1 -0
- package/dist/tools/query/chart-source.test.js +62 -0
- package/dist/tools/query/filter-overrides.d.ts +34 -0
- package/dist/tools/query/filter-overrides.js +75 -0
- package/dist/tools/query/filter-overrides.test.d.ts +1 -0
- package/dist/tools/query/filter-overrides.test.js +21 -0
- package/dist/tools/query/lifecycle.d.ts +7 -0
- package/dist/tools/query/lifecycle.js +104 -0
- package/dist/tools/query/query-ledger.d.ts +41 -0
- package/dist/tools/query/query-ledger.js +92 -0
- package/dist/tools/query/query-ledger.test.d.ts +1 -0
- package/dist/tools/query/query-ledger.test.js +75 -0
- package/dist/tools/query/reader-tool-helpers.d.ts +12 -0
- package/dist/tools/query/reader-tool-helpers.js +57 -0
- package/dist/tools/query/reader-tool-helpers.test.d.ts +1 -0
- package/dist/tools/query/reader-tool-helpers.test.js +53 -0
- package/dist/tools/query/result-normalizer.d.ts +27 -0
- package/dist/tools/query/result-normalizer.js +133 -0
- package/dist/tools/query/result-normalizer.test.d.ts +1 -0
- package/dist/tools/query/result-normalizer.test.js +41 -0
- package/dist/tools/query/wait-for-async.d.ts +10 -0
- package/dist/tools/query/wait-for-async.js +46 -0
- package/dist/tools/query/wait-for-async.test.d.ts +1 -0
- package/dist/tools/query/wait-for-async.test.js +45 -0
- package/dist/tools/registry.d.ts +187 -3
- package/dist/tools/registry.js +89 -7
- package/dist/tools/shared.d.ts +52 -10
- package/dist/tools/shared.js +127 -41
- package/dist/tools/shared.test.js +103 -3
- package/dist/transports/streamable-http.js +47 -198
- package/dist/transports/streamable-http.test.js +21 -9
- package/package.json +5 -5
- package/dist/personas/organization-audit/v1/resources/playbook.d.ts +0 -11
- package/dist/personas/organization-audit/v1/resources/playbook.js +0 -40
- package/dist/personas/organization-audit/v1/resources/playbook.md +0 -52
- package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +0 -12
- package/dist/personas/semantic-layer/v1/resources/playbook.js +0 -42
- package/dist/personas/semantic-layer/v1/resources/playbook.md +0 -153
- 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 -40
- package/dist/transports/session-store.js +0 -88
- package/dist/transports/session-store.test.js +0 -111
- /package/dist/{transports/session-store.test.d.ts → destructive/capability.test.d.ts} +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Central wrapper for elicitation-gated mutation MCP tools (ADR-0015 / ADR-0017).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PROMOTE_GATE_LABELS = void 0;
|
|
7
|
+
exports.registerElicitationGatedTool = registerElicitationGatedTool;
|
|
8
|
+
exports.registerDestructiveDeleteTool = registerDestructiveDeleteTool;
|
|
9
|
+
const common_1 = require("@lightdash-tools/common");
|
|
10
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
11
|
+
const project_scope_js_1 = require("../governance/project-scope.js");
|
|
12
|
+
const api_errors_js_1 = require("../tools/lib/api-errors.js");
|
|
13
|
+
const schema_fields_js_1 = require("../tools/lib/schema-fields.js");
|
|
14
|
+
const reader_tool_helpers_js_1 = require("../tools/query/reader-tool-helpers.js");
|
|
15
|
+
const shared_js_1 = require("../tools/shared.js");
|
|
16
|
+
const capability_js_1 = require("./capability.js");
|
|
17
|
+
const confirmation_js_1 = require("./confirmation.js");
|
|
18
|
+
const request_state_js_1 = require("./request-state.js");
|
|
19
|
+
const types_js_1 = require("./types.js");
|
|
20
|
+
const DELETE_GATE_LABELS = {
|
|
21
|
+
operation: 'delete',
|
|
22
|
+
successStatus: 'deleted',
|
|
23
|
+
successAudit: 'deletion_succeeded',
|
|
24
|
+
failureCode: 'DELETION_FAILED',
|
|
25
|
+
failureMessage: 'Soft-delete failed. Retry after reviewing the resource, or check server logs.',
|
|
26
|
+
failureAudit: 'deletion_failed',
|
|
27
|
+
bindingMismatchMessage: 'Confirmation binding does not match this delete request.',
|
|
28
|
+
acceptMismatchMessage: 'Confirmation was not accepted, or the typed resource name did not match.',
|
|
29
|
+
resourceChangedMessage: 'The resource changed after confirmation was requested. Review it and confirm again.',
|
|
30
|
+
elicitationRequiredMessage: 'This destructive operation requires an MCP client that supports form elicitation.',
|
|
31
|
+
};
|
|
32
|
+
exports.PROMOTE_GATE_LABELS = {
|
|
33
|
+
operation: 'promote',
|
|
34
|
+
successStatus: 'promoted',
|
|
35
|
+
successAudit: 'promotion_succeeded',
|
|
36
|
+
failureCode: 'PROMOTION_FAILED',
|
|
37
|
+
failureMessage: 'Dashboard promote failed. Retry after reviewing promoteDiff, or check server logs.',
|
|
38
|
+
failureAudit: 'promotion_failed',
|
|
39
|
+
bindingMismatchMessage: 'Confirmation binding does not match this promote request.',
|
|
40
|
+
acceptMismatchMessage: 'Confirmation was not accepted, or the typed dashboard name did not match.',
|
|
41
|
+
resourceChangedMessage: 'The dashboard or promotion diff changed after confirmation was requested. Review it and confirm again.',
|
|
42
|
+
elicitationRequiredMessage: 'Dashboard promote requires an MCP client that supports form elicitation.',
|
|
43
|
+
};
|
|
44
|
+
async function readBoundRequestState(serverContext) {
|
|
45
|
+
const mcpReq = serverContext.mcpReq;
|
|
46
|
+
const raw = typeof mcpReq.requestState === 'function' ? mcpReq.requestState() : mcpReq.requestState;
|
|
47
|
+
// HMAC-signed opaque token (not encrypted): verify via codec.
|
|
48
|
+
if (typeof raw === 'string') {
|
|
49
|
+
return (0, request_state_js_1.verifyDestructiveRequestState)(raw, serverContext);
|
|
50
|
+
}
|
|
51
|
+
// 2025-era SDK legacy elicitation shim may echo the decoded payload object.
|
|
52
|
+
if (raw && typeof raw === 'object' && 'preconditionDigest' in raw && 'operationId' in raw) {
|
|
53
|
+
return raw;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
function confirmationInvalidResult(message, mutatedFlag) {
|
|
58
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
59
|
+
status: 'blocked',
|
|
60
|
+
code: 'CONFIRMATION_INVALID',
|
|
61
|
+
message,
|
|
62
|
+
[mutatedFlag]: false,
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
function elicitationRequiredResult(message, mutatedFlag) {
|
|
66
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
67
|
+
status: 'blocked',
|
|
68
|
+
code: 'ELICITATION_REQUIRED',
|
|
69
|
+
message,
|
|
70
|
+
[mutatedFlag]: false,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
function mutatedFlagFor(operation) {
|
|
74
|
+
return operation === 'delete' ? 'deleted' : 'promoted';
|
|
75
|
+
}
|
|
76
|
+
function declinedOrCancelledResult(action, auditStatus, labels, spec, scopedArgs) {
|
|
77
|
+
const flag = mutatedFlagFor(labels.operation);
|
|
78
|
+
return (0, shared_js_1.withAuditStatus)((0, shared_js_1.jsonToolResult)({
|
|
79
|
+
status: action,
|
|
80
|
+
[flag]: false,
|
|
81
|
+
operation: labels.operation,
|
|
82
|
+
resourceType: spec.resourceType,
|
|
83
|
+
resourceId: scopedArgs.resourceId,
|
|
84
|
+
projectUuid: scopedArgs.projectUuid,
|
|
85
|
+
}), auditStatus);
|
|
86
|
+
}
|
|
87
|
+
function bindingMatches(boundState, spec, scopedArgs, subject) {
|
|
88
|
+
return (boundState.operationId === spec.operationId &&
|
|
89
|
+
boundState.resourceType === spec.resourceType &&
|
|
90
|
+
boundState.resourceId === scopedArgs.resourceId &&
|
|
91
|
+
boundState.projectUuid === scopedArgs.projectUuid &&
|
|
92
|
+
boundState.subject === subject);
|
|
93
|
+
}
|
|
94
|
+
async function resolveTargetOrNotFound(spec, scopedArgs, ctx) {
|
|
95
|
+
try {
|
|
96
|
+
return { ok: true, snapshot: await spec.resolveTarget(scopedArgs, ctx) };
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (err instanceof project_scope_js_1.ProjectScopeError) {
|
|
100
|
+
return { ok: false, result: (0, reader_tool_helpers_js_1.projectScopeErrorResult)(err) };
|
|
101
|
+
}
|
|
102
|
+
if ((0, api_errors_js_1.isNotFoundError)(err)) {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
result: (0, reader_tool_helpers_js_1.codedErrorResult)('CONTENT_NOT_FOUND', `${spec.resourceType} '${scopedArgs.resourceId}' was not found`),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function applyAcceptedMutation(input) {
|
|
112
|
+
const { spec, scopedArgs, boundState, accepted, ctx, form, labels } = input;
|
|
113
|
+
const flag = mutatedFlagFor(labels.operation);
|
|
114
|
+
if (!bindingMatches(boundState, spec, scopedArgs, ctx.subject)) {
|
|
115
|
+
return confirmationInvalidResult(labels.bindingMismatchMessage, flag);
|
|
116
|
+
}
|
|
117
|
+
if (!form.isAcceptedForm(accepted, boundState.resourceName)) {
|
|
118
|
+
return confirmationInvalidResult(labels.acceptMismatchMessage, flag);
|
|
119
|
+
}
|
|
120
|
+
const resolved = await resolveTargetOrNotFound(spec, scopedArgs, ctx);
|
|
121
|
+
if (!resolved.ok) {
|
|
122
|
+
return resolved.result;
|
|
123
|
+
}
|
|
124
|
+
const { snapshot } = resolved;
|
|
125
|
+
// Identity is already checked in bindingMatches (tool arg). Digest uses canonical
|
|
126
|
+
// snapshot ids, so do not require arg slug === uuid via samePrecondition.
|
|
127
|
+
const currentPre = spec.getPrecondition(snapshot);
|
|
128
|
+
if (currentPre.digest !== boundState.preconditionDigest) {
|
|
129
|
+
return (0, shared_js_1.withAuditStatus)((0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
130
|
+
status: 'blocked',
|
|
131
|
+
code: 'RESOURCE_CHANGED',
|
|
132
|
+
message: labels.resourceChangedMessage,
|
|
133
|
+
[flag]: false,
|
|
134
|
+
})), 'resource_changed');
|
|
135
|
+
}
|
|
136
|
+
let executeExtra;
|
|
137
|
+
try {
|
|
138
|
+
executeExtra = await spec.execute(scopedArgs, snapshot, ctx);
|
|
139
|
+
}
|
|
140
|
+
catch (_a) {
|
|
141
|
+
// Do not echo upstream/API exception text to MCP clients or unbounded stderr.
|
|
142
|
+
process.stderr.write(`[lightdash-mcp] ${labels.operation} failed for ${spec.resourceType} ${scopedArgs.resourceId} (${labels.failureCode})\n`);
|
|
143
|
+
return (0, shared_js_1.withAuditStatus)((0, shared_js_1.jsonToolResult)({
|
|
144
|
+
status: 'error',
|
|
145
|
+
[flag]: false,
|
|
146
|
+
code: labels.failureCode,
|
|
147
|
+
message: labels.failureMessage,
|
|
148
|
+
operation: labels.operation,
|
|
149
|
+
resourceType: spec.resourceType,
|
|
150
|
+
resourceId: scopedArgs.resourceId,
|
|
151
|
+
projectUuid: scopedArgs.projectUuid,
|
|
152
|
+
}), labels.failureAudit);
|
|
153
|
+
}
|
|
154
|
+
const target = spec.summarizeTarget(snapshot);
|
|
155
|
+
const completedAt = new Date().toISOString();
|
|
156
|
+
return (0, shared_js_1.withAuditStatus)((0, shared_js_1.jsonToolResult)(Object.assign(Object.assign({ status: labels.successStatus, operation: labels.operation, resourceType: target.resourceType, resourceId: target.resourceId, resourceName: target.resourceName, projectUuid: target.projectUuid, confirmation: { mode: 'form', action: 'accept' } }, (labels.operation === 'delete'
|
|
157
|
+
? { deletedAt: completedAt }
|
|
158
|
+
: { promoted: true, promotedAt: completedAt })), (executeExtra !== null && executeExtra !== void 0 ? executeExtra : {}))), labels.successAudit);
|
|
159
|
+
}
|
|
160
|
+
function requireFormElicitation(server, serverContext, labels) {
|
|
161
|
+
// 2026: per-request envelope; 2025: initialize-declared caps via Server.
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- 2025-era fallback; envelope preferred in capability.ts
|
|
163
|
+
const initializeCaps = server.server.getClientCapabilities();
|
|
164
|
+
if (!(0, capability_js_1.supportsFormElicitation)(serverContext, initializeCaps)) {
|
|
165
|
+
return elicitationRequiredResult(labels.elicitationRequiredMessage, mutatedFlagFor(labels.operation));
|
|
166
|
+
}
|
|
167
|
+
if (!serverContext) {
|
|
168
|
+
return elicitationRequiredResult('Missing MCP ServerContext required for elicitation.', mutatedFlagFor(labels.operation));
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
function declineOrCancelIfPresent(serverContext, inputKey, labels, spec, scopedArgs) {
|
|
173
|
+
const responseView = (0, server_1.inputResponse)(serverContext.mcpReq.inputResponses, inputKey);
|
|
174
|
+
if (responseView.kind === 'elicit' && responseView.action === 'decline') {
|
|
175
|
+
return declinedOrCancelledResult('declined', 'confirmation_declined', labels, spec, scopedArgs);
|
|
176
|
+
}
|
|
177
|
+
if (responseView.kind === 'elicit' && responseView.action === 'cancel') {
|
|
178
|
+
return declinedOrCancelledResult('cancelled', 'confirmation_cancelled', labels, spec, scopedArgs);
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
async function requestConfirmation(spec, scopedArgs, ctx, serverContext, form) {
|
|
183
|
+
const resolved = await resolveTargetOrNotFound(spec, scopedArgs, ctx);
|
|
184
|
+
if (!resolved.ok) {
|
|
185
|
+
return resolved.result;
|
|
186
|
+
}
|
|
187
|
+
const { snapshot } = resolved;
|
|
188
|
+
const target = spec.summarizeTarget(snapshot);
|
|
189
|
+
const precondition = spec.getPrecondition(snapshot);
|
|
190
|
+
const stateToken = await (0, request_state_js_1.mintDestructiveRequestState)({
|
|
191
|
+
operationId: spec.operationId,
|
|
192
|
+
resourceType: spec.resourceType,
|
|
193
|
+
resourceId: scopedArgs.resourceId,
|
|
194
|
+
projectUuid: scopedArgs.projectUuid,
|
|
195
|
+
preconditionDigest: precondition.digest,
|
|
196
|
+
subject: ctx.subject,
|
|
197
|
+
resourceName: target.resourceName,
|
|
198
|
+
}, serverContext);
|
|
199
|
+
return (0, server_1.inputRequired)({
|
|
200
|
+
requestState: stateToken,
|
|
201
|
+
inputRequests: {
|
|
202
|
+
[form.inputKey]: server_1.inputRequired.elicit({
|
|
203
|
+
mode: 'form',
|
|
204
|
+
message: form.buildMessage(target),
|
|
205
|
+
requestedSchema: form.formSchema,
|
|
206
|
+
}),
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
async function handleElicitationGatedMutation(server, ctx, rawArgs, gate) {
|
|
211
|
+
const { options, spec, form, labels } = gate;
|
|
212
|
+
const argsRecord = rawArgs;
|
|
213
|
+
const resourceId = argsRecord[options.resourceIdArgName];
|
|
214
|
+
if (typeof resourceId !== 'string' || resourceId.length === 0) {
|
|
215
|
+
return (0, reader_tool_helpers_js_1.codedErrorResult)('INVALID_ARGUMENT', `${options.resourceIdArgName} is required`);
|
|
216
|
+
}
|
|
217
|
+
const elicitationError = requireFormElicitation(server, ctx.serverContext, labels);
|
|
218
|
+
if (elicitationError) {
|
|
219
|
+
return elicitationError;
|
|
220
|
+
}
|
|
221
|
+
const serverContext = ctx.serverContext;
|
|
222
|
+
let scopedArgs;
|
|
223
|
+
try {
|
|
224
|
+
const scope = (0, project_scope_js_1.resolveProjectScope)({
|
|
225
|
+
projectUuid: typeof argsRecord.projectUuid === 'string' ? argsRecord.projectUuid : undefined,
|
|
226
|
+
});
|
|
227
|
+
scopedArgs = { projectUuid: scope.projectUuid, resourceId };
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
return (0, reader_tool_helpers_js_1.projectScopeErrorResult)(err);
|
|
231
|
+
}
|
|
232
|
+
const declineOrCancel = declineOrCancelIfPresent(serverContext, form.inputKey, labels, spec, scopedArgs);
|
|
233
|
+
if (declineOrCancel) {
|
|
234
|
+
return declineOrCancel;
|
|
235
|
+
}
|
|
236
|
+
const accepted = (0, server_1.acceptedContent)(serverContext.mcpReq.inputResponses, form.inputKey);
|
|
237
|
+
const boundState = await readBoundRequestState(serverContext);
|
|
238
|
+
if (accepted && boundState) {
|
|
239
|
+
return applyAcceptedMutation({
|
|
240
|
+
spec,
|
|
241
|
+
scopedArgs,
|
|
242
|
+
boundState,
|
|
243
|
+
accepted,
|
|
244
|
+
ctx,
|
|
245
|
+
form,
|
|
246
|
+
labels,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return requestConfirmation(spec, scopedArgs, ctx, serverContext, form);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Register a mutation tool that requires form elicitation before calling Lightdash.
|
|
253
|
+
*/
|
|
254
|
+
function registerElicitationGatedTool(server, shortName, contextProvider, gate) {
|
|
255
|
+
var _a;
|
|
256
|
+
const { options } = gate;
|
|
257
|
+
const inputSchema = {
|
|
258
|
+
projectUuid: (0, schema_fields_js_1.projectUuidField)().optional(),
|
|
259
|
+
[options.resourceIdArgName]: options.resourceIdField,
|
|
260
|
+
};
|
|
261
|
+
(0, shared_js_1.registerToolSafe)(server, shortName, {
|
|
262
|
+
title: options.title,
|
|
263
|
+
description: options.description,
|
|
264
|
+
annotations: Object.assign(Object.assign({}, ((_a = options.annotations) !== null && _a !== void 0 ? _a : common_1.WRITE_DESTRUCTIVE)), (options.idempotentHint === true ? { idempotentHint: true } : {})),
|
|
265
|
+
inputSchema,
|
|
266
|
+
}, (0, shared_js_1.wrapToolContextual)(contextProvider, (ctx) => async (rawArgs) => handleElicitationGatedMutation(server, ctx, rawArgs, gate)));
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Register a soft-delete tool that requires form elicitation before calling Lightdash DELETE.
|
|
270
|
+
*/
|
|
271
|
+
function registerDestructiveDeleteTool(server, shortName, options, contextProvider, spec) {
|
|
272
|
+
registerElicitationGatedTool(server, shortName, contextProvider, {
|
|
273
|
+
options: Object.assign(Object.assign({}, options), { idempotentHint: true }),
|
|
274
|
+
spec,
|
|
275
|
+
form: {
|
|
276
|
+
inputKey: types_js_1.CONFIRM_INPUT_KEY,
|
|
277
|
+
formSchema: confirmation_js_1.DELETE_CONFIRM_FORM_SCHEMA,
|
|
278
|
+
buildMessage: confirmation_js_1.buildDeleteConfirmationMessage,
|
|
279
|
+
isAcceptedForm: confirmation_js_1.isAcceptedDeleteForm,
|
|
280
|
+
},
|
|
281
|
+
labels: DELETE_GATE_LABELS,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC-signed requestState codec for destructive confirmation binding (ADR-0015).
|
|
3
|
+
* (SDK createRequestStateCodec signs; payload is not encrypted.)
|
|
4
|
+
*/
|
|
5
|
+
import type { DestructiveRequestState } from './types.js';
|
|
6
|
+
import type { RequestStateCodec, ServerContext } from '@modelcontextprotocol/server';
|
|
7
|
+
declare function getDestructiveRequestStateCodec(): RequestStateCodec<DestructiveRequestState>;
|
|
8
|
+
/** Reset codec (tests only). */
|
|
9
|
+
export declare function resetDestructiveRequestStateCodecForTests(): void;
|
|
10
|
+
export declare function mintDestructiveRequestState(state: DestructiveRequestState, serverContext: ServerContext): Promise<string>;
|
|
11
|
+
export declare function verifyDestructiveRequestState(token: string | undefined, serverContext: ServerContext): Promise<DestructiveRequestState | undefined>;
|
|
12
|
+
export { getDestructiveRequestStateCodec };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* HMAC-signed requestState codec for destructive confirmation binding (ADR-0015).
|
|
4
|
+
* (SDK createRequestStateCodec signs; payload is not encrypted.)
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resetDestructiveRequestStateCodecForTests = resetDestructiveRequestStateCodecForTests;
|
|
8
|
+
exports.mintDestructiveRequestState = mintDestructiveRequestState;
|
|
9
|
+
exports.verifyDestructiveRequestState = verifyDestructiveRequestState;
|
|
10
|
+
exports.getDestructiveRequestStateCodec = getDestructiveRequestStateCodec;
|
|
11
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
12
|
+
const request_state_key_js_1 = require("../auth/request-state-key.js");
|
|
13
|
+
const TTL_SECONDS = 10 * 60;
|
|
14
|
+
let codec;
|
|
15
|
+
function getDestructiveRequestStateCodec() {
|
|
16
|
+
if (!codec) {
|
|
17
|
+
codec = (0, server_1.createRequestStateCodec)({
|
|
18
|
+
key: (0, request_state_key_js_1.resolveRequestStateKey)(request_state_key_js_1.DESTRUCTIVE_REQUEST_STATE_KEY_PURPOSE),
|
|
19
|
+
ttlSeconds: TTL_SECONDS,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return codec;
|
|
23
|
+
}
|
|
24
|
+
/** Reset codec (tests only). */
|
|
25
|
+
function resetDestructiveRequestStateCodecForTests() {
|
|
26
|
+
codec = undefined;
|
|
27
|
+
}
|
|
28
|
+
async function mintDestructiveRequestState(state, serverContext) {
|
|
29
|
+
return getDestructiveRequestStateCodec().mint(state, serverContext);
|
|
30
|
+
}
|
|
31
|
+
async function verifyDestructiveRequestState(token, serverContext) {
|
|
32
|
+
if (token === undefined || token.length === 0) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return await getDestructiveRequestStateCodec().verify(token, serverContext);
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for elicitation-gated mutation MCP tools (ADR-0015 / ADR-0017).
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolExecutionContext } from '../tools/shared.js';
|
|
5
|
+
import type { AuditStatus } from '@lightdash-tools/common';
|
|
6
|
+
export type DestructiveResourceType = 'chart' | 'dashboard';
|
|
7
|
+
export type ConfirmationOperation = 'delete' | 'promote';
|
|
8
|
+
export type ConfirmationTarget = {
|
|
9
|
+
operation: ConfirmationOperation;
|
|
10
|
+
resourceType: DestructiveResourceType;
|
|
11
|
+
resourceId: string;
|
|
12
|
+
resourceName: string;
|
|
13
|
+
projectUuid: string;
|
|
14
|
+
location?: string;
|
|
15
|
+
updatedAt?: string;
|
|
16
|
+
consequences: string[];
|
|
17
|
+
/** Extra human-readable lines (e.g. promoteDiff summary). */
|
|
18
|
+
details?: string[];
|
|
19
|
+
};
|
|
20
|
+
export type ResourcePrecondition = {
|
|
21
|
+
resourceType: DestructiveResourceType;
|
|
22
|
+
resourceId: string;
|
|
23
|
+
projectUuid: string;
|
|
24
|
+
/** Opaque digest of material metadata (e.g. updatedAt + name + spaceUuid + promoteDiff). */
|
|
25
|
+
digest: string;
|
|
26
|
+
};
|
|
27
|
+
export type DestructiveOperationSpec<TArgs, TSnapshot> = {
|
|
28
|
+
operationId: string;
|
|
29
|
+
resourceType: DestructiveResourceType;
|
|
30
|
+
resolveTarget: (args: TArgs, ctx: ToolExecutionContext) => Promise<TSnapshot>;
|
|
31
|
+
summarizeTarget: (snapshot: TSnapshot) => ConfirmationTarget;
|
|
32
|
+
getPrecondition: (snapshot: TSnapshot) => ResourcePrecondition;
|
|
33
|
+
/**
|
|
34
|
+
* Perform the mutating API call. May return a receipt payload merged into the
|
|
35
|
+
* success structured content (e.g. upstream dashboard identity after promote).
|
|
36
|
+
*/
|
|
37
|
+
execute: (args: TArgs, snapshot: TSnapshot, ctx: ToolExecutionContext) => Promise<Record<string, unknown> | void>;
|
|
38
|
+
};
|
|
39
|
+
export type DestructiveRequestState = {
|
|
40
|
+
operationId: string;
|
|
41
|
+
resourceType: DestructiveResourceType;
|
|
42
|
+
resourceId: string;
|
|
43
|
+
projectUuid: string;
|
|
44
|
+
preconditionDigest: string;
|
|
45
|
+
/** Authenticated principal (not transport session) — ADR-0019. */
|
|
46
|
+
subject: string;
|
|
47
|
+
resourceName: string;
|
|
48
|
+
};
|
|
49
|
+
/** Soft-delete form input key (ADR-0015). */
|
|
50
|
+
export declare const CONFIRM_INPUT_KEY: "confirm_delete";
|
|
51
|
+
/** Dashboard promote form input key (ADR-0017). */
|
|
52
|
+
export declare const CONFIRM_PROMOTE_INPUT_KEY: "confirm_promote";
|
|
53
|
+
export type ElicitationGateLabels = {
|
|
54
|
+
operation: ConfirmationOperation;
|
|
55
|
+
successStatus: string;
|
|
56
|
+
successAudit: AuditStatus;
|
|
57
|
+
failureCode: string;
|
|
58
|
+
/** Stable client-facing message (never echo upstream exception text). */
|
|
59
|
+
failureMessage: string;
|
|
60
|
+
failureAudit: AuditStatus;
|
|
61
|
+
bindingMismatchMessage: string;
|
|
62
|
+
acceptMismatchMessage: string;
|
|
63
|
+
resourceChangedMessage: string;
|
|
64
|
+
elicitationRequiredMessage: string;
|
|
65
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared types for elicitation-gated mutation MCP tools (ADR-0015 / ADR-0017).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CONFIRM_PROMOTE_INPUT_KEY = exports.CONFIRM_INPUT_KEY = void 0;
|
|
7
|
+
/** Soft-delete form input key (ADR-0015). */
|
|
8
|
+
exports.CONFIRM_INPUT_KEY = 'confirm_delete';
|
|
9
|
+
/** Dashboard promote form input key (ADR-0017). */
|
|
10
|
+
exports.CONFIRM_PROMOTE_INPUT_KEY = 'confirm_promote';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared project allowlist for MCP (ADR-0008).
|
|
3
|
+
*
|
|
4
|
+
* Canonical: `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS` (same env as CLI).
|
|
5
|
+
* Unset/empty → unrestricted. Non-empty → hard ceiling for all personas.
|
|
6
|
+
* UUIDs normalized to lowercase; invalid / empty segments fail closed.
|
|
7
|
+
*
|
|
8
|
+
* Removed envs fail at startup if still set:
|
|
9
|
+
* - `LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS`
|
|
10
|
+
* - `LIGHTDASH_TOOLS_ALLOWED_PROJECTS`
|
|
11
|
+
*/
|
|
12
|
+
export declare const ENV_ALLOWED_PROJECT_UUIDS = "LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS";
|
|
13
|
+
export declare class AvailableProjectsConfigError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export type AvailableProjectsPolicy = {
|
|
17
|
+
restricted: false;
|
|
18
|
+
} | {
|
|
19
|
+
restricted: true;
|
|
20
|
+
uuids: ReadonlySet<string>;
|
|
21
|
+
list: readonly string[];
|
|
22
|
+
};
|
|
23
|
+
/** Clear process-env policy cache (tests only). */
|
|
24
|
+
export declare function resetAvailableProjectsCache(): void;
|
|
25
|
+
/** Parsed allowlist policy (cached for `process.env`). */
|
|
26
|
+
export declare function getAvailableProjectsPolicy(env?: NodeJS.ProcessEnv): AvailableProjectsPolicy;
|
|
27
|
+
export declare function isProjectAvailable(uuid: string, env?: NodeJS.ProcessEnv): boolean;
|
|
28
|
+
export declare function findUnavailableProjectUuids(uuids: readonly string[], env?: NodeJS.ProcessEnv): string[];
|
|
29
|
+
export declare function filterProjectsByAvailability<T extends {
|
|
30
|
+
projectUuid: string;
|
|
31
|
+
}>(projects: readonly T[], env?: NodeJS.ProcessEnv): T[];
|
|
32
|
+
export declare function resolveSearchProjectUuids(input: {
|
|
33
|
+
pinned?: string;
|
|
34
|
+
explicit?: readonly string[];
|
|
35
|
+
}, env?: NodeJS.ProcessEnv): string[] | undefined;
|
|
36
|
+
/** Fail-closed startup: reject removed envs; validate ALLOWED_PROJECT_UUIDS. */
|
|
37
|
+
export declare function validateAvailableProjectsConfig(env?: NodeJS.ProcessEnv): void;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared project allowlist for MCP (ADR-0008).
|
|
4
|
+
*
|
|
5
|
+
* Canonical: `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS` (same env as CLI).
|
|
6
|
+
* Unset/empty → unrestricted. Non-empty → hard ceiling for all personas.
|
|
7
|
+
* UUIDs normalized to lowercase; invalid / empty segments fail closed.
|
|
8
|
+
*
|
|
9
|
+
* Removed envs fail at startup if still set:
|
|
10
|
+
* - `LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS`
|
|
11
|
+
* - `LIGHTDASH_TOOLS_ALLOWED_PROJECTS`
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.AvailableProjectsConfigError = exports.ENV_ALLOWED_PROJECT_UUIDS = void 0;
|
|
15
|
+
exports.resetAvailableProjectsCache = resetAvailableProjectsCache;
|
|
16
|
+
exports.getAvailableProjectsPolicy = getAvailableProjectsPolicy;
|
|
17
|
+
exports.isProjectAvailable = isProjectAvailable;
|
|
18
|
+
exports.findUnavailableProjectUuids = findUnavailableProjectUuids;
|
|
19
|
+
exports.filterProjectsByAvailability = filterProjectsByAvailability;
|
|
20
|
+
exports.resolveSearchProjectUuids = resolveSearchProjectUuids;
|
|
21
|
+
exports.validateAvailableProjectsConfig = validateAvailableProjectsConfig;
|
|
22
|
+
const common_1 = require("@lightdash-tools/common");
|
|
23
|
+
exports.ENV_ALLOWED_PROJECT_UUIDS = common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
|
|
24
|
+
/** Removed env — fail closed at validate if still present. */
|
|
25
|
+
const ENV_MCP_AVAILABLE_PROJECT_UUIDS_REMOVED = 'LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS';
|
|
26
|
+
/** Previous shared allowlist name — fail closed at validate if still present. */
|
|
27
|
+
const ENV_ALLOWED_PROJECTS_REMOVED = 'LIGHTDASH_TOOLS_ALLOWED_PROJECTS';
|
|
28
|
+
class AvailableProjectsConfigError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = 'AvailableProjectsConfigError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.AvailableProjectsConfigError = AvailableProjectsConfigError;
|
|
35
|
+
let processCache;
|
|
36
|
+
/** Clear process-env policy cache (tests only). */
|
|
37
|
+
function resetAvailableProjectsCache() {
|
|
38
|
+
processCache = undefined;
|
|
39
|
+
}
|
|
40
|
+
function parsePolicy(raw, envLabel) {
|
|
41
|
+
if (raw === undefined || raw.trim() === '') {
|
|
42
|
+
return { restricted: false };
|
|
43
|
+
}
|
|
44
|
+
const parts = raw.split(',').map((s) => s.trim());
|
|
45
|
+
if (parts.some((part) => part === '')) {
|
|
46
|
+
throw new AvailableProjectsConfigError(`${envLabel} must be a non-empty comma-separated list of UUIDs (empty segments are not allowed)`);
|
|
47
|
+
}
|
|
48
|
+
const normalized = [];
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
for (const part of parts) {
|
|
51
|
+
let uuid;
|
|
52
|
+
try {
|
|
53
|
+
uuid = (0, common_1.validateUuid)(part).toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
throw new AvailableProjectsConfigError(`${envLabel} contains invalid UUID '${part}'`);
|
|
57
|
+
}
|
|
58
|
+
if (!seen.has(uuid)) {
|
|
59
|
+
seen.add(uuid);
|
|
60
|
+
normalized.push(uuid);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { restricted: true, uuids: seen, list: normalized };
|
|
64
|
+
}
|
|
65
|
+
function resolveAllowlist(env) {
|
|
66
|
+
const raw = env.LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS;
|
|
67
|
+
if (raw === undefined || raw.trim() === '') {
|
|
68
|
+
return { raw: '', policy: { restricted: false } };
|
|
69
|
+
}
|
|
70
|
+
return { raw };
|
|
71
|
+
}
|
|
72
|
+
/** Parsed allowlist policy (cached for `process.env`). */
|
|
73
|
+
function getAvailableProjectsPolicy(env = process.env) {
|
|
74
|
+
var _a;
|
|
75
|
+
const resolved = resolveAllowlist(env);
|
|
76
|
+
if (env === process.env && (processCache === null || processCache === void 0 ? void 0 : processCache.raw) === resolved.raw) {
|
|
77
|
+
return processCache.policy;
|
|
78
|
+
}
|
|
79
|
+
const policy = (_a = resolved.policy) !== null && _a !== void 0 ? _a : parsePolicy(resolved.raw || undefined, exports.ENV_ALLOWED_PROJECT_UUIDS);
|
|
80
|
+
if (env === process.env) {
|
|
81
|
+
processCache = { raw: resolved.raw, policy };
|
|
82
|
+
}
|
|
83
|
+
return policy;
|
|
84
|
+
}
|
|
85
|
+
function isProjectAvailable(uuid, env = process.env) {
|
|
86
|
+
const policy = getAvailableProjectsPolicy(env);
|
|
87
|
+
if (!policy.restricted) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return policy.uuids.has(uuid.toLowerCase());
|
|
91
|
+
}
|
|
92
|
+
function findUnavailableProjectUuids(uuids, env = process.env) {
|
|
93
|
+
const policy = getAvailableProjectsPolicy(env);
|
|
94
|
+
if (!policy.restricted) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return uuids.filter((uuid) => !policy.uuids.has(uuid.toLowerCase()));
|
|
98
|
+
}
|
|
99
|
+
function filterProjectsByAvailability(projects, env = process.env) {
|
|
100
|
+
const policy = getAvailableProjectsPolicy(env);
|
|
101
|
+
if (!policy.restricted) {
|
|
102
|
+
return projects;
|
|
103
|
+
}
|
|
104
|
+
return projects.filter((p) => policy.uuids.has(p.projectUuid.toLowerCase()));
|
|
105
|
+
}
|
|
106
|
+
function resolveSearchProjectUuids(input, env = process.env) {
|
|
107
|
+
if (input.pinned) {
|
|
108
|
+
return [input.pinned.toLowerCase()];
|
|
109
|
+
}
|
|
110
|
+
if (input.explicit && input.explicit.length > 0) {
|
|
111
|
+
return input.explicit.map((u) => u.toLowerCase());
|
|
112
|
+
}
|
|
113
|
+
const policy = getAvailableProjectsPolicy(env);
|
|
114
|
+
if (policy.restricted) {
|
|
115
|
+
return [...policy.list];
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
/** Fail-closed startup: reject removed envs; validate ALLOWED_PROJECT_UUIDS. */
|
|
120
|
+
function validateAvailableProjectsConfig(env = process.env) {
|
|
121
|
+
const removedMcp = env.LIGHTDASH_TOOLS_MCP_AVAILABLE_PROJECT_UUIDS;
|
|
122
|
+
if (removedMcp !== undefined && removedMcp.trim() !== '') {
|
|
123
|
+
throw new AvailableProjectsConfigError(`${ENV_MCP_AVAILABLE_PROJECT_UUIDS_REMOVED} is no longer supported. ` +
|
|
124
|
+
`Use ${exports.ENV_ALLOWED_PROJECT_UUIDS} instead.`);
|
|
125
|
+
}
|
|
126
|
+
const removedLegacy = env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
|
|
127
|
+
if (removedLegacy !== undefined && removedLegacy.trim() !== '') {
|
|
128
|
+
throw new AvailableProjectsConfigError(`${ENV_ALLOWED_PROJECTS_REMOVED} is no longer supported. ` +
|
|
129
|
+
`Use ${exports.ENV_ALLOWED_PROJECT_UUIDS} instead.`);
|
|
130
|
+
}
|
|
131
|
+
getAvailableProjectsPolicy(env);
|
|
132
|
+
}
|