@lightdash-tools/mcp 0.7.0 → 0.8.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 +98 -26
- package/dist/auth/oauth-broker/pending-store.d.ts +70 -19
- package/dist/auth/oauth-broker/pending-store.js +53 -26
- package/dist/auth/oauth-broker/pending-store.test.d.ts +6 -0
- package/dist/auth/oauth-broker/pending-store.test.js +146 -0
- package/dist/auth/oauth-broker/routes.d.ts +6 -2
- package/dist/auth/oauth-broker/routes.js +26 -21
- package/dist/auth/oauth-broker/routes.test.js +32 -27
- package/dist/auth/resource-server/www-authenticate.test.js +12 -6
- package/dist/bin.js +23 -2
- package/dist/config/env.d.ts +7 -0
- package/dist/config/env.js +8 -1
- package/dist/config/load-mcp-config.js +4 -0
- package/dist/config/load-mcp-config.test.js +7 -0
- package/dist/config/normalize-url.test.js +13 -7
- package/dist/destructive/capability.d.ts +13 -0
- package/dist/destructive/capability.js +37 -0
- package/dist/destructive/capability.test.d.ts +1 -0
- package/dist/destructive/capability.test.js +46 -0
- package/dist/destructive/confirmation-claim.d.ts +21 -0
- package/dist/destructive/confirmation-claim.js +87 -0
- package/dist/destructive/confirmation-claim.test.d.ts +1 -0
- package/dist/destructive/confirmation-claim.test.js +50 -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 +144 -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 +339 -0
- package/dist/destructive/register-destructive-tool.d.ts +54 -0
- package/dist/destructive/register-destructive-tool.js +301 -0
- package/dist/destructive/request-state.d.ts +16 -0
- package/dist/destructive/request-state.js +76 -0
- package/dist/destructive/types.d.ts +64 -0
- package/dist/destructive/types.js +10 -0
- package/dist/governance/mcp-client-session.d.ts +9 -0
- package/dist/governance/mcp-client-session.js +30 -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 +38 -0
- package/dist/governance/project-scope.js +79 -0
- package/dist/governance/project-scope.test.d.ts +4 -0
- package/dist/governance/project-scope.test.js +103 -0
- package/dist/http.integration.test.js +34 -0
- package/dist/index.js +1 -1
- package/dist/personas/content-developer/v1/index.d.ts +10 -0
- package/dist/personas/content-developer/v1/index.js +51 -0
- package/dist/personas/content-developer/v1/prompts.d.ts +5 -0
- package/dist/personas/content-developer/v1/prompts.js +138 -0
- package/dist/personas/content-developer/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-developer/v1/prompts.test.js +75 -0
- package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +15 -0
- package/dist/personas/content-developer/v1/resources/playbooks/core.md +63 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +55 -0
- package/dist/personas/content-developer/v1/resources/playbooks/index.md +13 -0
- package/dist/personas/content-developer/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-developer/v1/resources/playbooks.js +44 -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 +37 -0
- package/dist/personas/content-reader/v1/prompts.d.ts +5 -0
- package/dist/personas/content-reader/v1/prompts.js +128 -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 +21 -0
- package/dist/personas/content-reader/v1/resources/playbooks/core.md +40 -0
- package/dist/personas/content-reader/v1/resources/playbooks/discover.md +13 -0
- package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +19 -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 +3 -0
- package/dist/personas/index.js +26 -10
- package/dist/personas/index.test.js +77 -26
- package/dist/personas/lib/playbook-resources.d.ts +79 -0
- package/dist/personas/lib/playbook-resources.js +165 -0
- package/dist/personas/organization-audit/v1/index.js +2 -2
- package/dist/personas/organization-audit/v1/prompts.js +14 -33
- package/dist/personas/organization-audit/v1/prompts.test.js +4 -4
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +13 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +9 -0
- package/dist/personas/organization-audit/v1/resources/{playbook.md → playbooks/core.md} +6 -22
- package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +9 -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 +26 -0
- package/dist/personas/semantic-layer/v1/index.js +2 -2
- package/dist/personas/semantic-layer/v1/prompts.js +15 -37
- 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 +55 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +39 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +76 -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 +48 -0
- package/dist/policy/content-reader.d.ts +24 -0
- package/dist/policy/content-reader.js +52 -0
- package/dist/policy/content-reader.test.d.ts +4 -0
- package/dist/policy/content-reader.test.js +22 -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 +527 -0
- package/dist/policy/preview-ledger.d.ts +118 -0
- package/dist/policy/preview-ledger.js +243 -0
- package/dist/policy/preview-ledger.test.d.ts +1 -0
- package/dist/policy/preview-ledger.test.js +267 -0
- package/dist/policy/result-limits.d.ts +27 -0
- package/dist/policy/result-limits.js +107 -0
- package/dist/policy/result-limits.test.d.ts +4 -0
- package/dist/policy/result-limits.test.js +28 -0
- package/dist/server/capabilities.js +1 -1
- package/dist/server/capabilities.test.js +3 -1
- package/dist/server/server.js +12 -1
- package/dist/stdio.process.test.js +148 -0
- package/dist/store/config.d.ts +11 -0
- package/dist/store/config.js +50 -0
- package/dist/store/config.test.d.ts +1 -0
- package/dist/store/config.test.js +56 -0
- package/dist/store/create-oauth-broker-store.d.ts +6 -0
- package/dist/store/create-oauth-broker-store.js +16 -0
- package/dist/store/create-preview-store.d.ts +10 -0
- package/dist/store/create-preview-store.js +30 -0
- package/dist/store/create-session-store.d.ts +19 -0
- package/dist/store/create-session-store.js +24 -0
- package/dist/store/in-memory-preview-store.d.ts +17 -0
- package/dist/store/in-memory-preview-store.js +72 -0
- package/dist/store/redis-client.d.ts +11 -0
- package/dist/store/redis-client.js +48 -0
- package/dist/store/redis-oauth-broker-store.d.ts +42 -0
- package/dist/store/redis-oauth-broker-store.js +167 -0
- package/dist/store/redis-oauth-broker-store.test.d.ts +1 -0
- package/dist/store/redis-oauth-broker-store.test.js +80 -0
- package/dist/store/redis-preview-store.d.ts +23 -0
- package/dist/store/redis-preview-store.js +94 -0
- package/dist/store/redis-preview-store.test.d.ts +1 -0
- package/dist/store/redis-preview-store.test.js +39 -0
- package/dist/store/redis-session-index.d.ts +33 -0
- package/dist/store/redis-session-index.js +49 -0
- package/dist/store/types.d.ts +13 -0
- package/dist/store/types.js +8 -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/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 +12 -0
- package/dist/tools/project/developer-content-preview.js +286 -0
- package/dist/tools/project/developer-content-shared.d.ts +18 -0
- package/dist/tools/project/developer-content-shared.js +46 -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 +39 -0
- package/dist/tools/project/developer-content.js +584 -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 +42 -0
- package/dist/tools/project/invariants.test.d.ts +4 -0
- package/dist/tools/project/invariants.test.js +42 -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 +64 -4
- package/dist/tools/project/projects.test.js +38 -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/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 +112 -0
- package/dist/tools/query/query-ledger.d.ts +34 -0
- package/dist/tools/query/query-ledger.js +86 -0
- package/dist/tools/query/query-ledger.test.d.ts +1 -0
- package/dist/tools/query/query-ledger.test.js +73 -0
- package/dist/tools/query/reader-tool-helpers.d.ts +12 -0
- package/dist/tools/query/reader-tool-helpers.js +59 -0
- package/dist/tools/query/reader-tool-helpers.test.d.ts +1 -0
- package/dist/tools/query/reader-tool-helpers.test.js +49 -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 +124 -3
- package/dist/tools/registry.js +63 -7
- package/dist/tools/shared.d.ts +25 -2
- package/dist/tools/shared.js +66 -13
- package/dist/tools/shared.test.js +6 -2
- package/dist/transports/session-store.d.ts +33 -1
- package/dist/transports/session-store.js +56 -1
- package/dist/transports/streamable-http.js +10 -3
- package/dist/transports/streamable-http.test.js +11 -6
- package/package.json +6 -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/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/tools/registry.js
CHANGED
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Shared MCP tool registry: short id → register(server, ctx).
|
|
4
4
|
* Wire names are always `lightdash_` + id via registerToolSafe.
|
|
5
|
+
* Persona allowlists must resolve through the operation catalog (ADR-0013).
|
|
5
6
|
*/
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
8
|
exports.toolRegistry = void 0;
|
|
8
9
|
exports.registerToolsByIds = registerToolsByIds;
|
|
10
|
+
const common_1 = require("@lightdash-tools/common");
|
|
11
|
+
const explain_content_js_1 = require("./composition/explain-content.js");
|
|
9
12
|
const inventory_js_1 = require("./organization/inventory.js");
|
|
10
13
|
const roles_js_1 = require("./organization/roles.js");
|
|
11
14
|
const content_js_1 = require("./project/content.js");
|
|
15
|
+
const delete_chart_js_1 = require("./project/delete-chart.js");
|
|
16
|
+
const delete_dashboard_js_1 = require("./project/delete-dashboard.js");
|
|
17
|
+
const developer_content_js_1 = require("./project/developer-content.js");
|
|
18
|
+
const get_dashboard_promote_diff_js_1 = require("./project/get-dashboard-promote-diff.js");
|
|
19
|
+
const parameters_js_1 = require("./project/parameters.js");
|
|
12
20
|
const projects_js_1 = require("./project/projects.js");
|
|
21
|
+
const promote_dashboard_js_1 = require("./project/promote-dashboard.js");
|
|
22
|
+
const reader_content_js_1 = require("./project/reader-content.js");
|
|
23
|
+
const reader_execution_js_1 = require("./project/reader-execution.js");
|
|
13
24
|
const schedulers_js_1 = require("./project/schedulers.js");
|
|
25
|
+
const spaces_js_1 = require("./project/spaces.js");
|
|
26
|
+
const lifecycle_js_1 = require("./query/lifecycle.js");
|
|
14
27
|
const explores_js_1 = require("./semantic/explores.js");
|
|
15
28
|
const metrics_js_1 = require("./semantic/metrics.js");
|
|
16
29
|
const query_js_1 = require("./semantic/query.js");
|
|
@@ -45,15 +58,58 @@ exports.toolRegistry = {
|
|
|
45
58
|
get_project_user_activity: { register: content_js_1.registerGetProjectUserActivity },
|
|
46
59
|
list_project_schedulers: { register: schedulers_js_1.registerListProjectSchedulers },
|
|
47
60
|
get_scheduler: { register: schedulers_js_1.registerGetScheduler },
|
|
61
|
+
// content-reader
|
|
62
|
+
search_content: { register: reader_content_js_1.registerSearchContent },
|
|
63
|
+
list_spaces: { register: spaces_js_1.registerListSpaces },
|
|
64
|
+
get_space: { register: spaces_js_1.registerGetSpace },
|
|
65
|
+
get_dashboard: { register: reader_content_js_1.registerGetDashboard },
|
|
66
|
+
get_chart: { register: reader_content_js_1.registerGetChart },
|
|
67
|
+
list_project_parameters: { register: parameters_js_1.registerListProjectParameters },
|
|
68
|
+
get_project_parameters: { register: parameters_js_1.registerGetProjectParameters },
|
|
69
|
+
explain_content: { register: explain_content_js_1.registerExplainContent },
|
|
70
|
+
run_chart: { register: reader_execution_js_1.registerRunChart },
|
|
71
|
+
run_dashboard_tile: { register: reader_execution_js_1.registerRunDashboardTile },
|
|
72
|
+
get_query_result: { register: lifecycle_js_1.registerGetQueryResult },
|
|
73
|
+
cancel_query: { register: lifecycle_js_1.registerCancelQuery },
|
|
74
|
+
// content-developer (ADR-0014)
|
|
75
|
+
preview_chart_changes: { register: developer_content_js_1.registerPreviewChartChanges },
|
|
76
|
+
preview_dashboard_changes: { register: developer_content_js_1.registerPreviewDashboardChanges },
|
|
77
|
+
preview_content_move: { register: developer_content_js_1.registerPreviewContentMove },
|
|
78
|
+
validate_chart: { register: developer_content_js_1.registerValidateChart },
|
|
79
|
+
validate_dashboard: { register: developer_content_js_1.registerValidateDashboard },
|
|
80
|
+
confirm_preview: { register: developer_content_js_1.registerConfirmPreview },
|
|
81
|
+
compare_chart_versions: { register: developer_content_js_1.registerCompareChartVersions },
|
|
82
|
+
compare_dashboard_versions: { register: developer_content_js_1.registerCompareDashboardVersions },
|
|
83
|
+
create_chart: { register: developer_content_js_1.registerCreateChart },
|
|
84
|
+
update_chart: { register: developer_content_js_1.registerUpdateChart },
|
|
85
|
+
duplicate_chart: { register: developer_content_js_1.registerDuplicateChart },
|
|
86
|
+
create_dashboard: { register: developer_content_js_1.registerCreateDashboard },
|
|
87
|
+
update_dashboard: { register: developer_content_js_1.registerUpdateDashboard },
|
|
88
|
+
duplicate_dashboard: { register: developer_content_js_1.registerDuplicateDashboard },
|
|
89
|
+
add_dashboard_tile: { register: developer_content_js_1.registerAddDashboardTile },
|
|
90
|
+
move_dashboard_tile: { register: developer_content_js_1.registerMoveDashboardTile },
|
|
91
|
+
remove_dashboard_tile: { register: developer_content_js_1.registerRemoveDashboardTile },
|
|
92
|
+
resize_dashboard_tile: { register: developer_content_js_1.registerResizeDashboardTile },
|
|
93
|
+
move_content: { register: developer_content_js_1.registerMoveContent },
|
|
94
|
+
// content-governance (ADR-0015 / ADR-0017)
|
|
95
|
+
delete_chart: { register: delete_chart_js_1.registerDeleteChart },
|
|
96
|
+
delete_dashboard: { register: delete_dashboard_js_1.registerDeleteDashboard },
|
|
97
|
+
get_dashboard_promote_diff: { register: get_dashboard_promote_diff_js_1.registerGetDashboardPromoteDiff },
|
|
98
|
+
promote_dashboard: { register: promote_dashboard_js_1.registerPromoteDashboard },
|
|
48
99
|
};
|
|
49
|
-
|
|
50
|
-
|
|
100
|
+
const BANNED_MCP_TOOL_IDS = new Set((0, common_1.listBannedMcpToolNames)());
|
|
101
|
+
/** Register a subset of tools by id (persona allowlist). Requires catalog parity (ADR-0013). */
|
|
102
|
+
function registerToolsByIds(server, contextProvider, ids, options) {
|
|
103
|
+
var _a;
|
|
51
104
|
for (const id of ids) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
if (BANNED_MCP_TOOL_IDS.has(id)) {
|
|
106
|
+
throw new Error(`MCP tool id '${id}' is banned (client-only / irrecoverable)`);
|
|
107
|
+
}
|
|
108
|
+
const catalogOp = (0, common_1.getOperationByMcpToolName)(id);
|
|
109
|
+
if (((_a = catalogOp === null || catalogOp === void 0 ? void 0 : catalogOp.mcp) === null || _a === void 0 ? void 0 : _a.taskSupport.exposed) !== true) {
|
|
110
|
+
throw new Error(`MCP tool id '${id}' is not an exposed operation in the catalog (ADR-0013)`);
|
|
56
111
|
}
|
|
57
|
-
|
|
112
|
+
// eslint-disable-next-line security/detect-object-injection -- ToolId union keys only
|
|
113
|
+
exports.toolRegistry[id].register(server, contextProvider, options);
|
|
58
114
|
}
|
|
59
115
|
}
|
package/dist/tools/shared.d.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { McpContextProvider } from '../server/request-context.js';
|
|
13
13
|
import type { LightdashClient } from '@lightdash-tools/client';
|
|
14
|
-
import type { ToolAnnotations } from '@lightdash-tools/common';
|
|
14
|
+
import type { AuditStatus, ToolAnnotations } from '@lightdash-tools/common';
|
|
15
|
+
import type { InputRequiredResult, ServerContext } from '@modelcontextprotocol/server';
|
|
15
16
|
import type { z } from 'zod';
|
|
16
17
|
/** Prefix for all MCP tool names (disambiguation when multiple servers are connected). */
|
|
17
18
|
export declare const TOOL_PREFIX = "lightdash_";
|
|
@@ -23,10 +24,12 @@ export type TextContent = {
|
|
|
23
24
|
structuredContent?: Record<string, unknown>;
|
|
24
25
|
isError?: boolean;
|
|
25
26
|
};
|
|
27
|
+
/** Handler return type: normal tool content or MCP 2026-07-28 MRTR InputRequiredResult. */
|
|
28
|
+
export type ToolResult = InputRequiredResult | TextContent;
|
|
26
29
|
/** Builds a tool result with JSON text and matching structuredContent. */
|
|
27
30
|
export declare function jsonToolResult(data: unknown): TextContent;
|
|
28
31
|
/** Tool handler type used to avoid deep instantiation with SDK/Zod. Accepts (args, extra) for SDK compatibility. */
|
|
29
|
-
export type ToolHandler = (args: unknown, extra?: unknown) => Promise<
|
|
32
|
+
export type ToolHandler = (args: unknown, extra?: unknown) => Promise<ToolResult>;
|
|
30
33
|
/** Options for registerTool; inputSchema typed as ZodRawShapeCompat for SDK compatibility. Pass annotations explicitly (e.g. READ_ONLY_DEFAULT or WRITE_IDEMPOTENT) for visibility. */
|
|
31
34
|
export type ToolOptions = {
|
|
32
35
|
description: string;
|
|
@@ -44,12 +47,32 @@ export { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
|
|
|
44
47
|
type BlockedContent = TextContent & {
|
|
45
48
|
readonly _lightdashBlocked: true;
|
|
46
49
|
};
|
|
50
|
+
type AuditedContent = TextContent & {
|
|
51
|
+
readonly _lightdashBlocked?: true;
|
|
52
|
+
readonly _lightdashAuditStatus?: AuditStatus;
|
|
53
|
+
};
|
|
47
54
|
/** Guardrail-blocked tool result; audit wrapper strips `_lightdashBlocked`. */
|
|
48
55
|
export declare function blockedToolContent(message: string): BlockedContent;
|
|
56
|
+
/**
|
|
57
|
+
* Attach `_lightdashBlocked` so audit status is `blocked` (stripped before MCP client).
|
|
58
|
+
* Prefer for policy denials that already have JSON content + structuredContent.
|
|
59
|
+
*/
|
|
60
|
+
export declare function withLightdashBlockedMarker<T extends TextContent>(result: T): BlockedContent & T;
|
|
61
|
+
/** Attach a specific audit status (stripped before MCP client). */
|
|
62
|
+
export declare function withAuditStatus<T extends TextContent>(result: T, status: AuditStatus): AuditedContent & T;
|
|
49
63
|
/**
|
|
50
64
|
* Registers a tool with prefix and annotations, applying pin / validation / audit guardrails.
|
|
51
65
|
* shortName is prefixed to become TOOL_PREFIX + shortName.
|
|
52
66
|
* Pass annotations explicitly (e.g. READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, or WRITE_DESTRUCTIVE).
|
|
67
|
+
* Handlers may return TextContent or InputRequiredResult (MRTR elicitation).
|
|
53
68
|
*/
|
|
54
69
|
export declare function registerToolSafe(server: unknown, shortName: string, options: ToolOptions, handler: ToolHandler): void;
|
|
70
|
+
export type ToolExecutionContext = {
|
|
71
|
+
lightdashClient: LightdashClient;
|
|
72
|
+
/** SDK ServerContext when the transport provides it (second registerTool arg). */
|
|
73
|
+
serverContext: ServerContext | undefined;
|
|
74
|
+
sessionId: string;
|
|
75
|
+
};
|
|
76
|
+
/** Like wrapTool, but passes ServerContext / session / auth for elicitation-capable tools. */
|
|
77
|
+
export declare function wrapToolContextual<T>(contextProvider: McpContextProvider, fn: (ctx: ToolExecutionContext) => (args: T) => Promise<ToolResult>): ToolHandler;
|
|
55
78
|
export declare function wrapTool<T>(contextProvider: McpContextProvider, fn: (client: LightdashClient) => (args: T) => Promise<TextContent>): ToolHandler;
|
package/dist/tools/shared.js
CHANGED
|
@@ -14,10 +14,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.READ_ONLY_DEFAULT = exports.TOOL_PREFIX = void 0;
|
|
15
15
|
exports.jsonToolResult = jsonToolResult;
|
|
16
16
|
exports.blockedToolContent = blockedToolContent;
|
|
17
|
+
exports.withLightdashBlockedMarker = withLightdashBlockedMarker;
|
|
18
|
+
exports.withAuditStatus = withAuditStatus;
|
|
17
19
|
exports.registerToolSafe = registerToolSafe;
|
|
20
|
+
exports.wrapToolContextual = wrapToolContextual;
|
|
18
21
|
exports.wrapTool = wrapTool;
|
|
19
22
|
const common_1 = require("@lightdash-tools/common");
|
|
23
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
20
24
|
const tool_audit_context_js_1 = require("../audit/tool-audit-context.js");
|
|
25
|
+
const mcp_client_session_js_1 = require("../governance/mcp-client-session.js");
|
|
21
26
|
const project_pin_js_1 = require("../governance/project-pin.js");
|
|
22
27
|
const errors_js_1 = require("../server/errors.js");
|
|
23
28
|
/** Prefix for all MCP tool names (disambiguation when multiple servers are connected). */
|
|
@@ -83,6 +88,22 @@ function isGuardrailBlocked(result) {
|
|
|
83
88
|
return ('_lightdashBlocked' in result &&
|
|
84
89
|
result['_lightdashBlocked'] === true);
|
|
85
90
|
}
|
|
91
|
+
function resolveAuditStatus(result) {
|
|
92
|
+
if ((0, server_1.isInputRequiredResult)(result)) {
|
|
93
|
+
return 'confirmation_requested';
|
|
94
|
+
}
|
|
95
|
+
const audited = result;
|
|
96
|
+
if (typeof audited._lightdashAuditStatus === 'string') {
|
|
97
|
+
return audited._lightdashAuditStatus;
|
|
98
|
+
}
|
|
99
|
+
if (isGuardrailBlocked(result)) {
|
|
100
|
+
return 'blocked';
|
|
101
|
+
}
|
|
102
|
+
if (result.isError) {
|
|
103
|
+
return 'error';
|
|
104
|
+
}
|
|
105
|
+
return 'success';
|
|
106
|
+
}
|
|
86
107
|
/** Guardrail-blocked tool result; audit wrapper strips `_lightdashBlocked`. */
|
|
87
108
|
function blockedToolContent(message) {
|
|
88
109
|
return {
|
|
@@ -91,10 +112,22 @@ function blockedToolContent(message) {
|
|
|
91
112
|
_lightdashBlocked: true,
|
|
92
113
|
};
|
|
93
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Attach `_lightdashBlocked` so audit status is `blocked` (stripped before MCP client).
|
|
117
|
+
* Prefer for policy denials that already have JSON content + structuredContent.
|
|
118
|
+
*/
|
|
119
|
+
function withLightdashBlockedMarker(result) {
|
|
120
|
+
return Object.assign(Object.assign({}, result), { _lightdashBlocked: true });
|
|
121
|
+
}
|
|
122
|
+
/** Attach a specific audit status (stripped before MCP client). */
|
|
123
|
+
function withAuditStatus(result, status) {
|
|
124
|
+
return Object.assign(Object.assign({}, result), { _lightdashAuditStatus: status });
|
|
125
|
+
}
|
|
94
126
|
/**
|
|
95
127
|
* Registers a tool with prefix and annotations, applying pin / validation / audit guardrails.
|
|
96
128
|
* shortName is prefixed to become TOOL_PREFIX + shortName.
|
|
97
129
|
* Pass annotations explicitly (e.g. READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, or WRITE_DESTRUCTIVE).
|
|
130
|
+
* Handlers may return TextContent or InputRequiredResult (MRTR elicitation).
|
|
98
131
|
*/
|
|
99
132
|
function registerToolSafe(server, shortName, options, handler) {
|
|
100
133
|
var _a, _b;
|
|
@@ -139,12 +172,7 @@ function registerToolSafe(server, shortName, options, handler) {
|
|
|
139
172
|
let result;
|
|
140
173
|
try {
|
|
141
174
|
result = await auditedInner(args, extra);
|
|
142
|
-
|
|
143
|
-
status = 'blocked';
|
|
144
|
-
}
|
|
145
|
-
else if (result.isError) {
|
|
146
|
-
status = 'error';
|
|
147
|
-
}
|
|
175
|
+
status = resolveAuditStatus(result);
|
|
148
176
|
}
|
|
149
177
|
catch (err) {
|
|
150
178
|
status = 'error';
|
|
@@ -152,7 +180,11 @@ function registerToolSafe(server, shortName, options, handler) {
|
|
|
152
180
|
throw err;
|
|
153
181
|
}
|
|
154
182
|
(0, common_1.logAuditEntry)(buildAuditFields(name, projectUuids, status, start, auth));
|
|
155
|
-
//
|
|
183
|
+
// Pass InputRequiredResult through unchanged (MRTR).
|
|
184
|
+
if ((0, server_1.isInputRequiredResult)(result)) {
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
// Strip internal markers before returning to the MCP client.
|
|
156
188
|
const enriched = enrichStructuredContent(result);
|
|
157
189
|
const { content, isError, structuredContent } = enriched;
|
|
158
190
|
return structuredContent !== undefined
|
|
@@ -162,14 +194,29 @@ function registerToolSafe(server, shortName, options, handler) {
|
|
|
162
194
|
const mergedOptions = Object.assign(Object.assign({}, options), { title: (_a = options.title) !== null && _a !== void 0 ? _a : (_b = options.annotations) === null || _b === void 0 ? void 0 : _b.title, annotations });
|
|
163
195
|
server.registerTool(name, mergedOptions, finalHandler);
|
|
164
196
|
}
|
|
165
|
-
function
|
|
197
|
+
function asServerContext(extra) {
|
|
198
|
+
if (extra !== null && typeof extra === 'object' && 'mcpReq' in extra) {
|
|
199
|
+
return extra;
|
|
200
|
+
}
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
/** Like wrapTool, but passes ServerContext / session / auth for elicitation-capable tools. */
|
|
204
|
+
function wrapToolContextual(contextProvider, fn) {
|
|
166
205
|
return async (args, extra) => {
|
|
206
|
+
const sessionId = (0, mcp_client_session_js_1.resolveMcpClientSessionId)(extra);
|
|
167
207
|
try {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
208
|
+
return await (0, mcp_client_session_js_1.runWithMcpClientSessionAsync)(sessionId, async () => {
|
|
209
|
+
const context = await contextProvider.getContext(extra);
|
|
210
|
+
const auth = context.auth;
|
|
211
|
+
return await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)({ tokenHash: auth === null || auth === void 0 ? void 0 : auth.tokenHash, subject: auth === null || auth === void 0 ? void 0 : auth.subject }, async () => {
|
|
212
|
+
const execution = {
|
|
213
|
+
lightdashClient: context.lightdashClient,
|
|
214
|
+
serverContext: asServerContext(extra),
|
|
215
|
+
sessionId,
|
|
216
|
+
};
|
|
217
|
+
const handler = fn(execution);
|
|
218
|
+
return await handler(args);
|
|
219
|
+
});
|
|
173
220
|
});
|
|
174
221
|
}
|
|
175
222
|
catch (err) {
|
|
@@ -178,3 +225,9 @@ function wrapTool(contextProvider, fn) {
|
|
|
178
225
|
}
|
|
179
226
|
};
|
|
180
227
|
}
|
|
228
|
+
function wrapTool(contextProvider, fn) {
|
|
229
|
+
return wrapToolContextual(contextProvider, (ctx) => {
|
|
230
|
+
const inner = fn(ctx.lightdashClient);
|
|
231
|
+
return async (args) => inner(args);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
@@ -36,6 +36,7 @@ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
|
|
|
36
36
|
(0, vitest_1.expect)(result.content[0].text).toBe('success');
|
|
37
37
|
});
|
|
38
38
|
(0, vitest_1.it)('allows tools when OAuth subject is present (no local JWT scope gate)', async () => {
|
|
39
|
+
var _a;
|
|
39
40
|
const contextProvider = {
|
|
40
41
|
getContext: async () => ({
|
|
41
42
|
lightdashClient: {},
|
|
@@ -51,7 +52,8 @@ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
|
|
|
51
52
|
}));
|
|
52
53
|
const result = await wrapped({});
|
|
53
54
|
(0, vitest_1.expect)(result.isError).toBeUndefined();
|
|
54
|
-
(0, vitest_1.expect)(result.content
|
|
55
|
+
(0, vitest_1.expect)(Array.isArray(result.content)).toBe(true);
|
|
56
|
+
(0, vitest_1.expect)((_a = result.content[0]) === null || _a === void 0 ? void 0 : _a.text).toBe('success');
|
|
55
57
|
});
|
|
56
58
|
(0, vitest_1.it)('should reject invalid projectUuid before calling handler', async () => {
|
|
57
59
|
(0, shared_js_1.registerToolSafe)(mockServer, 'list_tool', {
|
|
@@ -154,6 +156,7 @@ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
|
|
|
154
156
|
(0, vitest_1.expect)(JSON.parse(result.content[0].text)).toEqual([{ id: 'a' }]);
|
|
155
157
|
});
|
|
156
158
|
(0, vitest_1.it)('wrapTool returns a safe error message when the inner handler throws', async () => {
|
|
159
|
+
var _a;
|
|
157
160
|
const contextProvider = {
|
|
158
161
|
getContext: async () => ({
|
|
159
162
|
lightdashClient: {},
|
|
@@ -165,6 +168,7 @@ const PROJECT_B = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
|
|
|
165
168
|
});
|
|
166
169
|
const result = await wrapped({});
|
|
167
170
|
(0, vitest_1.expect)(result.isError).toBe(true);
|
|
168
|
-
(0, vitest_1.expect)(result.content
|
|
171
|
+
(0, vitest_1.expect)(Array.isArray(result.content)).toBe(true);
|
|
172
|
+
(0, vitest_1.expect)((_a = result.content[0]) === null || _a === void 0 ? void 0 : _a.text).toBe('boom');
|
|
169
173
|
});
|
|
170
174
|
});
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamable HTTP MCP session store (ADR-0007 / ADR-0016).
|
|
3
|
+
*
|
|
4
|
+
* ## Hybrid design (when LIGHTDASH_TOOLS_MCP_STORE=redis)
|
|
5
|
+
*
|
|
6
|
+
* `SessionEntry` holds live `transport` / `server` objects that **cannot** be
|
|
7
|
+
* serialized to Redis. This store therefore always keeps those objects in a
|
|
8
|
+
* process-local Map.
|
|
9
|
+
*
|
|
10
|
+
* When a Redis session index is attached (via `createSessionStore`):
|
|
11
|
+
* - Serializable metadata (sessionId, auth, lastAccessAt, personaId) is also
|
|
12
|
+
* written to Redis for multi-instance *awareness* / TTL / ops visibility.
|
|
13
|
+
* - `get()` only returns a session when the transport lives on **this** process.
|
|
14
|
+
* Redis metadata without a local entry is treated as not found (clear failure
|
|
15
|
+
* when a request lands on the wrong replica).
|
|
16
|
+
* - Streamable HTTP transport affinity still requires **sticky sessions** or a
|
|
17
|
+
* single instance for in-flight transports. OAuth pending state (separate
|
|
18
|
+
* store) is the fully shared multi-instance path.
|
|
19
|
+
*
|
|
20
|
+
* Capacity checks (`maxSessions` / per-subject) remain process-local.
|
|
21
|
+
*/
|
|
1
22
|
import type { McpAuthMode } from '../auth/auth-mode.js';
|
|
2
23
|
import type { PersonaId } from '../personas/types.js';
|
|
3
24
|
import type { McpContextProvider } from '../server/request-context.js';
|
|
25
|
+
import type { RedisSessionIndex } from '../store/redis-session-index.js';
|
|
4
26
|
import type { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
|
|
5
27
|
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
28
|
export interface SessionAuthState {
|
|
@@ -23,11 +45,21 @@ export declare class SessionStore {
|
|
|
23
45
|
private readonly maxSessions;
|
|
24
46
|
/** `0` disables the per-subject cap (unlimited per subject; global maxSessions still applies). */
|
|
25
47
|
private readonly maxSessionsPerSubject;
|
|
48
|
+
/**
|
|
49
|
+
* Optional Redis index for serializable session metadata (hybrid mode).
|
|
50
|
+
* Live transport/server objects remain in `sessions` only.
|
|
51
|
+
*/
|
|
52
|
+
private readonly sessionIndex?;
|
|
26
53
|
private readonly sessions;
|
|
27
54
|
private readonly subjectSessionCounts;
|
|
28
55
|
constructor(sessionTtlMs: number, maxSessions: number,
|
|
29
56
|
/** `0` disables the per-subject cap (unlimited per subject; global maxSessions still applies). */
|
|
30
|
-
maxSessionsPerSubject: number
|
|
57
|
+
maxSessionsPerSubject: number,
|
|
58
|
+
/**
|
|
59
|
+
* Optional Redis index for serializable session metadata (hybrid mode).
|
|
60
|
+
* Live transport/server objects remain in `sessions` only.
|
|
61
|
+
*/
|
|
62
|
+
sessionIndex?: RedisSessionIndex | undefined);
|
|
31
63
|
get(sessionId: string): SessionEntry | undefined;
|
|
32
64
|
set(sessionId: string, entry: SessionEntry): void;
|
|
33
65
|
delete(sessionId: string): void;
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Streamable HTTP MCP session store (ADR-0007 / ADR-0016).
|
|
4
|
+
*
|
|
5
|
+
* ## Hybrid design (when LIGHTDASH_TOOLS_MCP_STORE=redis)
|
|
6
|
+
*
|
|
7
|
+
* `SessionEntry` holds live `transport` / `server` objects that **cannot** be
|
|
8
|
+
* serialized to Redis. This store therefore always keeps those objects in a
|
|
9
|
+
* process-local Map.
|
|
10
|
+
*
|
|
11
|
+
* When a Redis session index is attached (via `createSessionStore`):
|
|
12
|
+
* - Serializable metadata (sessionId, auth, lastAccessAt, personaId) is also
|
|
13
|
+
* written to Redis for multi-instance *awareness* / TTL / ops visibility.
|
|
14
|
+
* - `get()` only returns a session when the transport lives on **this** process.
|
|
15
|
+
* Redis metadata without a local entry is treated as not found (clear failure
|
|
16
|
+
* when a request lands on the wrong replica).
|
|
17
|
+
* - Streamable HTTP transport affinity still requires **sticky sessions** or a
|
|
18
|
+
* single instance for in-flight transports. OAuth pending state (separate
|
|
19
|
+
* store) is the fully shared multi-instance path.
|
|
20
|
+
*
|
|
21
|
+
* Capacity checks (`maxSessions` / per-subject) remain process-local.
|
|
22
|
+
*/
|
|
2
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
24
|
exports.SessionStore = void 0;
|
|
4
25
|
class SessionStore {
|
|
5
26
|
constructor(sessionTtlMs, maxSessions,
|
|
6
27
|
/** `0` disables the per-subject cap (unlimited per subject; global maxSessions still applies). */
|
|
7
|
-
maxSessionsPerSubject
|
|
28
|
+
maxSessionsPerSubject,
|
|
29
|
+
/**
|
|
30
|
+
* Optional Redis index for serializable session metadata (hybrid mode).
|
|
31
|
+
* Live transport/server objects remain in `sessions` only.
|
|
32
|
+
*/
|
|
33
|
+
sessionIndex) {
|
|
8
34
|
this.sessionTtlMs = sessionTtlMs;
|
|
9
35
|
this.maxSessions = maxSessions;
|
|
10
36
|
this.maxSessionsPerSubject = maxSessionsPerSubject;
|
|
37
|
+
this.sessionIndex = sessionIndex;
|
|
11
38
|
this.sessions = new Map();
|
|
12
39
|
this.subjectSessionCounts = new Map();
|
|
13
40
|
}
|
|
14
41
|
get(sessionId) {
|
|
42
|
+
// Local-only: Redis index without a local transport is a cross-instance miss.
|
|
15
43
|
return this.sessions.get(sessionId);
|
|
16
44
|
}
|
|
17
45
|
set(sessionId, entry) {
|
|
@@ -25,6 +53,18 @@ class SessionStore {
|
|
|
25
53
|
if (subject) {
|
|
26
54
|
this.subjectSessionCounts.set(subject, ((_a = this.subjectSessionCounts.get(subject)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
27
55
|
}
|
|
56
|
+
if (this.sessionIndex) {
|
|
57
|
+
void this.sessionIndex
|
|
58
|
+
.put({
|
|
59
|
+
sessionId,
|
|
60
|
+
lastAccessAt: entry.lastAccessAt,
|
|
61
|
+
auth: entry.auth,
|
|
62
|
+
personaId: entry.personaId,
|
|
63
|
+
})
|
|
64
|
+
.catch((err) => {
|
|
65
|
+
console.error(`Failed to persist session index ${sessionId}:`, err);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
28
68
|
}
|
|
29
69
|
delete(sessionId) {
|
|
30
70
|
const entry = this.sessions.get(sessionId);
|
|
@@ -32,6 +72,11 @@ class SessionStore {
|
|
|
32
72
|
this.decrementSubjectCount(entry);
|
|
33
73
|
}
|
|
34
74
|
this.sessions.delete(sessionId);
|
|
75
|
+
if (this.sessionIndex) {
|
|
76
|
+
void this.sessionIndex.delete(sessionId).catch((err) => {
|
|
77
|
+
console.error(`Failed to delete session index ${sessionId}:`, err);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
35
80
|
}
|
|
36
81
|
decrementSubjectCount(entry) {
|
|
37
82
|
var _a;
|
|
@@ -50,6 +95,11 @@ class SessionStore {
|
|
|
50
95
|
const entry = this.sessions.get(sessionId);
|
|
51
96
|
if (entry) {
|
|
52
97
|
entry.lastAccessAt = Date.now();
|
|
98
|
+
if (this.sessionIndex) {
|
|
99
|
+
void this.sessionIndex.touch(sessionId, entry.lastAccessAt).catch((err) => {
|
|
100
|
+
console.error(`Failed to touch session index ${sessionId}:`, err);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
53
103
|
}
|
|
54
104
|
}
|
|
55
105
|
cleanupExpired(onClose) {
|
|
@@ -80,6 +130,11 @@ class SessionStore {
|
|
|
80
130
|
drainAll(onClose) {
|
|
81
131
|
for (const [sessionId, entry] of this.sessions) {
|
|
82
132
|
onClose(entry, sessionId);
|
|
133
|
+
if (this.sessionIndex) {
|
|
134
|
+
void this.sessionIndex.delete(sessionId).catch((err) => {
|
|
135
|
+
console.error(`Failed to delete session index ${sessionId} on drain:`, err);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
83
138
|
}
|
|
84
139
|
this.sessions.clear();
|
|
85
140
|
this.subjectSessionCounts.clear();
|
|
@@ -20,10 +20,12 @@ const runtime_js_1 = require("../config/runtime.js");
|
|
|
20
20
|
const project_pin_js_1 = require("../governance/project-pin.js");
|
|
21
21
|
const index_js_1 = require("../personas/index.js");
|
|
22
22
|
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");
|
|
23
26
|
const http_body_js_1 = require("./http-body.js");
|
|
24
27
|
const http_request_utils_js_1 = require("./http-request-utils.js");
|
|
25
28
|
const http_response_js_1 = require("./http-response.js");
|
|
26
|
-
const session_store_js_1 = require("./session-store.js");
|
|
27
29
|
const ERROR_SESSION_NOT_FOUND = 'Session not found';
|
|
28
30
|
function listen(server, port, host) {
|
|
29
31
|
return new Promise((resolve, reject) => {
|
|
@@ -308,7 +310,12 @@ async function createStreamableHttpServer(config) {
|
|
|
308
310
|
const inputConfig = config !== null && config !== void 0 ? config : (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
309
311
|
(0, load_mcp_config_js_1.emitMcpHttpSecurityWarnings)(inputConfig);
|
|
310
312
|
(0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
|
|
311
|
-
const
|
|
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
|
+
});
|
|
312
319
|
let httpConfig = inputConfig;
|
|
313
320
|
const cleanupTimer = setInterval(() => {
|
|
314
321
|
sessionStore.cleanupExpired((entry, sessionId) => {
|
|
@@ -331,7 +338,7 @@ async function createStreamableHttpServer(config) {
|
|
|
331
338
|
httpConfig = resolveHttpConfig(inputConfig, port);
|
|
332
339
|
const baseUrl = (_a = httpConfig.publicUrl) !== null && _a !== void 0 ? _a : `http://${resolveListenHost(httpConfig.host)}:${port}`;
|
|
333
340
|
if (httpConfig.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
334
|
-
oauthBroker = (0, routes_js_1.createOAuthBroker)(httpConfig);
|
|
341
|
+
oauthBroker = (0, routes_js_1.createOAuthBroker)(httpConfig, (0, create_oauth_broker_store_js_1.createOAuthBrokerStore)(ephemeralStoreConfig));
|
|
335
342
|
}
|
|
336
343
|
return {
|
|
337
344
|
port,
|
|
@@ -6,8 +6,9 @@ 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("../personas/
|
|
10
|
-
const index_js_2 = require("../personas/
|
|
9
|
+
const index_js_1 = require("../personas/content-reader/v1/index.js");
|
|
10
|
+
const index_js_2 = require("../personas/organization-audit/v1/index.js");
|
|
11
|
+
const index_js_3 = require("../personas/semantic-layer/v1/index.js");
|
|
11
12
|
const http_response_js_1 = require("./http-response.js");
|
|
12
13
|
const streamable_http_js_1 = require("./streamable-http.js");
|
|
13
14
|
const oauthConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
@@ -67,14 +68,18 @@ function clearMcpEnv() {
|
|
|
67
68
|
});
|
|
68
69
|
(0, vitest_1.describe)('streamable HTTP OAuth metadata', () => {
|
|
69
70
|
(0, vitest_1.it)('builds protected resource metadata with MCP host as authorization_servers', () => {
|
|
70
|
-
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig,
|
|
71
|
+
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PERSONA_PATH);
|
|
71
72
|
(0, vitest_1.expect)(metadata.authorization_servers).toEqual(['https://mcp.example.com']);
|
|
72
|
-
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${
|
|
73
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PERSONA_PATH}`);
|
|
73
74
|
(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');
|
|
74
75
|
});
|
|
75
76
|
(0, vitest_1.it)('builds organization-audit protected resource metadata', () => {
|
|
76
|
-
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig,
|
|
77
|
-
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${
|
|
77
|
+
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH);
|
|
78
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH}`);
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.it)('builds content-reader protected resource metadata', () => {
|
|
81
|
+
const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.CONTENT_READER_PERSONA_PATH);
|
|
82
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.CONTENT_READER_PERSONA_PATH}`);
|
|
78
83
|
});
|
|
79
84
|
(0, vitest_1.it)('builds WWW-Authenticate challenges with resource_metadata for OAuth clients', () => {
|
|
80
85
|
const header = (0, www_authenticate_js_1.buildWwwAuthenticateHeader)({
|
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
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, and content-governance personas.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
"@modelcontextprotocol/server": "2.0.0",
|
|
24
24
|
"commander": "^15.0.0",
|
|
25
25
|
"hono": "^4.12.32",
|
|
26
|
+
"redis": "^6.2.0",
|
|
26
27
|
"zod": "^4.4.3",
|
|
27
|
-
"@lightdash-tools/client": "0.
|
|
28
|
-
"@lightdash-tools/common": "0.
|
|
28
|
+
"@lightdash-tools/client": "0.8.0",
|
|
29
|
+
"@lightdash-tools/common": "0.8.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@modelcontextprotocol/client": "2.0.0",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"access": "public"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|
|
38
|
-
"build": "rm -rf dist && tsc &&
|
|
39
|
+
"build": "rm -rf dist && tsc && for p in semantic-layer organization-audit content-reader content-developer content-governance; do mkdir -p dist/personas/$p/v1/resources/playbooks && cp -R src/personas/$p/v1/resources/playbooks/. dist/personas/$p/v1/resources/playbooks/; done",
|
|
39
40
|
"start": "node dist/index.js",
|
|
40
41
|
"start:http": "node dist/http.js",
|
|
41
42
|
"test": "pnpm --dir ../.. exec vitest run packages/mcp/src"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Static organization-audit playbook resource.
|
|
3
|
-
*/
|
|
4
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
-
export declare const ORGANIZATION_AUDIT_PLAYBOOK_URI = "lightdash://playbooks/organization-audit";
|
|
6
|
-
export declare const ORGANIZATION_AUDIT_PLAYBOOK_MIME = "text/markdown";
|
|
7
|
-
export declare const ORGANIZATION_AUDIT_PLAYBOOK_NAME = "organization_audit_playbook";
|
|
8
|
-
export declare const ORGANIZATION_AUDIT_HARD_BANS = "Do not mutate users/groups/roles/content/schedulers, execute warehouse or chart queries, download user-activity CSV, reveal secrets, or claim compliance certification. Those capabilities are not available on this server.";
|
|
9
|
-
/** Loads playbook markdown from disk (next to this module after build). */
|
|
10
|
-
export declare function getPlaybookMarkdown(): string;
|
|
11
|
-
export declare function registerOrganizationAuditPlaybook(server: McpServer): void;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Static organization-audit playbook resource.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ORGANIZATION_AUDIT_HARD_BANS = exports.ORGANIZATION_AUDIT_PLAYBOOK_NAME = exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME = exports.ORGANIZATION_AUDIT_PLAYBOOK_URI = void 0;
|
|
7
|
-
exports.getPlaybookMarkdown = getPlaybookMarkdown;
|
|
8
|
-
exports.registerOrganizationAuditPlaybook = registerOrganizationAuditPlaybook;
|
|
9
|
-
const node_fs_1 = require("node:fs");
|
|
10
|
-
const node_path_1 = require("node:path");
|
|
11
|
-
exports.ORGANIZATION_AUDIT_PLAYBOOK_URI = 'lightdash://playbooks/organization-audit';
|
|
12
|
-
exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME = 'text/markdown';
|
|
13
|
-
exports.ORGANIZATION_AUDIT_PLAYBOOK_NAME = 'organization_audit_playbook';
|
|
14
|
-
exports.ORGANIZATION_AUDIT_HARD_BANS = 'Do not mutate users/groups/roles/content/schedulers, execute warehouse or chart queries, download user-activity CSV, reveal secrets, or claim compliance certification. Those capabilities are not available on this server.';
|
|
15
|
-
let cachedPlaybookMarkdown;
|
|
16
|
-
/** Loads playbook markdown from disk (next to this module after build). */
|
|
17
|
-
function getPlaybookMarkdown() {
|
|
18
|
-
if (cachedPlaybookMarkdown !== undefined) {
|
|
19
|
-
return cachedPlaybookMarkdown;
|
|
20
|
-
}
|
|
21
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- __dirname + constant filename
|
|
22
|
-
cachedPlaybookMarkdown = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, 'playbook.md'), 'utf8');
|
|
23
|
-
return cachedPlaybookMarkdown;
|
|
24
|
-
}
|
|
25
|
-
function registerOrganizationAuditPlaybook(server) {
|
|
26
|
-
const markdown = getPlaybookMarkdown();
|
|
27
|
-
server.registerResource(exports.ORGANIZATION_AUDIT_PLAYBOOK_NAME, exports.ORGANIZATION_AUDIT_PLAYBOOK_URI, {
|
|
28
|
-
title: 'Organization-audit playbook',
|
|
29
|
-
description: 'How to inventory and audit Lightdash organization identity, access, content health, and deliveries',
|
|
30
|
-
mimeType: exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME,
|
|
31
|
-
}, async (uri) => ({
|
|
32
|
-
contents: [
|
|
33
|
-
{
|
|
34
|
-
uri: typeof uri === 'string' ? uri : uri.href,
|
|
35
|
-
mimeType: exports.ORGANIZATION_AUDIT_PLAYBOOK_MIME,
|
|
36
|
-
text: markdown,
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Static semantic-layer playbook resource.
|
|
3
|
-
*/
|
|
4
|
-
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
-
export declare const SEMANTIC_LAYER_PLAYBOOK_URI = "lightdash://playbooks/semantic-layer";
|
|
6
|
-
export declare const SEMANTIC_LAYER_PLAYBOOK_MIME = "text/markdown";
|
|
7
|
-
export declare const SEMANTIC_LAYER_PLAYBOOK_NAME = "semantic_layer_playbook";
|
|
8
|
-
/** Shared hard-ban text for prompts (keep in sync with playbook.md Hard bans section). */
|
|
9
|
-
export declare const SEMANTIC_LAYER_HARD_BANS = "Do not run metric/SQL/chart queries, use SQL runner, trigger validation jobs, mutate content, or call AI/identity tools. Those are not available on this server.";
|
|
10
|
-
/** Loads playbook markdown from disk (next to this module after build). */
|
|
11
|
-
export declare function getPlaybookMarkdown(): string;
|
|
12
|
-
export declare function registerPlaybookResource(server: McpServer): void;
|