@lightdash-tools/mcp 0.8.0 → 0.11.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 +112 -236
- package/dist/audit/server-profile.d.ts +13 -0
- package/dist/audit/server-profile.js +28 -0
- package/dist/audit/server-profile.test.js +21 -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 +1 -3
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +1 -20
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +14 -14
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +6 -6
- package/dist/auth/resource-server/oauth-protected-resource.js +8 -8
- package/dist/auth/resource-server/token-scopes.d.ts +1 -1
- package/dist/auth/resource-server/token-scopes.js +1 -1
- package/dist/auth/resource-server/www-authenticate.test.js +11 -13
- package/dist/bin.js +54 -51
- package/dist/config/env.d.ts +8 -16
- package/dist/config/env.js +9 -17
- package/dist/config/load-mcp-config.d.ts +0 -4
- package/dist/config/load-mcp-config.js +9 -38
- package/dist/config/load-mcp-config.test.js +8 -2
- package/dist/config/normalize-url.d.ts +1 -1
- package/dist/config/normalize-url.js +1 -1
- package/dist/config/normalize-url.test.js +16 -13
- package/dist/config/obsolete-env.d.ts +5 -0
- package/dist/config/obsolete-env.js +48 -0
- package/dist/config/obsolete-env.test.js +22 -0
- 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/mcp-client-session.d.ts +3 -2
- package/dist/governance/mcp-client-session.js +3 -2
- package/dist/governance/mcp-post-factory-context.d.ts +15 -0
- package/dist/governance/mcp-post-factory-context.js +22 -0
- package/dist/governance/mcp-post-factory-context.test.js +34 -0
- 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 +116 -265
- package/dist/http.test.js +0 -12
- package/dist/index.d.ts +5 -1
- package/dist/index.integration.test.js +0 -4
- package/dist/index.js +31 -16
- 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 +15 -6
- package/dist/policy/content-reader.js +39 -10
- package/dist/policy/content-reader.test.js +5 -3
- package/dist/policy/envelope.d.ts +4 -2
- package/dist/policy/envelope.js +2 -2
- package/dist/policy/envelope.test.js +28 -0
- 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/profiles/ai-agent-ops/v1/index.d.ts +6 -0
- package/dist/profiles/ai-agent-ops/v1/index.js +20 -0
- package/dist/profiles/ai-agent-ops/v1/prompts.d.ts +5 -0
- package/dist/profiles/ai-agent-ops/v1/prompts.js +141 -0
- package/dist/profiles/ai-agent-ops/v1/prompts.test.d.ts +4 -0
- package/dist/profiles/ai-agent-ops/v1/prompts.test.js +26 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks.js +41 -0
- package/dist/profiles/content-developer/v1/index.d.ts +8 -0
- package/dist/profiles/content-developer/v1/index.js +22 -0
- package/dist/{personas → profiles}/content-developer/v1/prompts.d.ts +3 -0
- package/dist/profiles/content-developer/v1/prompts.js +157 -0
- package/dist/profiles/content-developer/v1/prompts.test.js +286 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/chart-types.md +138 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/content-move.md +22 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/core.md +109 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/dashboards.md +108 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/index.md +15 -0
- package/dist/{personas → profiles}/content-developer/v1/resources/playbooks.d.ts +1 -1
- package/dist/profiles/content-developer/v1/resources/playbooks.js +65 -0
- package/dist/profiles/content-governance/v1/index.d.ts +7 -0
- package/dist/profiles/content-governance/v1/index.js +21 -0
- package/dist/{personas → profiles}/content-governance/v1/prompts.test.js +2 -2
- package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/core.md +3 -3
- package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/dashboards.md +1 -1
- package/dist/{personas → profiles}/content-governance/v1/resources/playbooks.js +4 -4
- package/dist/profiles/content-reader/v1/index.d.ts +6 -0
- package/dist/profiles/content-reader/v1/index.js +20 -0
- package/dist/profiles/content-reader/v1/prompts.js +162 -0
- package/dist/{personas → profiles}/content-reader/v1/prompts.test.js +2 -2
- package/dist/profiles/content-reader/v1/resources/playbooks/compare.md +36 -0
- package/dist/profiles/content-reader/v1/resources/playbooks/core.md +67 -0
- package/dist/profiles/content-reader/v1/resources/playbooks/discover.md +35 -0
- package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +49 -0
- package/dist/profiles/content-reader/v1/resources/playbooks/index.md +14 -0
- package/dist/{personas → profiles}/content-reader/v1/resources/playbooks.js +4 -4
- package/dist/profiles/data-analyst/v1/index.d.ts +6 -0
- package/dist/profiles/data-analyst/v1/index.js +20 -0
- package/dist/profiles/data-analyst/v1/prompts.d.ts +5 -0
- package/dist/profiles/data-analyst/v1/prompts.js +41 -0
- package/dist/profiles/data-analyst/v1/prompts.test.d.ts +4 -0
- package/dist/profiles/data-analyst/v1/prompts.test.js +26 -0
- package/dist/profiles/data-analyst/v1/resources/playbooks/core.md +41 -0
- package/dist/profiles/data-analyst/v1/resources/playbooks/explore.md +26 -0
- package/dist/profiles/data-analyst/v1/resources/playbooks/index.md +8 -0
- package/dist/profiles/data-analyst/v1/resources/playbooks.d.ts +10 -0
- package/dist/profiles/data-analyst/v1/resources/playbooks.js +33 -0
- package/dist/profiles/index.d.ts +24 -0
- package/dist/profiles/index.js +73 -0
- package/dist/profiles/index.test.js +121 -0
- package/dist/{personas → profiles}/lib/playbook-resources.d.ts +12 -10
- package/dist/{personas → profiles}/lib/playbook-resources.js +28 -24
- package/dist/profiles/organization-audit/v1/index.d.ts +6 -0
- package/dist/profiles/organization-audit/v1/index.js +20 -0
- package/dist/profiles/organization-audit/v1/prompts.js +124 -0
- package/dist/{personas → profiles}/organization-audit/v1/prompts.test.js +2 -2
- package/dist/profiles/organization-audit/v1/resources/playbooks/access.md +21 -0
- package/dist/profiles/organization-audit/v1/resources/playbooks/content.md +19 -0
- package/dist/profiles/organization-audit/v1/resources/playbooks/core.md +69 -0
- package/dist/profiles/organization-audit/v1/resources/playbooks/deliveries.md +14 -0
- package/dist/profiles/organization-audit/v1/resources/playbooks/index.md +14 -0
- package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks.js +3 -3
- package/dist/profiles/profile.membership.test.js +36 -0
- package/dist/profiles/semantic-layer/v1/index.d.ts +6 -0
- package/dist/profiles/semantic-layer/v1/index.js +19 -0
- package/dist/profiles/semantic-layer/v1/prompts.js +96 -0
- package/dist/{personas → profiles}/semantic-layer/v1/prompts.test.js +2 -2
- package/dist/profiles/semantic-layer/v1/resources/playbooks/compose-compile.md +60 -0
- package/dist/profiles/semantic-layer/v1/resources/playbooks/core.md +71 -0
- package/dist/profiles/semantic-layer/v1/resources/playbooks/explore.md +79 -0
- package/dist/profiles/semantic-layer/v1/resources/playbooks/index.md +13 -0
- package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks.js +4 -4
- package/dist/{personas → profiles}/types.d.ts +6 -7
- package/dist/{personas → profiles}/types.js +1 -1
- package/dist/protocol-contract.test.js +48 -3
- package/dist/server/capabilities.d.ts +6 -6
- package/dist/server/capabilities.js +11 -8
- package/dist/server/capabilities.test.js +8 -7
- package/dist/server/server.js +17 -13
- 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 +65 -9
- 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 +63 -0
- package/dist/tools/ai-agents/helpers.js +321 -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.js +3 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.test.js +16 -10
- package/dist/tools/lib/schema-fields.d.ts +2 -0
- package/dist/tools/lib/schema-fields.js +4 -1
- package/dist/tools/lib/stable-stringify.d.ts +1 -1
- package/dist/tools/lib/stable-stringify.js +1 -1
- package/dist/tools/organization/invariants.test.d.ts +1 -1
- package/dist/tools/organization/invariants.test.js +5 -5
- 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 +3 -2
- package/dist/tools/project/developer-content-preview.js +41 -36
- package/dist/tools/project/developer-content-shared.d.ts +9 -3
- package/dist/tools/project/developer-content-shared.js +8 -4
- 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.d.ts +1 -1
- package/dist/tools/project/invariants.test.js +12 -10
- package/dist/tools/project/parameters.js +8 -3
- package/dist/tools/project/projects.d.ts +1 -4
- package/dist/tools/project/projects.js +37 -15
- package/dist/tools/project/projects.test.js +70 -8
- package/dist/tools/project/reader-content.js +6 -3
- package/dist/tools/project/reader-execution.js +4 -2
- 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/spaces.js +12 -4
- package/dist/tools/project/spaces.test.d.ts +1 -0
- package/dist/tools/project/spaces.test.js +47 -0
- package/dist/tools/query/bounded-saved-query.d.ts +4 -3
- package/dist/tools/query/bounded-saved-query.js +4 -6
- package/dist/tools/query/lifecycle.d.ts +1 -1
- package/dist/tools/query/lifecycle.js +25 -31
- package/dist/tools/query/query-ledger.d.ts +17 -9
- 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.d.ts +4 -2
- package/dist/tools/query/reader-tool-helpers.js +11 -8
- package/dist/tools/query/reader-tool-helpers.test.js +8 -4
- package/dist/tools/query/run-metric-query.d.ts +6 -0
- package/dist/tools/query/run-metric-query.js +94 -0
- package/dist/tools/query/run-metric-query.test.d.ts +4 -0
- package/dist/tools/query/run-metric-query.test.js +116 -0
- package/dist/tools/registry.d.ts +71 -8
- package/dist/tools/registry.js +36 -6
- package/dist/tools/semantic/explores.js +43 -17
- package/dist/tools/semantic/metrics.js +22 -8
- package/dist/tools/semantic/query.js +25 -17
- package/dist/tools/shared.d.ts +28 -9
- package/dist/tools/shared.js +62 -29
- package/dist/tools/shared.test.js +100 -4
- package/dist/transports/streamable-http.js +75 -223
- package/dist/transports/streamable-http.test.js +19 -12
- 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/personas/content-developer/v1/index.d.ts +0 -10
- package/dist/personas/content-developer/v1/index.js +0 -51
- package/dist/personas/content-developer/v1/prompts.js +0 -138
- package/dist/personas/content-developer/v1/prompts.test.js +0 -75
- package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +0 -15
- package/dist/personas/content-developer/v1/resources/playbooks/core.md +0 -63
- package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +0 -55
- package/dist/personas/content-developer/v1/resources/playbooks/index.md +0 -13
- package/dist/personas/content-developer/v1/resources/playbooks.js +0 -44
- package/dist/personas/content-governance/v1/index.d.ts +0 -9
- package/dist/personas/content-governance/v1/index.js +0 -29
- package/dist/personas/content-reader/v1/index.d.ts +0 -8
- package/dist/personas/content-reader/v1/index.js +0 -37
- package/dist/personas/content-reader/v1/prompts.js +0 -128
- package/dist/personas/content-reader/v1/resources/playbooks/compare.md +0 -21
- package/dist/personas/content-reader/v1/resources/playbooks/core.md +0 -40
- package/dist/personas/content-reader/v1/resources/playbooks/discover.md +0 -13
- package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +0 -19
- package/dist/personas/content-reader/v1/resources/playbooks/index.md +0 -14
- package/dist/personas/index.d.ts +0 -22
- package/dist/personas/index.js +0 -73
- package/dist/personas/index.test.js +0 -109
- package/dist/personas/organization-audit/v1/index.d.ts +0 -8
- package/dist/personas/organization-audit/v1/index.js +0 -42
- package/dist/personas/organization-audit/v1/prompts.js +0 -92
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +0 -13
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +0 -9
- package/dist/personas/organization-audit/v1/resources/playbooks/core.md +0 -36
- package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +0 -9
- package/dist/personas/organization-audit/v1/resources/playbooks/index.md +0 -14
- package/dist/personas/persona.parity.test.js +0 -26
- package/dist/personas/semantic-layer/v1/index.d.ts +0 -8
- package/dist/personas/semantic-layer/v1/index.js +0 -32
- package/dist/personas/semantic-layer/v1/prompts.js +0 -85
- package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +0 -55
- package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +0 -39
- package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +0 -76
- package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +0 -13
- 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.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.js +0 -111
- /package/dist/{destructive/confirmation-claim.test.d.ts → audit/server-profile.test.d.ts} +0 -0
- /package/dist/{personas/index.test.d.ts → config/obsolete-env.test.d.ts} +0 -0
- /package/dist/{personas/persona.parity.test.d.ts → governance/mcp-post-factory-context.test.d.ts} +0 -0
- /package/dist/{store/config.test.d.ts → policy/envelope.test.d.ts} +0 -0
- /package/dist/{personas → profiles}/content-developer/v1/prompts.test.d.ts +0 -0
- /package/dist/{personas → profiles}/content-governance/v1/prompts.d.ts +0 -0
- /package/dist/{personas → profiles}/content-governance/v1/prompts.js +0 -0
- /package/dist/{personas → profiles}/content-governance/v1/prompts.test.d.ts +0 -0
- /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/charts.md +0 -0
- /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks/index.md +0 -0
- /package/dist/{personas → profiles}/content-governance/v1/resources/playbooks.d.ts +0 -0
- /package/dist/{personas → profiles}/content-reader/v1/prompts.d.ts +0 -0
- /package/dist/{personas → profiles}/content-reader/v1/prompts.test.d.ts +0 -0
- /package/dist/{personas → profiles}/content-reader/v1/resources/playbooks.d.ts +0 -0
- /package/dist/{store/redis-oauth-broker-store.test.d.ts → profiles/index.test.d.ts} +0 -0
- /package/dist/{personas → profiles}/organization-audit/v1/prompts.d.ts +0 -0
- /package/dist/{personas → profiles}/organization-audit/v1/prompts.test.d.ts +0 -0
- /package/dist/{personas → profiles}/organization-audit/v1/resources/playbooks.d.ts +0 -0
- /package/dist/{store/redis-preview-store.test.d.ts → profiles/profile.membership.test.d.ts} +0 -0
- /package/dist/{personas → profiles}/semantic-layer/v1/prompts.d.ts +0 -0
- /package/dist/{personas → profiles}/semantic-layer/v1/prompts.test.d.ts +0 -0
- /package/dist/{personas → profiles}/semantic-layer/v1/resources/playbooks.d.ts +0 -0
- /package/dist/{transports/session-store.test.d.ts → server/upstream-errors.test.d.ts} +0 -0
|
@@ -2,31 +2,41 @@
|
|
|
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");
|
|
7
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
8
8
|
const audit_js_1 = require("../audit/audit.js");
|
|
9
9
|
const tool_audit_context_js_1 = require("../audit/tool-audit-context.js");
|
|
10
10
|
const auth_mode_js_1 = require("../auth/auth-mode.js");
|
|
11
11
|
const routes_js_1 = require("../auth/oauth-broker/routes.js");
|
|
12
12
|
const bearer_context_provider_js_1 = require("../auth/providers/bearer-context-provider.js");
|
|
13
13
|
const env_context_provider_js_1 = require("../auth/providers/env-context-provider.js");
|
|
14
|
+
const request_state_key_js_1 = require("../auth/request-state-key.js");
|
|
14
15
|
const lightdash_oauth_middleware_js_1 = require("../auth/resource-server/lightdash-oauth-middleware.js");
|
|
15
16
|
const oauth_protected_resource_js_1 = require("../auth/resource-server/oauth-protected-resource.js");
|
|
16
17
|
const shared_key_middleware_js_1 = require("../auth/resource-server/shared-key-middleware.js");
|
|
17
18
|
const token_hash_js_1 = require("../auth/token-hash.js");
|
|
18
19
|
const load_mcp_config_js_1 = require("../config/load-mcp-config.js");
|
|
19
20
|
const runtime_js_1 = require("../config/runtime.js");
|
|
21
|
+
const available_projects_js_1 = require("../governance/available-projects.js");
|
|
22
|
+
const mcp_post_factory_context_js_1 = require("../governance/mcp-post-factory-context.js");
|
|
20
23
|
const project_pin_js_1 = require("../governance/project-pin.js");
|
|
21
|
-
const index_js_1 = require("../
|
|
24
|
+
const index_js_1 = require("../profiles/index.js");
|
|
22
25
|
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
26
|
const http_body_js_1 = require("./http-body.js");
|
|
27
|
-
const http_request_utils_js_1 = require("./http-request-utils.js");
|
|
28
27
|
const http_response_js_1 = require("./http-response.js");
|
|
29
|
-
|
|
28
|
+
function reportMcpHttpError(error) {
|
|
29
|
+
console.error('MCP HTTP error:', error);
|
|
30
|
+
}
|
|
31
|
+
function createProcessMcpHttpHandler() {
|
|
32
|
+
return (0, server_1.createMcpHandler)(() => {
|
|
33
|
+
const store = (0, mcp_post_factory_context_js_1.getMcpPostFactoryStore)();
|
|
34
|
+
if (!store) {
|
|
35
|
+
throw new Error('MCP request factory context is missing');
|
|
36
|
+
}
|
|
37
|
+
return (0, server_js_1.createLightdashMcpServer)(store.contextProvider, { profile: store.profile });
|
|
38
|
+
}, { legacy: 'stateless', onerror: reportMcpHttpError });
|
|
39
|
+
}
|
|
30
40
|
function listen(server, port, host) {
|
|
31
41
|
return new Promise((resolve, reject) => {
|
|
32
42
|
server.once('error', reject);
|
|
@@ -59,55 +69,12 @@ function resolveHttpConfig(config, listenPort) {
|
|
|
59
69
|
const listenHost = resolveListenHost(config.host);
|
|
60
70
|
return Object.assign(Object.assign({}, config), { publicUrl: resolvePublicUrl(config.publicUrl, listenHost, listenPort) });
|
|
61
71
|
}
|
|
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
72
|
function createEnvContextProvider(config) {
|
|
67
73
|
return new env_context_provider_js_1.EnvContextProvider({
|
|
68
74
|
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
75
|
client: (0, runtime_js_1.getClient)(),
|
|
70
76
|
});
|
|
71
77
|
}
|
|
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
78
|
function handleHealth(path, res, config) {
|
|
112
79
|
if (path === '/health/live') {
|
|
113
80
|
(0, http_response_js_1.sendJson)(res, 200, { status: 'ok' });
|
|
@@ -124,7 +91,7 @@ function handleHealth(path, res, config) {
|
|
|
124
91
|
}
|
|
125
92
|
}
|
|
126
93
|
/**
|
|
127
|
-
* Auth helpers for
|
|
94
|
+
* Auth helpers for profile MCP routes. PRM path resolution lives in
|
|
128
95
|
* `oauth-protected-resource.ts` (single owner for well-known PRM grammar).
|
|
129
96
|
*/
|
|
130
97
|
async function ensureEndpointAuth(req, res, config, mcpPath) {
|
|
@@ -157,103 +124,33 @@ function getOAuthAuditContext(req) {
|
|
|
157
124
|
subject: oauth.user.userUuid,
|
|
158
125
|
};
|
|
159
126
|
}
|
|
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
|
-
}
|
|
127
|
+
/**
|
|
128
|
+
* Creates a fresh context provider for the current request.
|
|
129
|
+
* For OAuth, uses the bearer token from this request directly.
|
|
130
|
+
* For shared-key/none, uses the env-based provider.
|
|
131
|
+
*/
|
|
132
|
+
function createContextProviderForRequest(config, req) {
|
|
222
133
|
if (config.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
134
|
+
const oauth = req.lightdashOAuth;
|
|
135
|
+
if (oauth === null || oauth === void 0 ? void 0 : oauth.ok) {
|
|
136
|
+
return (0, bearer_context_provider_js_1.createOAuthBearerProvider)(config, {
|
|
137
|
+
accessToken: oauth.accessToken,
|
|
138
|
+
subject: oauth.user.userUuid,
|
|
139
|
+
});
|
|
227
140
|
}
|
|
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;
|
|
141
|
+
throw new Error('OAuth auth mode requires authenticated request context');
|
|
243
142
|
}
|
|
244
|
-
|
|
245
|
-
mode: config.authMode,
|
|
246
|
-
}, persona);
|
|
247
|
-
await transport.handleRequest(req, res, body);
|
|
143
|
+
return createEnvContextProvider(config);
|
|
248
144
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Auth / Origin / pin run outside the handler. ALS supplies profile + provider
|
|
147
|
+
* so the process-lifetime createMcpHandler factory can build a fresh McpServer.
|
|
148
|
+
*/
|
|
149
|
+
async function handleMcpPost(ctx) {
|
|
150
|
+
const { req, res, config, profile, nodeHandler } = ctx;
|
|
151
|
+
if (!(await ensureEndpointAuth(req, res, config, profile.path))) {
|
|
152
|
+
(0, http_body_js_1.drainRequestBody)(req);
|
|
153
|
+
return;
|
|
257
154
|
}
|
|
258
155
|
const raw = await (0, http_body_js_1.readBody)(req, res, config.maxBodyBytes);
|
|
259
156
|
if (raw === undefined)
|
|
@@ -268,65 +165,25 @@ async function handleMcpPost(ctx, sid) {
|
|
|
268
165
|
return;
|
|
269
166
|
}
|
|
270
167
|
}
|
|
271
|
-
|
|
272
|
-
await handleExistingSessionPost(ctx, sid, body);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
if (body !== undefined && (0, http_request_utils_js_1.isInitializeMessage)(body)) {
|
|
276
|
-
await handleInitializePost(ctx, body);
|
|
277
|
-
return;
|
|
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;
|
|
293
|
-
}
|
|
294
|
-
const entry = sessionStore.get(sid);
|
|
295
|
-
if (!entry || entry.personaId !== persona.id) {
|
|
296
|
-
(0, http_response_js_1.sendJson)(res, 404, { error: ERROR_SESSION_NOT_FOUND });
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (!verifySessionAuth(req, res, config, persona.path, entry))
|
|
300
|
-
return;
|
|
301
|
-
sessionStore.touch(sid);
|
|
168
|
+
const contextProvider = createContextProviderForRequest(config, req);
|
|
302
169
|
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));
|
|
170
|
+
await (0, mcp_post_factory_context_js_1.runWithMcpPostFactoryAsync)({ contextProvider, profile }, () => (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)(auditAuth, () => nodeHandler(req, res, body)));
|
|
307
171
|
}
|
|
308
172
|
async function createStreamableHttpServer(config) {
|
|
309
173
|
var _a;
|
|
310
174
|
const inputConfig = config !== null && config !== void 0 ? config : (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
311
175
|
(0, load_mcp_config_js_1.emitMcpHttpSecurityWarnings)(inputConfig);
|
|
176
|
+
(0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
|
|
177
|
+
(0, available_projects_js_1.validateAvailableProjectsConfig)();
|
|
178
|
+
(0, request_state_key_js_1.assertHttpSignedStateKeyConfigured)();
|
|
312
179
|
(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
180
|
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
181
|
let oauthBroker;
|
|
182
|
+
const mcpHttpHandler = createProcessMcpHttpHandler();
|
|
183
|
+
const mcpNodeHandler = (0, node_1.toNodeHandler)(mcpHttpHandler, { onerror: reportMcpHttpError });
|
|
327
184
|
const server = (0, node_http_1.createServer)((req, res) => {
|
|
328
|
-
handleHttpRequest(req, res, httpConfig,
|
|
329
|
-
|
|
185
|
+
handleHttpRequest(req, res, httpConfig, oauthBroker, mcpNodeHandler).catch((err) => {
|
|
186
|
+
reportMcpHttpError(err);
|
|
330
187
|
if (!res.headersSent) {
|
|
331
188
|
(0, http_response_js_1.sendJson)(res, 500, { error: 'Internal Server Error' });
|
|
332
189
|
}
|
|
@@ -338,30 +195,31 @@ async function createStreamableHttpServer(config) {
|
|
|
338
195
|
httpConfig = resolveHttpConfig(inputConfig, port);
|
|
339
196
|
const baseUrl = (_a = httpConfig.publicUrl) !== null && _a !== void 0 ? _a : `http://${resolveListenHost(httpConfig.host)}:${port}`;
|
|
340
197
|
if (httpConfig.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
341
|
-
oauthBroker = (0, routes_js_1.createOAuthBroker)(httpConfig
|
|
198
|
+
oauthBroker = (0, routes_js_1.createOAuthBroker)(httpConfig);
|
|
342
199
|
}
|
|
343
200
|
return {
|
|
344
201
|
port,
|
|
345
202
|
baseUrl,
|
|
346
203
|
config: httpConfig,
|
|
347
|
-
close:
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
closeSessionEntry(entry, sessionId, 'shutdown');
|
|
204
|
+
close: async () => {
|
|
205
|
+
await mcpHttpHandler.close().catch((err) => {
|
|
206
|
+
reportMcpHttpError(err);
|
|
351
207
|
});
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
208
|
+
await new Promise((resolve, reject) => {
|
|
209
|
+
server.close((err) => {
|
|
210
|
+
if (err)
|
|
211
|
+
reject(err);
|
|
212
|
+
else
|
|
213
|
+
resolve();
|
|
214
|
+
});
|
|
357
215
|
});
|
|
358
|
-
}
|
|
216
|
+
},
|
|
359
217
|
};
|
|
360
218
|
}
|
|
361
219
|
function startStreamableHttpServer(config) {
|
|
362
220
|
void createStreamableHttpServer(config)
|
|
363
221
|
.then(({ baseUrl, config: httpConfig }) => {
|
|
364
|
-
const paths = (0, index_js_1.
|
|
222
|
+
const paths = (0, index_js_1.listProfilePaths)()
|
|
365
223
|
.map((p) => `${baseUrl}${p}`)
|
|
366
224
|
.join(', ');
|
|
367
225
|
console.error(`Lightdash MCP server listening on ${paths} (auth: ${httpConfig.authMode})`);
|
|
@@ -382,14 +240,14 @@ function requestOrigin(req) {
|
|
|
382
240
|
* Applies CORS reflect headers without blocking.
|
|
383
241
|
* When `reflectAnyOrigin` is true (OAuth AS / PRM), always echo Origin and ignore
|
|
384
242
|
* `ALLOWED_ORIGINS` so Cursor loopback (`http://localhost:8787`) can read token JSON
|
|
385
|
-
* even if
|
|
243
|
+
* even if profile MCP routes use a browser allowlist.
|
|
386
244
|
*/
|
|
387
245
|
function applyOptionalCorsHeaders(req, res, config, reflectAnyOrigin = false) {
|
|
388
246
|
const allowed = reflectAnyOrigin ? [] : config.allowedOrigins;
|
|
389
247
|
(0, http_response_js_1.applyResponseHeaders)(res, (0, http_response_js_1.buildCorsHeaders)(requestOrigin(req), allowed, reflectAnyOrigin));
|
|
390
248
|
}
|
|
391
249
|
/**
|
|
392
|
-
* Validates Origin and applies CORS headers for
|
|
250
|
+
* Validates Origin and applies CORS headers for profile MCP routes.
|
|
393
251
|
* Short-circuits OPTIONS preflight with 204; returns true when the request is fully handled.
|
|
394
252
|
*/
|
|
395
253
|
function applyOriginGuardAndCors(req, res, config) {
|
|
@@ -430,32 +288,26 @@ async function handlePublicHttpPaths(req, res, config, path, oauthBroker) {
|
|
|
430
288
|
}
|
|
431
289
|
return false;
|
|
432
290
|
}
|
|
433
|
-
async function handleHttpRequest(req, res, config,
|
|
291
|
+
async function handleHttpRequest(req, res, config, oauthBroker, nodeHandler) {
|
|
434
292
|
var _a, _b;
|
|
435
293
|
const path = (_b = ((_a = req.url) !== null && _a !== void 0 ? _a : '').split('?')[0]) !== null && _b !== void 0 ? _b : '';
|
|
436
294
|
if (await handlePublicHttpPaths(req, res, config, path, oauthBroker)) {
|
|
437
295
|
return;
|
|
438
296
|
}
|
|
439
|
-
//
|
|
297
|
+
// Profile MCP routes: Origin allowlist is enforced (CSRF / browser blast-radius).
|
|
440
298
|
if (applyOriginGuardAndCors(req, res, config)) {
|
|
441
299
|
return;
|
|
442
300
|
}
|
|
443
|
-
const
|
|
444
|
-
if (!
|
|
301
|
+
const profile = (0, index_js_1.getProfileByPath)(path);
|
|
302
|
+
if (!profile) {
|
|
445
303
|
(0, http_response_js_1.sendJson)(res, 404, { error: 'Not Found' });
|
|
446
304
|
return;
|
|
447
305
|
}
|
|
448
|
-
|
|
306
|
+
// Sessionless: only POST is supported on profile MCP paths.
|
|
307
|
+
if (req.method !== 'POST') {
|
|
308
|
+
res.writeHead(405, { Allow: 'POST' }).end();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
449
311
|
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
|
-
});
|
|
312
|
+
await (0, project_pin_js_1.runWithProjectPinAsync)(pinnedProjectUuid, () => handleMcpPost({ req, res, config, profile, nodeHandler }));
|
|
461
313
|
}
|
|
@@ -6,17 +6,14 @@ const www_authenticate_js_1 = require("../auth/resource-server/www-authenticate.
|
|
|
6
6
|
const env_js_1 = require("../config/env.js");
|
|
7
7
|
const load_mcp_config_js_1 = require("../config/load-mcp-config.js");
|
|
8
8
|
const test_mcp_http_config_js_1 = require("../config/test-mcp-http-config.js");
|
|
9
|
-
const index_js_1 = require("../
|
|
10
|
-
const index_js_2 = require("../
|
|
11
|
-
const index_js_3 = require("../
|
|
9
|
+
const index_js_1 = require("../profiles/content-reader/v1/index.js");
|
|
10
|
+
const index_js_2 = require("../profiles/organization-audit/v1/index.js");
|
|
11
|
+
const index_js_3 = require("../profiles/semantic-layer/v1/index.js");
|
|
12
12
|
const http_response_js_1 = require("./http-response.js");
|
|
13
13
|
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
|
});
|
|
@@ -68,18 +65,18 @@ function clearMcpEnv() {
|
|
|
68
65
|
});
|
|
69
66
|
(0, vitest_1.describe)('streamable HTTP OAuth metadata', () => {
|
|
70
67
|
(0, vitest_1.it)('builds protected resource metadata with MCP host as authorization_servers', () => {
|
|
71
|
-
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.
|
|
68
|
+
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PROFILE_PATH);
|
|
72
69
|
(0, vitest_1.expect)(metadata.authorization_servers).toEqual(['https://mcp.example.com']);
|
|
73
|
-
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_3.
|
|
70
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PROFILE_PATH}`);
|
|
74
71
|
(0, vitest_1.expect)((0, oauth_protected_resource_js_1.getAuthorizationServerMetadataUrl)(metadata.authorization_servers[0])).toBe('https://mcp.example.com/.well-known/oauth-authorization-server');
|
|
75
72
|
});
|
|
76
73
|
(0, vitest_1.it)('builds organization-audit protected resource metadata', () => {
|
|
77
|
-
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.
|
|
78
|
-
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.
|
|
74
|
+
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH);
|
|
75
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH}`);
|
|
79
76
|
});
|
|
80
77
|
(0, vitest_1.it)('builds content-reader protected resource metadata', () => {
|
|
81
|
-
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.
|
|
82
|
-
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.
|
|
78
|
+
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.CONTENT_READER_PROFILE_PATH);
|
|
79
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.CONTENT_READER_PROFILE_PATH}`);
|
|
83
80
|
});
|
|
84
81
|
(0, vitest_1.it)('builds WWW-Authenticate challenges with resource_metadata for OAuth clients', () => {
|
|
85
82
|
const header = (0, www_authenticate_js_1.buildWwwAuthenticateHeader)({
|
|
@@ -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.11.0",
|
|
4
|
+
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, and ai-agent-ops profiles.",
|
|
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.11.0",
|
|
28
|
+
"@lightdash-tools/common": "0.11.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/
|
|
38
|
+
"build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance ai-agent-ops data-analyst; do mkdir -p dist/profiles/$p/v1/resources/playbooks && cp -R src/profiles/$p/v1/resources/playbooks/. dist/profiles/$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
|
-
}
|