@lightdash-tools/mcp 0.6.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 +205 -58
- package/dist/audit/audit.d.ts +5 -0
- package/dist/{audit.js → audit/audit.js} +1 -2
- package/dist/audit/tool-audit-context.d.ts +6 -0
- package/dist/audit/tool-audit-context.js +12 -0
- package/dist/audit/tool-audit-context.test.d.ts +1 -0
- package/dist/audit/tool-audit-context.test.js +19 -0
- package/dist/auth/auth-mode.d.ts +4 -0
- package/dist/auth/auth-mode.js +6 -0
- package/dist/auth/bearer.d.ts +3 -0
- package/dist/auth/bearer.js +13 -0
- package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
- package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
- package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
- package/dist/auth/oauth-broker/as-metadata.js +20 -0
- package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
- package/dist/auth/oauth-broker/lightdash-token.js +76 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +127 -0
- package/dist/auth/oauth-broker/pending-store.js +151 -0
- 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/pkce.d.ts +2 -0
- package/dist/auth/oauth-broker/pkce.js +17 -0
- package/dist/auth/oauth-broker/routes.d.ts +13 -0
- package/dist/auth/oauth-broker/routes.js +452 -0
- package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
- package/dist/auth/oauth-broker/routes.test.js +242 -0
- package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
- package/dist/auth/providers/bearer-context-provider.js +52 -0
- package/dist/auth/providers/env-context-provider.d.ts +13 -0
- package/dist/auth/providers/env-context-provider.js +19 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
- package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
- package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
- package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
- package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
- package/dist/auth/resource-server/shared-key-middleware.js +24 -0
- package/dist/auth/resource-server/token-scopes.d.ts +15 -0
- package/dist/auth/resource-server/token-scopes.js +76 -0
- package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
- package/dist/auth/resource-server/token-scopes.test.js +51 -0
- package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
- package/dist/auth/resource-server/token-validation-cache.js +44 -0
- package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
- package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
- package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
- package/dist/auth/resource-server/token-validation-error.js +13 -0
- package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
- package/dist/auth/resource-server/www-authenticate.js +24 -0
- package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
- package/dist/auth/resource-server/www-authenticate.test.js +70 -0
- package/dist/auth/token-hash.d.ts +2 -0
- package/dist/auth/token-hash.js +8 -0
- package/dist/bin.d.ts +0 -4
- package/dist/bin.js +62 -33
- package/dist/config/env.d.ts +57 -0
- package/dist/config/env.js +60 -0
- package/dist/config/load-mcp-config.d.ts +30 -0
- package/dist/config/load-mcp-config.js +286 -0
- package/dist/config/load-mcp-config.test.d.ts +1 -0
- package/dist/config/load-mcp-config.test.js +202 -0
- package/dist/config/normalize-url.d.ts +13 -0
- package/dist/config/normalize-url.js +52 -0
- package/dist/config/normalize-url.test.d.ts +1 -0
- package/dist/config/normalize-url.test.js +47 -0
- package/dist/config/public-url.d.ts +3 -0
- package/dist/config/public-url.js +10 -0
- package/dist/config/runtime.d.ts +15 -0
- package/dist/config/runtime.js +48 -0
- package/dist/config/runtime.test.d.ts +1 -0
- package/dist/config/runtime.test.js +69 -0
- package/dist/config/test-mcp-http-config.d.ts +3 -0
- package/dist/config/test-mcp-http-config.js +7 -0
- package/dist/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-pin.d.ts +14 -0
- package/dist/governance/project-pin.js +44 -0
- package/dist/governance/project-pin.test.d.ts +1 -0
- package/dist/governance/project-pin.test.js +35 -0
- package/dist/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.d.ts +1 -2
- package/dist/http.integration.test.d.ts +1 -0
- package/dist/http.integration.test.js +722 -0
- package/dist/http.js +3 -170
- package/dist/http.test.d.ts +4 -0
- package/dist/http.test.js +131 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.integration.test.js +73 -30
- package/dist/index.js +28 -27
- package/dist/index.test.js +3 -3
- package/dist/logging/structured.d.ts +27 -0
- package/dist/logging/structured.js +32 -0
- package/dist/logging/structured.test.d.ts +1 -0
- package/dist/logging/structured.test.js +33 -0
- package/dist/personas/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 +22 -0
- package/dist/personas/index.js +73 -0
- package/dist/personas/index.test.d.ts +1 -0
- package/dist/personas/index.test.js +109 -0
- 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.d.ts +8 -0
- package/dist/personas/organization-audit/v1/index.js +42 -0
- package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
- package/dist/personas/organization-audit/v1/prompts.js +92 -0
- package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
- package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +13 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +9 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/core.md +36 -0
- 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.d.ts +8 -0
- package/dist/personas/semantic-layer/v1/index.js +32 -0
- package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
- package/dist/personas/semantic-layer/v1/prompts.js +85 -0
- 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 +19 -0
- package/dist/personas/types.js +5 -0
- 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/protocol-contract.test.d.ts +1 -0
- package/dist/protocol-contract.test.js +42 -0
- package/dist/server/capabilities.d.ts +15 -0
- package/dist/server/capabilities.js +19 -0
- package/dist/server/capabilities.test.d.ts +1 -0
- package/dist/server/capabilities.test.js +41 -0
- package/dist/server/errors.test.d.ts +1 -0
- package/dist/server/errors.test.js +53 -0
- package/dist/server/request-context.d.ts +13 -0
- package/dist/server/request-context.js +2 -0
- package/dist/server/server.d.ts +4 -0
- package/dist/server/server.js +28 -0
- package/dist/server/server.test.d.ts +1 -0
- package/dist/server/server.test.js +15 -0
- package/dist/server/version.d.ts +1 -0
- package/dist/server/version.js +7 -0
- package/dist/server/version.test.d.ts +1 -0
- package/dist/server/version.test.js +9 -0
- package/dist/stdio.process.test.d.ts +1 -0
- package/dist/stdio.process.test.js +274 -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/index.d.ts +2 -4
- package/dist/tools/index.js +4 -30
- package/dist/tools/index.test.d.ts +1 -0
- package/dist/tools/index.test.js +72 -0
- package/dist/tools/lib/api-errors.d.ts +11 -0
- package/dist/tools/lib/api-errors.js +27 -0
- package/dist/tools/lib/api-shape.d.ts +16 -0
- package/dist/tools/lib/api-shape.js +47 -0
- package/dist/tools/lib/assert-safe.d.ts +13 -0
- package/dist/tools/lib/assert-safe.js +21 -0
- package/dist/tools/lib/assert-safe.test.d.ts +4 -0
- package/dist/tools/lib/assert-safe.test.js +32 -0
- package/dist/tools/lib/concurrency.d.ts +4 -0
- package/dist/tools/lib/concurrency.js +24 -0
- package/dist/tools/lib/contracts.d.ts +34 -0
- package/dist/tools/lib/contracts.js +30 -0
- package/dist/tools/lib/redaction.d.ts +107 -0
- package/dist/tools/lib/redaction.js +299 -0
- package/dist/tools/lib/redaction.test.d.ts +4 -0
- package/dist/tools/lib/redaction.test.js +216 -0
- package/dist/tools/lib/register-org-audit.d.ts +9 -0
- package/dist/tools/lib/register-org-audit.js +20 -0
- package/dist/tools/lib/schema-fields.d.ts +9 -0
- package/dist/tools/lib/schema-fields.js +19 -0
- package/dist/tools/lib/stable-stringify.d.ts +9 -0
- package/dist/tools/lib/stable-stringify.js +35 -0
- package/dist/tools/organization/binding.d.ts +14 -0
- package/dist/tools/organization/binding.js +31 -0
- package/dist/tools/organization/invariants.test.d.ts +4 -0
- package/dist/tools/organization/invariants.test.js +28 -0
- package/dist/tools/organization/inventory.d.ts +10 -0
- package/dist/tools/organization/inventory.js +189 -0
- package/dist/tools/organization/roles.d.ts +10 -0
- package/dist/tools/organization/roles.js +213 -0
- package/dist/tools/project/content.d.ts +9 -0
- package/dist/tools/project/content.js +192 -0
- package/dist/tools/project/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 +10 -0
- package/dist/tools/project/projects.js +102 -0
- package/dist/tools/project/projects.test.d.ts +1 -0
- package/dist/tools/project/projects.test.js +154 -0
- 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/schedulers.d.ts +7 -0
- package/dist/tools/project/schedulers.js +115 -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 +225 -0
- package/dist/tools/registry.js +115 -0
- package/dist/tools/semantic/explore-helpers.d.ts +56 -0
- package/dist/tools/semantic/explore-helpers.js +115 -0
- package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
- package/dist/tools/semantic/explore-helpers.test.js +170 -0
- package/dist/tools/semantic/explores.d.ts +9 -0
- package/dist/tools/semantic/explores.js +80 -0
- package/dist/tools/semantic/metrics.d.ts +7 -0
- package/dist/tools/semantic/metrics.js +53 -0
- package/dist/tools/semantic/query.d.ts +6 -0
- package/dist/tools/semantic/query.js +42 -0
- package/dist/tools/semantic/schema-fields.d.ts +3 -0
- package/dist/tools/semantic/schema-fields.js +7 -0
- package/dist/tools/shared.d.ts +51 -15
- package/dist/tools/shared.js +171 -163
- package/dist/tools/shared.test.js +137 -184
- package/dist/tools/space/access.d.ts +66 -0
- package/dist/tools/space/access.js +322 -0
- package/dist/tools/space/access.test.d.ts +4 -0
- package/dist/tools/space/access.test.js +90 -0
- package/dist/transports/http-body.d.ts +5 -0
- package/dist/transports/http-body.js +50 -0
- package/dist/transports/http-request-utils.d.ts +2 -0
- package/dist/transports/http-request-utils.js +13 -0
- package/dist/transports/http-response.d.ts +6 -0
- package/dist/transports/http-response.js +56 -0
- package/dist/transports/session-store.d.ts +72 -0
- package/dist/transports/session-store.js +143 -0
- package/dist/transports/session-store.test.d.ts +1 -0
- package/dist/transports/session-store.test.js +111 -0
- package/dist/transports/streamable-http.d.ts +9 -0
- package/dist/transports/streamable-http.js +461 -0
- package/dist/transports/streamable-http.test.d.ts +1 -0
- package/dist/transports/streamable-http.test.js +100 -0
- package/package.json +26 -10
- package/dist/audit.d.ts +0 -6
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -82
- package/dist/tools/ai-agents.d.ts +0 -6
- package/dist/tools/ai-agents.js +0 -388
- package/dist/tools/charts.d.ts +0 -6
- package/dist/tools/charts.js +0 -55
- package/dist/tools/content.d.ts +0 -6
- package/dist/tools/content.js +0 -37
- package/dist/tools/dashboards.d.ts +0 -6
- package/dist/tools/dashboards.js +0 -28
- package/dist/tools/explores.d.ts +0 -6
- package/dist/tools/explores.js +0 -65
- package/dist/tools/groups.d.ts +0 -6
- package/dist/tools/groups.js +0 -121
- package/dist/tools/metrics.d.ts +0 -6
- package/dist/tools/metrics.js +0 -45
- package/dist/tools/projects.d.ts +0 -6
- package/dist/tools/projects.js +0 -58
- package/dist/tools/query.d.ts +0 -6
- package/dist/tools/query.js +0 -34
- package/dist/tools/schedulers.d.ts +0 -6
- package/dist/tools/schedulers.js +0 -45
- package/dist/tools/spaces.d.ts +0 -6
- package/dist/tools/spaces.js +0 -128
- package/dist/tools/tags.d.ts +0 -6
- package/dist/tools/tags.js +0 -28
- package/dist/tools/users.d.ts +0 -6
- package/dist/tools/users.js +0 -50
- package/src/audit.ts +0 -6
- package/src/bin.ts +0 -58
- package/src/config.ts +0 -83
- package/src/errors.ts +0 -27
- package/src/http.ts +0 -187
- package/src/index.integration.test.ts +0 -57
- package/src/index.test.ts +0 -8
- package/src/index.ts +0 -31
- package/src/tools/ai-agents.ts +0 -759
- package/src/tools/charts.ts +0 -85
- package/src/tools/content.ts +0 -44
- package/src/tools/dashboards.ts +0 -25
- package/src/tools/explores.ts +0 -98
- package/src/tools/groups.ts +0 -180
- package/src/tools/index.ts +0 -35
- package/src/tools/metrics.ts +0 -42
- package/src/tools/projects.ts +0 -74
- package/src/tools/query.ts +0 -47
- package/src/tools/schedulers.ts +0 -42
- package/src/tools/shared.test.ts +0 -365
- package/src/tools/shared.ts +0 -274
- package/src/tools/spaces.ts +0 -217
- package/src/tools/tags.ts +0 -25
- package/src/tools/users.ts +0 -64
- package/tsconfig.json +0 -13
- /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
- /package/dist/{errors.js → server/errors.js} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const config_js_1 = require("./config.js");
|
|
5
|
+
(0, vitest_1.describe)('resolveEphemeralStoreConfig', () => {
|
|
6
|
+
const originalStore = process.env.LIGHTDASH_TOOLS_MCP_STORE;
|
|
7
|
+
const originalRedis = process.env.LIGHTDASH_TOOLS_MCP_REDIS_URL;
|
|
8
|
+
(0, vitest_1.afterEach)(() => {
|
|
9
|
+
if (originalStore === undefined) {
|
|
10
|
+
delete process.env.LIGHTDASH_TOOLS_MCP_STORE;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
process.env.LIGHTDASH_TOOLS_MCP_STORE = originalStore;
|
|
14
|
+
}
|
|
15
|
+
if (originalRedis === undefined) {
|
|
16
|
+
delete process.env.LIGHTDASH_TOOLS_MCP_REDIS_URL;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
process.env.LIGHTDASH_TOOLS_MCP_REDIS_URL = originalRedis;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('defaults to memory', () => {
|
|
23
|
+
(0, vitest_1.expect)((0, config_js_1.resolveEphemeralStoreConfig)({})).toEqual({ backend: 'memory' });
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('accepts explicit memory', () => {
|
|
26
|
+
(0, vitest_1.expect)((0, config_js_1.resolveEphemeralStoreConfig)({ LIGHTDASH_TOOLS_MCP_STORE: 'memory' })).toEqual({
|
|
27
|
+
backend: 'memory',
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('requires REDIS_URL when store=redis', () => {
|
|
31
|
+
(0, vitest_1.expect)(() => (0, config_js_1.resolveEphemeralStoreConfig)({ LIGHTDASH_TOOLS_MCP_STORE: 'redis' })).toThrow(/LIGHTDASH_TOOLS_MCP_REDIS_URL/);
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)('returns redis config when URL is set', () => {
|
|
34
|
+
(0, vitest_1.expect)((0, config_js_1.resolveEphemeralStoreConfig)({
|
|
35
|
+
LIGHTDASH_TOOLS_MCP_STORE: 'redis',
|
|
36
|
+
LIGHTDASH_TOOLS_MCP_REDIS_URL: 'redis://localhost:6379',
|
|
37
|
+
})).toEqual({ backend: 'redis', redisUrl: 'redis://localhost:6379' });
|
|
38
|
+
});
|
|
39
|
+
(0, vitest_1.it)('rejects unknown store values', () => {
|
|
40
|
+
(0, vitest_1.expect)(() => (0, config_js_1.resolveEphemeralStoreConfig)({ LIGHTDASH_TOOLS_MCP_STORE: 'postgres' })).toThrow(/memory' or 'redis/);
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('emitEphemeralStoreHttpWarning warns for memory', () => {
|
|
43
|
+
const warnings = [];
|
|
44
|
+
const original = console.warn;
|
|
45
|
+
console.warn = (msg) => {
|
|
46
|
+
warnings.push(msg);
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
(0, config_js_1.emitEphemeralStoreHttpWarning)({ backend: 'memory' });
|
|
50
|
+
(0, vitest_1.expect)(warnings.some((w) => w.includes('in-memory'))).toBe(true);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
console.warn = original;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for OAuthBrokerStore (ADR-0016).
|
|
3
|
+
*/
|
|
4
|
+
import type { EphemeralStoreConfig } from './types.js';
|
|
5
|
+
import type { OAuthBrokerStore, OAuthBrokerStoreOptions } from '../auth/oauth-broker/pending-store.js';
|
|
6
|
+
export declare function createOAuthBrokerStore(config?: EphemeralStoreConfig, options?: OAuthBrokerStoreOptions): OAuthBrokerStore;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for OAuthBrokerStore (ADR-0016).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createOAuthBrokerStore = createOAuthBrokerStore;
|
|
7
|
+
const pending_store_js_1 = require("../auth/oauth-broker/pending-store.js");
|
|
8
|
+
const config_js_1 = require("./config.js");
|
|
9
|
+
const redis_client_js_1 = require("./redis-client.js");
|
|
10
|
+
const redis_oauth_broker_store_js_1 = require("./redis-oauth-broker-store.js");
|
|
11
|
+
function createOAuthBrokerStore(config = (0, config_js_1.resolveEphemeralStoreConfig)(), options = {}) {
|
|
12
|
+
if (config.backend === 'memory') {
|
|
13
|
+
return new pending_store_js_1.InMemoryOAuthBrokerStore(options);
|
|
14
|
+
}
|
|
15
|
+
return new redis_oauth_broker_store_js_1.RedisOAuthBrokerStore(() => (0, redis_client_js_1.getSharedRedisClient)(config), options);
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory + process singleton for PreviewStore (ADR-0016).
|
|
3
|
+
*/
|
|
4
|
+
import type { EphemeralStoreConfig } from './types.js';
|
|
5
|
+
import type { PreviewStore } from '../policy/preview-ledger.js';
|
|
6
|
+
export declare function createPreviewStore(config?: EphemeralStoreConfig): PreviewStore;
|
|
7
|
+
/** Lazy process singleton (memory by default; redis when configured). */
|
|
8
|
+
export declare function getPreviewStore(): PreviewStore;
|
|
9
|
+
/** Test helper: inject or clear the process singleton. */
|
|
10
|
+
export declare function setPreviewStoreForTests(store: PreviewStore | undefined): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Factory + process singleton for PreviewStore (ADR-0016).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createPreviewStore = createPreviewStore;
|
|
7
|
+
exports.getPreviewStore = getPreviewStore;
|
|
8
|
+
exports.setPreviewStoreForTests = setPreviewStoreForTests;
|
|
9
|
+
const config_js_1 = require("./config.js");
|
|
10
|
+
const in_memory_preview_store_js_1 = require("./in-memory-preview-store.js");
|
|
11
|
+
const redis_client_js_1 = require("./redis-client.js");
|
|
12
|
+
const redis_preview_store_js_1 = require("./redis-preview-store.js");
|
|
13
|
+
function createPreviewStore(config = (0, config_js_1.resolveEphemeralStoreConfig)()) {
|
|
14
|
+
if (config.backend === 'memory') {
|
|
15
|
+
return new in_memory_preview_store_js_1.InMemoryPreviewStore();
|
|
16
|
+
}
|
|
17
|
+
return new redis_preview_store_js_1.RedisPreviewStore(() => (0, redis_client_js_1.getSharedRedisClient)(config));
|
|
18
|
+
}
|
|
19
|
+
let processStore;
|
|
20
|
+
/** Lazy process singleton (memory by default; redis when configured). */
|
|
21
|
+
function getPreviewStore() {
|
|
22
|
+
if (!processStore) {
|
|
23
|
+
processStore = createPreviewStore();
|
|
24
|
+
}
|
|
25
|
+
return processStore;
|
|
26
|
+
}
|
|
27
|
+
/** Test helper: inject or clear the process singleton. */
|
|
28
|
+
function setPreviewStoreForTests(store) {
|
|
29
|
+
processStore = store;
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for hybrid SessionStore (ADR-0016).
|
|
3
|
+
*/
|
|
4
|
+
import { SessionStore } from '../transports/session-store.js';
|
|
5
|
+
import type { EphemeralStoreConfig } from './types.js';
|
|
6
|
+
export type CreateSessionStoreOptions = {
|
|
7
|
+
sessionTtlMs: number;
|
|
8
|
+
maxSessions: number;
|
|
9
|
+
/** `0` disables the per-subject cap. */
|
|
10
|
+
maxSessionsPerSubject: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Build a SessionStore for the configured ephemeral backend.
|
|
14
|
+
*
|
|
15
|
+
* - memory: process-local Map only
|
|
16
|
+
* - redis: process-local transports + Redis session index (sticky still required
|
|
17
|
+
* for Streamable HTTP transport affinity)
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSessionStore(config: EphemeralStoreConfig | undefined, options: CreateSessionStoreOptions): SessionStore;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for hybrid SessionStore (ADR-0016).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSessionStore = createSessionStore;
|
|
7
|
+
const session_store_js_1 = require("../transports/session-store.js");
|
|
8
|
+
const config_js_1 = require("./config.js");
|
|
9
|
+
const redis_client_js_1 = require("./redis-client.js");
|
|
10
|
+
const redis_session_index_js_1 = require("./redis-session-index.js");
|
|
11
|
+
/**
|
|
12
|
+
* Build a SessionStore for the configured ephemeral backend.
|
|
13
|
+
*
|
|
14
|
+
* - memory: process-local Map only
|
|
15
|
+
* - redis: process-local transports + Redis session index (sticky still required
|
|
16
|
+
* for Streamable HTTP transport affinity)
|
|
17
|
+
*/
|
|
18
|
+
function createSessionStore(config = (0, config_js_1.resolveEphemeralStoreConfig)(), options) {
|
|
19
|
+
if (config.backend === 'memory') {
|
|
20
|
+
return new session_store_js_1.SessionStore(options.sessionTtlMs, options.maxSessions, options.maxSessionsPerSubject);
|
|
21
|
+
}
|
|
22
|
+
const index = new redis_session_index_js_1.RedisSessionIndex(() => (0, redis_client_js_1.getSharedRedisClient)(config), options.sessionTtlMs);
|
|
23
|
+
return new session_store_js_1.SessionStore(options.sessionTtlMs, options.maxSessions, options.maxSessionsPerSubject, index);
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local PreviewStore with a mutex serializing compareAndSwap (ADR-0016).
|
|
3
|
+
*/
|
|
4
|
+
import type { PreviewLedgerEntry, PreviewStatus, PreviewStore } from '../policy/preview-ledger.js';
|
|
5
|
+
export declare class InMemoryPreviewStore implements PreviewStore {
|
|
6
|
+
private readonly entries;
|
|
7
|
+
/** Promise chain mutex so CAS is atomic within the process. */
|
|
8
|
+
private lock;
|
|
9
|
+
private withLock;
|
|
10
|
+
get(previewId: string): Promise<PreviewLedgerEntry | undefined>;
|
|
11
|
+
put(entry: PreviewLedgerEntry): Promise<void>;
|
|
12
|
+
compareAndSwap(previewId: string, expectedStatus: PreviewStatus, next: PreviewLedgerEntry): Promise<boolean>;
|
|
13
|
+
compareAndDelete(previewId: string, expectedStatus: PreviewStatus): Promise<boolean>;
|
|
14
|
+
delete(previewId: string): Promise<void>;
|
|
15
|
+
/** Test helper. */
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Process-local PreviewStore with a mutex serializing compareAndSwap (ADR-0016).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InMemoryPreviewStore = void 0;
|
|
7
|
+
class InMemoryPreviewStore {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.entries = new Map();
|
|
10
|
+
/** Promise chain mutex so CAS is atomic within the process. */
|
|
11
|
+
this.lock = Promise.resolve();
|
|
12
|
+
}
|
|
13
|
+
async withLock(fn) {
|
|
14
|
+
let release;
|
|
15
|
+
const next = new Promise((resolve) => {
|
|
16
|
+
release = resolve;
|
|
17
|
+
});
|
|
18
|
+
const previous = this.lock;
|
|
19
|
+
this.lock = previous.then(() => next, () => next);
|
|
20
|
+
await previous;
|
|
21
|
+
try {
|
|
22
|
+
return await fn();
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
release();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async get(previewId) {
|
|
29
|
+
return this.withLock(() => {
|
|
30
|
+
const entry = this.entries.get(previewId);
|
|
31
|
+
return entry ? structuredClone(entry) : undefined;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async put(entry) {
|
|
35
|
+
await this.withLock(() => {
|
|
36
|
+
this.entries.set(entry.previewId, structuredClone(entry));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async compareAndSwap(previewId, expectedStatus, next) {
|
|
40
|
+
return this.withLock(() => {
|
|
41
|
+
const current = this.entries.get(previewId);
|
|
42
|
+
if (!current || current.status !== expectedStatus) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (next.previewId !== previewId) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
this.entries.set(previewId, structuredClone(next));
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async compareAndDelete(previewId, expectedStatus) {
|
|
53
|
+
return this.withLock(() => {
|
|
54
|
+
const current = this.entries.get(previewId);
|
|
55
|
+
if (!current || current.status !== expectedStatus) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
this.entries.delete(previewId);
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async delete(previewId) {
|
|
63
|
+
await this.withLock(() => {
|
|
64
|
+
this.entries.delete(previewId);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Test helper. */
|
|
68
|
+
clear() {
|
|
69
|
+
this.entries.clear();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.InMemoryPreviewStore = InMemoryPreviewStore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy shared Redis client for MCP ephemeral store backends (ADR-0016).
|
|
3
|
+
*/
|
|
4
|
+
import { type RedisClientType } from 'redis';
|
|
5
|
+
import type { EphemeralStoreConfig } from './types.js';
|
|
6
|
+
/** Return a connected Redis client for `config.redisUrl` (one shared connection). */
|
|
7
|
+
export declare function getSharedRedisClient(config: Extract<EphemeralStoreConfig, {
|
|
8
|
+
backend: 'redis';
|
|
9
|
+
}>): Promise<RedisClientType>;
|
|
10
|
+
/** Test helper: drop the shared client (does not quit a live connection unless open). */
|
|
11
|
+
export declare function resetSharedRedisClientForTests(): Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Lazy shared Redis client for MCP ephemeral store backends (ADR-0016).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSharedRedisClient = getSharedRedisClient;
|
|
7
|
+
exports.resetSharedRedisClientForTests = resetSharedRedisClientForTests;
|
|
8
|
+
const redis_1 = require("redis");
|
|
9
|
+
let sharedClient;
|
|
10
|
+
let sharedClientUrl;
|
|
11
|
+
let connectPromise;
|
|
12
|
+
/** Return a connected Redis client for `config.redisUrl` (one shared connection). */
|
|
13
|
+
async function getSharedRedisClient(config) {
|
|
14
|
+
if ((sharedClient === null || sharedClient === void 0 ? void 0 : sharedClient.isOpen) && sharedClientUrl === config.redisUrl) {
|
|
15
|
+
return sharedClient;
|
|
16
|
+
}
|
|
17
|
+
if (connectPromise && sharedClientUrl === config.redisUrl) {
|
|
18
|
+
return connectPromise;
|
|
19
|
+
}
|
|
20
|
+
sharedClientUrl = config.redisUrl;
|
|
21
|
+
const client = (0, redis_1.createClient)({ url: config.redisUrl });
|
|
22
|
+
client.on('error', (err) => {
|
|
23
|
+
console.error('MCP Redis client error:', err.message);
|
|
24
|
+
});
|
|
25
|
+
connectPromise = client
|
|
26
|
+
.connect()
|
|
27
|
+
.then(() => {
|
|
28
|
+
sharedClient = client;
|
|
29
|
+
return sharedClient;
|
|
30
|
+
})
|
|
31
|
+
.catch((err) => {
|
|
32
|
+
connectPromise = undefined;
|
|
33
|
+
sharedClient = undefined;
|
|
34
|
+
sharedClientUrl = undefined;
|
|
35
|
+
throw err;
|
|
36
|
+
});
|
|
37
|
+
return connectPromise;
|
|
38
|
+
}
|
|
39
|
+
/** Test helper: drop the shared client (does not quit a live connection unless open). */
|
|
40
|
+
async function resetSharedRedisClientForTests() {
|
|
41
|
+
const client = sharedClient;
|
|
42
|
+
sharedClient = undefined;
|
|
43
|
+
sharedClientUrl = undefined;
|
|
44
|
+
connectPromise = undefined;
|
|
45
|
+
if (client === null || client === void 0 ? void 0 : client.isOpen) {
|
|
46
|
+
await client.quit();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis-backed OAuthBrokerStore (ADR-0016).
|
|
3
|
+
*
|
|
4
|
+
* Fully serializable pending state, authorization codes, and DCR clients —
|
|
5
|
+
* the high-value multi-instance fix for authorize → callback → token.
|
|
6
|
+
*
|
|
7
|
+
* Key prefix: `lightdash-tools:mcp:oauth:`.
|
|
8
|
+
* DCR clients are capacity-capped via a ZSET index (same contract as in-memory maxClients).
|
|
9
|
+
*/
|
|
10
|
+
import { type IssuedAuthorizationCode, type OAuthBrokerStore, type OAuthBrokerStoreOptions, type PendingAuthorization, type RegisteredClient } from '../auth/oauth-broker/pending-store.js';
|
|
11
|
+
import type { RedisClientType } from 'redis';
|
|
12
|
+
export declare const OAUTH_REDIS_KEY_PREFIX = "lightdash-tools:mcp:oauth:";
|
|
13
|
+
export declare const OAUTH_CLIENTS_INDEX_KEY = "lightdash-tools:mcp:oauth:clients";
|
|
14
|
+
/**
|
|
15
|
+
* Atomic DCR register: prune expired index members, enforce maxClients, then
|
|
16
|
+
* SET client key + ZADD index (score = absolute expiry ms).
|
|
17
|
+
* Returns 1 on success, 0 when at capacity.
|
|
18
|
+
*/
|
|
19
|
+
export declare const REGISTER_CLIENT_LUA = "\nlocal indexKey = KEYS[1]\nlocal clientKey = KEYS[2]\nlocal now = tonumber(ARGV[1])\nlocal maxClients = tonumber(ARGV[2])\nlocal ttlMs = tonumber(ARGV[3])\nlocal clientJson = ARGV[4]\nlocal clientId = ARGV[5]\nlocal expiresAt = now + ttlMs\nredis.call('ZREMRANGEBYSCORE', indexKey, '-inf', now)\nif redis.call('ZCARD', indexKey) >= maxClients then\n return 0\nend\nredis.call('SET', clientKey, clientJson, 'PX', ttlMs)\nredis.call('ZADD', indexKey, expiresAt, clientId)\nreturn 1\n";
|
|
20
|
+
export declare class RedisOAuthBrokerStore implements OAuthBrokerStore {
|
|
21
|
+
private readonly resolveRedis;
|
|
22
|
+
private readonly pendingTtlMs;
|
|
23
|
+
private readonly codeTtlMs;
|
|
24
|
+
private readonly clientTtlMs;
|
|
25
|
+
private readonly maxClients;
|
|
26
|
+
constructor(resolveRedis: () => Promise<RedisClientType>, options?: OAuthBrokerStoreOptions);
|
|
27
|
+
registerClient(redirectUris: readonly string[]): Promise<RegisteredClient | undefined>;
|
|
28
|
+
getClient(clientId: string): Promise<RegisteredClient | undefined>;
|
|
29
|
+
isRedirectAllowedForClient(clientId: string, redirectUri: string): Promise<boolean>;
|
|
30
|
+
createPending(input: Omit<PendingAuthorization, 'brokerState' | 'createdAt'>): Promise<PendingAuthorization | undefined>;
|
|
31
|
+
takePending(brokerState: string): Promise<PendingAuthorization | undefined>;
|
|
32
|
+
issueCode(pending: PendingAuthorization, tokens: {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
expiresIn?: number;
|
|
35
|
+
tokenType?: string;
|
|
36
|
+
scope?: string;
|
|
37
|
+
}): Promise<IssuedAuthorizationCode | undefined>;
|
|
38
|
+
takeCode(code: string): Promise<IssuedAuthorizationCode | undefined>;
|
|
39
|
+
restoreCode(issued: IssuedAuthorizationCode): Promise<void>;
|
|
40
|
+
getCode(code: string): Promise<IssuedAuthorizationCode | undefined>;
|
|
41
|
+
deleteCode(code: string): Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Redis-backed OAuthBrokerStore (ADR-0016).
|
|
4
|
+
*
|
|
5
|
+
* Fully serializable pending state, authorization codes, and DCR clients —
|
|
6
|
+
* the high-value multi-instance fix for authorize → callback → token.
|
|
7
|
+
*
|
|
8
|
+
* Key prefix: `lightdash-tools:mcp:oauth:`.
|
|
9
|
+
* DCR clients are capacity-capped via a ZSET index (same contract as in-memory maxClients).
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RedisOAuthBrokerStore = exports.REGISTER_CLIENT_LUA = exports.OAUTH_CLIENTS_INDEX_KEY = exports.OAUTH_REDIS_KEY_PREFIX = void 0;
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
14
|
+
const pending_store_js_1 = require("../auth/oauth-broker/pending-store.js");
|
|
15
|
+
exports.OAUTH_REDIS_KEY_PREFIX = 'lightdash-tools:mcp:oauth:';
|
|
16
|
+
exports.OAUTH_CLIENTS_INDEX_KEY = `${exports.OAUTH_REDIS_KEY_PREFIX}clients`;
|
|
17
|
+
/**
|
|
18
|
+
* Atomic DCR register: prune expired index members, enforce maxClients, then
|
|
19
|
+
* SET client key + ZADD index (score = absolute expiry ms).
|
|
20
|
+
* Returns 1 on success, 0 when at capacity.
|
|
21
|
+
*/
|
|
22
|
+
exports.REGISTER_CLIENT_LUA = `
|
|
23
|
+
local indexKey = KEYS[1]
|
|
24
|
+
local clientKey = KEYS[2]
|
|
25
|
+
local now = tonumber(ARGV[1])
|
|
26
|
+
local maxClients = tonumber(ARGV[2])
|
|
27
|
+
local ttlMs = tonumber(ARGV[3])
|
|
28
|
+
local clientJson = ARGV[4]
|
|
29
|
+
local clientId = ARGV[5]
|
|
30
|
+
local expiresAt = now + ttlMs
|
|
31
|
+
redis.call('ZREMRANGEBYSCORE', indexKey, '-inf', now)
|
|
32
|
+
if redis.call('ZCARD', indexKey) >= maxClients then
|
|
33
|
+
return 0
|
|
34
|
+
end
|
|
35
|
+
redis.call('SET', clientKey, clientJson, 'PX', ttlMs)
|
|
36
|
+
redis.call('ZADD', indexKey, expiresAt, clientId)
|
|
37
|
+
return 1
|
|
38
|
+
`;
|
|
39
|
+
function pendingKey(brokerState) {
|
|
40
|
+
return `${exports.OAUTH_REDIS_KEY_PREFIX}pending:${brokerState}`;
|
|
41
|
+
}
|
|
42
|
+
function codeKey(code) {
|
|
43
|
+
return `${exports.OAUTH_REDIS_KEY_PREFIX}code:${code}`;
|
|
44
|
+
}
|
|
45
|
+
function clientKey(clientId) {
|
|
46
|
+
return `${exports.OAUTH_REDIS_KEY_PREFIX}client:${clientId}`;
|
|
47
|
+
}
|
|
48
|
+
function toRegisteredClient(wire) {
|
|
49
|
+
return {
|
|
50
|
+
clientId: wire.clientId,
|
|
51
|
+
redirectUris: new Set(wire.redirectUris),
|
|
52
|
+
createdAt: wire.createdAt,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
class RedisOAuthBrokerStore {
|
|
56
|
+
constructor(resolveRedis, options = {}) {
|
|
57
|
+
var _a, _b, _c, _d;
|
|
58
|
+
this.resolveRedis = resolveRedis;
|
|
59
|
+
this.pendingTtlMs = (_a = options.pendingTtlMs) !== null && _a !== void 0 ? _a : pending_store_js_1.DEFAULT_PENDING_TTL_MS;
|
|
60
|
+
this.codeTtlMs = (_b = options.codeTtlMs) !== null && _b !== void 0 ? _b : pending_store_js_1.DEFAULT_CODE_TTL_MS;
|
|
61
|
+
this.clientTtlMs = (_c = options.clientTtlMs) !== null && _c !== void 0 ? _c : pending_store_js_1.DEFAULT_CLIENT_TTL_MS;
|
|
62
|
+
this.maxClients = (_d = options.maxClients) !== null && _d !== void 0 ? _d : pending_store_js_1.DEFAULT_MAX_CLIENTS;
|
|
63
|
+
}
|
|
64
|
+
async registerClient(redirectUris) {
|
|
65
|
+
const clientId = (0, node_crypto_1.randomBytes)(16).toString('base64url');
|
|
66
|
+
const wire = {
|
|
67
|
+
clientId,
|
|
68
|
+
redirectUris: [...redirectUris],
|
|
69
|
+
createdAt: Date.now(),
|
|
70
|
+
};
|
|
71
|
+
const redis = await this.resolveRedis();
|
|
72
|
+
const result = await redis.eval(exports.REGISTER_CLIENT_LUA, {
|
|
73
|
+
keys: [exports.OAUTH_CLIENTS_INDEX_KEY, clientKey(clientId)],
|
|
74
|
+
arguments: [
|
|
75
|
+
String(Date.now()),
|
|
76
|
+
String(this.maxClients),
|
|
77
|
+
String(this.clientTtlMs),
|
|
78
|
+
JSON.stringify(wire),
|
|
79
|
+
clientId,
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
if (result !== 1 && result !== BigInt(1)) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return toRegisteredClient(wire);
|
|
86
|
+
}
|
|
87
|
+
async getClient(clientId) {
|
|
88
|
+
const redis = await this.resolveRedis();
|
|
89
|
+
const raw = await redis.get(clientKey(clientId));
|
|
90
|
+
if (raw == null) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
return toRegisteredClient(JSON.parse(raw));
|
|
94
|
+
}
|
|
95
|
+
async isRedirectAllowedForClient(clientId, redirectUri) {
|
|
96
|
+
const registered = await this.getClient(clientId);
|
|
97
|
+
return registered !== undefined && registered.redirectUris.has(redirectUri);
|
|
98
|
+
}
|
|
99
|
+
async createPending(input) {
|
|
100
|
+
const pending = Object.assign(Object.assign({}, input), { brokerState: (0, node_crypto_1.randomBytes)(24).toString('base64url'), createdAt: Date.now() });
|
|
101
|
+
const redis = await this.resolveRedis();
|
|
102
|
+
await redis.set(pendingKey(pending.brokerState), JSON.stringify(pending), {
|
|
103
|
+
PX: this.pendingTtlMs,
|
|
104
|
+
});
|
|
105
|
+
return pending;
|
|
106
|
+
}
|
|
107
|
+
async takePending(brokerState) {
|
|
108
|
+
const redis = await this.resolveRedis();
|
|
109
|
+
const key = pendingKey(brokerState);
|
|
110
|
+
// Atomic consume (Redis 6.2+ GETDEL).
|
|
111
|
+
const raw = await redis.getDel(key);
|
|
112
|
+
if (raw == null) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
return JSON.parse(raw);
|
|
116
|
+
}
|
|
117
|
+
async issueCode(pending, tokens) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const issued = {
|
|
120
|
+
code: (0, node_crypto_1.randomBytes)(32).toString('base64url'),
|
|
121
|
+
clientId: pending.clientId,
|
|
122
|
+
redirectUri: pending.redirectUri,
|
|
123
|
+
codeChallenge: pending.codeChallenge,
|
|
124
|
+
codeChallengeMethod: pending.codeChallengeMethod,
|
|
125
|
+
accessToken: tokens.accessToken,
|
|
126
|
+
expiresIn: tokens.expiresIn,
|
|
127
|
+
tokenType: (_a = tokens.tokenType) !== null && _a !== void 0 ? _a : 'Bearer',
|
|
128
|
+
scope: (_b = tokens.scope) !== null && _b !== void 0 ? _b : pending.scope,
|
|
129
|
+
createdAt: Date.now(),
|
|
130
|
+
};
|
|
131
|
+
const redis = await this.resolveRedis();
|
|
132
|
+
await redis.set(codeKey(issued.code), JSON.stringify(issued), { PX: this.codeTtlMs });
|
|
133
|
+
return issued;
|
|
134
|
+
}
|
|
135
|
+
async takeCode(code) {
|
|
136
|
+
const redis = await this.resolveRedis();
|
|
137
|
+
// Atomic consume (Redis 6.2+ GETDEL) — same pattern as takePending.
|
|
138
|
+
const raw = await redis.getDel(codeKey(code));
|
|
139
|
+
if (raw == null) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
return JSON.parse(raw);
|
|
143
|
+
}
|
|
144
|
+
async restoreCode(issued) {
|
|
145
|
+
const remaining = this.codeTtlMs - (Date.now() - issued.createdAt);
|
|
146
|
+
if (remaining <= 0) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const redis = await this.resolveRedis();
|
|
150
|
+
await redis.set(codeKey(issued.code), JSON.stringify(issued), {
|
|
151
|
+
PX: Math.max(1, remaining),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async getCode(code) {
|
|
155
|
+
const redis = await this.resolveRedis();
|
|
156
|
+
const raw = await redis.get(codeKey(code));
|
|
157
|
+
if (raw == null) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
return JSON.parse(raw);
|
|
161
|
+
}
|
|
162
|
+
async deleteCode(code) {
|
|
163
|
+
const redis = await this.resolveRedis();
|
|
164
|
+
await redis.del(codeKey(code));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.RedisOAuthBrokerStore = RedisOAuthBrokerStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const redis_oauth_broker_store_js_1 = require("./redis-oauth-broker-store.js");
|
|
5
|
+
function createFakeRedis() {
|
|
6
|
+
const strings = new Map();
|
|
7
|
+
const clientIndex = new Map();
|
|
8
|
+
const evalFn = vitest_1.vi.fn(async (script, opts) => {
|
|
9
|
+
if (script !== redis_oauth_broker_store_js_1.REGISTER_CLIENT_LUA) {
|
|
10
|
+
throw new Error('unexpected lua script');
|
|
11
|
+
}
|
|
12
|
+
const [indexKey, clientKey] = opts.keys;
|
|
13
|
+
const [nowRaw, maxRaw, ttlRaw, clientJson, clientId] = opts.arguments;
|
|
14
|
+
(0, vitest_1.expect)(indexKey).toBe(redis_oauth_broker_store_js_1.OAUTH_CLIENTS_INDEX_KEY);
|
|
15
|
+
const now = Number(nowRaw);
|
|
16
|
+
const maxClients = Number(maxRaw);
|
|
17
|
+
const ttlMs = Number(ttlRaw);
|
|
18
|
+
for (const [id, expiresAt] of [...clientIndex.entries()]) {
|
|
19
|
+
if (expiresAt <= now) {
|
|
20
|
+
clientIndex.delete(id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (clientIndex.size >= maxClients) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
strings.set(clientKey, clientJson);
|
|
27
|
+
clientIndex.set(clientId, now + ttlMs);
|
|
28
|
+
return 1;
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
strings,
|
|
32
|
+
clientIndex,
|
|
33
|
+
eval: evalFn,
|
|
34
|
+
get: vitest_1.vi.fn(async (key) => { var _a; return (_a = strings.get(key)) !== null && _a !== void 0 ? _a : null; }),
|
|
35
|
+
set: vitest_1.vi.fn(async (key, value) => {
|
|
36
|
+
strings.set(key, value);
|
|
37
|
+
return 'OK';
|
|
38
|
+
}),
|
|
39
|
+
getDel: vitest_1.vi.fn(async (key) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const value = (_a = strings.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
42
|
+
strings.delete(key);
|
|
43
|
+
return value;
|
|
44
|
+
}),
|
|
45
|
+
del: vitest_1.vi.fn(async (key) => {
|
|
46
|
+
strings.delete(key);
|
|
47
|
+
return 1;
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
(0, vitest_1.describe)('RedisOAuthBrokerStore.registerClient', () => {
|
|
52
|
+
(0, vitest_1.it)('registers until maxClients then returns undefined', async () => {
|
|
53
|
+
const fake = createFakeRedis();
|
|
54
|
+
const store = new redis_oauth_broker_store_js_1.RedisOAuthBrokerStore(async () => fake, {
|
|
55
|
+
maxClients: 1,
|
|
56
|
+
clientTtlMs: 60000,
|
|
57
|
+
});
|
|
58
|
+
const first = await store.registerClient(['http://127.0.0.1:8787/cb']);
|
|
59
|
+
(0, vitest_1.expect)(first).toBeDefined();
|
|
60
|
+
(0, vitest_1.expect)(fake.clientIndex.size).toBe(1);
|
|
61
|
+
(0, vitest_1.expect)(fake.strings.size).toBe(1);
|
|
62
|
+
const second = await store.registerClient(['http://127.0.0.1:8787/cb2']);
|
|
63
|
+
(0, vitest_1.expect)(second).toBeUndefined();
|
|
64
|
+
(0, vitest_1.expect)(fake.clientIndex.size).toBe(1);
|
|
65
|
+
});
|
|
66
|
+
(0, vitest_1.it)('prunes expired index members before enforcing capacity', async () => {
|
|
67
|
+
const fake = createFakeRedis();
|
|
68
|
+
const past = Date.now() - 10000;
|
|
69
|
+
fake.clientIndex.set('expired-client', past);
|
|
70
|
+
const store = new redis_oauth_broker_store_js_1.RedisOAuthBrokerStore(async () => fake, {
|
|
71
|
+
maxClients: 1,
|
|
72
|
+
clientTtlMs: 60000,
|
|
73
|
+
});
|
|
74
|
+
const registered = await store.registerClient(['http://127.0.0.1:8787/cb']);
|
|
75
|
+
(0, vitest_1.expect)(registered).toBeDefined();
|
|
76
|
+
(0, vitest_1.expect)(fake.clientIndex.has('expired-client')).toBe(false);
|
|
77
|
+
(0, vitest_1.expect)(fake.clientIndex.size).toBe(1);
|
|
78
|
+
(0, vitest_1.expect)([...fake.strings.keys()][0]).toBe(`${redis_oauth_broker_store_js_1.OAUTH_REDIS_KEY_PREFIX}client:${registered.clientId}`);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis-backed PreviewStore with Lua CAS (ADR-0016).
|
|
3
|
+
*
|
|
4
|
+
* Key prefix: `lightdash-tools:mcp:preview:`.
|
|
5
|
+
* Redis key TTL = logical expiresAt + grace so assertOwnedEntry can still
|
|
6
|
+
* distinguish PREVIEW_EXPIRED from PREVIEW_REQUIRED after logical expiry.
|
|
7
|
+
*/
|
|
8
|
+
import type { PreviewLedgerEntry, PreviewStatus, PreviewStore } from '../policy/preview-ledger.js';
|
|
9
|
+
import type { RedisClientType } from 'redis';
|
|
10
|
+
export declare const PREVIEW_REDIS_KEY_PREFIX = "lightdash-tools:mcp:preview:";
|
|
11
|
+
/** Keep expired entries briefly so the ledger can return PREVIEW_EXPIRED. */
|
|
12
|
+
export declare const PREVIEW_REDIS_EXPIRY_GRACE_MS: number;
|
|
13
|
+
/** Redis PX from logical expiresAt, including post-expiry grace. Exported for tests. */
|
|
14
|
+
export declare function redisTtlMsFromEntry(entry: PreviewLedgerEntry, now?: number, graceMs?: number): number;
|
|
15
|
+
export declare class RedisPreviewStore implements PreviewStore {
|
|
16
|
+
private readonly getClient;
|
|
17
|
+
constructor(getClient: () => Promise<RedisClientType>);
|
|
18
|
+
get(previewId: string): Promise<PreviewLedgerEntry | undefined>;
|
|
19
|
+
put(entry: PreviewLedgerEntry): Promise<void>;
|
|
20
|
+
compareAndSwap(previewId: string, expectedStatus: PreviewStatus, next: PreviewLedgerEntry): Promise<boolean>;
|
|
21
|
+
compareAndDelete(previewId: string, expectedStatus: PreviewStatus): Promise<boolean>;
|
|
22
|
+
delete(previewId: string): Promise<void>;
|
|
23
|
+
}
|