@lightdash-tools/mcp 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -237
- package/dist/audit/server-persona.d.ts +10 -0
- package/dist/audit/server-persona.js +19 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +6 -7
- package/dist/auth/oauth-broker/pending-store.js +3 -4
- package/dist/auth/oauth-broker/pending-store.test.d.ts +2 -3
- package/dist/auth/oauth-broker/pending-store.test.js +2 -39
- package/dist/auth/oauth-broker/routes.d.ts +1 -1
- package/dist/auth/oauth-broker/routes.js +3 -3
- package/dist/auth/oauth-broker/routes.test.js +1 -1
- package/dist/auth/request-state-key.d.ts +19 -0
- package/dist/auth/request-state-key.js +49 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +0 -2
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +0 -19
- package/dist/auth/resource-server/www-authenticate.test.js +0 -2
- package/dist/bin.js +9 -2
- package/dist/config/env.d.ts +5 -15
- package/dist/config/env.js +6 -16
- package/dist/config/load-mcp-config.d.ts +0 -4
- package/dist/config/load-mcp-config.js +8 -9
- package/dist/config/normalize-url.test.js +14 -11
- package/dist/config/runtime.d.ts +3 -3
- package/dist/config/runtime.js +19 -23
- package/dist/config/runtime.test.js +23 -9
- package/dist/config/test-mcp-http-config.js +1 -1
- package/dist/destructive/content-promote.js +7 -1
- package/dist/destructive/promote-contract.test.js +106 -47
- package/dist/destructive/register-destructive-tool.js +6 -24
- package/dist/destructive/request-state.d.ts +2 -6
- package/dist/destructive/request-state.js +3 -38
- package/dist/destructive/types.d.ts +2 -1
- package/dist/governance/available-projects.d.ts +37 -0
- package/dist/governance/available-projects.js +132 -0
- package/dist/governance/available-projects.test.d.ts +4 -0
- package/dist/governance/available-projects.test.js +107 -0
- package/dist/governance/client-capabilities-cache.d.ts +44 -0
- package/dist/governance/client-capabilities-cache.js +142 -0
- package/dist/governance/client-capabilities-cache.test.js +148 -0
- package/dist/governance/mcp-client-session.d.ts +3 -2
- package/dist/governance/mcp-client-session.js +3 -2
- package/dist/governance/project-scope.d.ts +8 -22
- package/dist/governance/project-scope.js +36 -44
- package/dist/governance/project-scope.test.d.ts +1 -1
- package/dist/governance/project-scope.test.js +21 -44
- package/dist/governance/promote-allowlist.d.ts +18 -0
- package/dist/governance/promote-allowlist.js +66 -0
- package/dist/governance/promote-allowlist.test.d.ts +4 -0
- package/dist/governance/promote-allowlist.test.js +87 -0
- package/dist/http.integration.test.js +117 -262
- package/dist/http.test.js +0 -12
- package/dist/index.integration.test.js +0 -4
- package/dist/index.js +3 -1
- package/dist/personas/ai-agent-ops/v1/index.d.ts +8 -0
- package/dist/personas/ai-agent-ops/v1/index.js +41 -0
- package/dist/personas/ai-agent-ops/v1/prompts.d.ts +5 -0
- package/dist/personas/ai-agent-ops/v1/prompts.js +141 -0
- package/dist/personas/ai-agent-ops/v1/prompts.test.d.ts +4 -0
- package/dist/personas/ai-agent-ops/v1/prompts.test.js +26 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks.js +41 -0
- package/dist/personas/content-developer/v1/index.d.ts +1 -1
- package/dist/personas/content-developer/v1/index.js +1 -0
- package/dist/personas/content-developer/v1/prompts.d.ts +3 -0
- package/dist/personas/content-developer/v1/prompts.js +80 -61
- package/dist/personas/content-developer/v1/prompts.test.js +159 -3
- package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
- package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +13 -6
- package/dist/personas/content-developer/v1/resources/playbooks/core.md +91 -49
- package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +82 -34
- package/dist/personas/content-developer/v1/resources/playbooks/index.md +9 -7
- package/dist/personas/content-developer/v1/resources/playbooks.d.ts +1 -1
- package/dist/personas/content-developer/v1/resources/playbooks.js +29 -10
- package/dist/personas/content-governance/v1/resources/playbooks/core.md +1 -1
- package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +1 -1
- package/dist/personas/content-reader/v1/index.d.ts +1 -1
- package/dist/personas/content-reader/v1/index.js +1 -0
- package/dist/personas/content-reader/v1/prompts.js +64 -30
- package/dist/personas/content-reader/v1/resources/playbooks/compare.md +24 -9
- package/dist/personas/content-reader/v1/resources/playbooks/core.md +56 -29
- package/dist/personas/content-reader/v1/resources/playbooks/discover.md +27 -5
- package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +38 -8
- package/dist/personas/content-reader/v1/resources/playbooks/index.md +8 -8
- package/dist/personas/content-reader/v1/resources/playbooks.js +2 -2
- package/dist/personas/index.d.ts +1 -0
- package/dist/personas/index.js +27 -22
- package/dist/personas/index.test.js +68 -53
- package/dist/personas/lib/playbook-resources.d.ts +4 -3
- package/dist/personas/lib/playbook-resources.js +14 -10
- package/dist/personas/organization-audit/v1/prompts.js +68 -36
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +12 -4
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +13 -3
- package/dist/personas/organization-audit/v1/resources/playbooks/core.md +49 -16
- package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +8 -3
- package/dist/personas/organization-audit/v1/resources/playbooks/index.md +8 -8
- package/dist/personas/organization-audit/v1/resources/playbooks.js +1 -1
- package/dist/personas/persona.parity.test.js +14 -10
- package/dist/personas/semantic-layer/v1/prompts.js +50 -39
- package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +36 -31
- package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +53 -21
- package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +42 -39
- package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +6 -6
- package/dist/personas/semantic-layer/v1/resources/playbooks.js +2 -2
- package/dist/personas/types.d.ts +1 -1
- package/dist/policy/content-developer.d.ts +3 -3
- package/dist/policy/content-developer.js +3 -3
- package/dist/policy/content-developer.test.js +10 -4
- package/dist/policy/content-reader.d.ts +5 -1
- package/dist/policy/content-reader.js +18 -3
- package/dist/policy/content-reader.test.js +2 -1
- package/dist/policy/preview-ledger-fault.test.js +101 -426
- package/dist/policy/preview-ledger.d.ts +38 -74
- package/dist/policy/preview-ledger.js +108 -186
- package/dist/policy/preview-ledger.test.js +237 -111
- package/dist/policy/result-limits.d.ts +6 -1
- package/dist/policy/result-limits.js +28 -29
- package/dist/policy/result-limits.test.js +10 -1
- package/dist/server/capabilities.js +2 -0
- package/dist/server/capabilities.test.js +2 -0
- package/dist/server/server.js +12 -8
- package/dist/server/upstream-errors.d.ts +17 -0
- package/dist/server/upstream-errors.js +60 -0
- package/dist/server/upstream-errors.test.js +50 -0
- package/dist/stdio.process.test.js +4 -2
- package/dist/tools/ai-agents/agents.d.ts +7 -0
- package/dist/tools/ai-agents/agents.js +32 -0
- package/dist/tools/ai-agents/agents.test.js +176 -0
- package/dist/tools/ai-agents/discovery.d.ts +9 -0
- package/dist/tools/ai-agents/discovery.js +73 -0
- package/dist/tools/ai-agents/evaluations.d.ts +14 -0
- package/dist/tools/ai-agents/evaluations.js +177 -0
- package/dist/tools/ai-agents/helpers.d.ts +64 -0
- package/dist/tools/ai-agents/helpers.js +323 -0
- package/dist/tools/ai-agents/threads.d.ts +7 -0
- package/dist/tools/ai-agents/threads.js +40 -0
- package/dist/tools/organization/inventory.js +2 -1
- package/dist/tools/project/content.js +5 -1
- package/dist/tools/project/developer-content-preview.d.ts +2 -1
- package/dist/tools/project/developer-content-preview.js +40 -35
- package/dist/tools/project/developer-content-shared.d.ts +8 -2
- package/dist/tools/project/developer-content-shared.js +7 -3
- package/dist/tools/project/developer-content.d.ts +7 -8
- package/dist/tools/project/developer-content.js +72 -67
- package/dist/tools/project/developer-get-chart-as-code.d.ts +9 -0
- package/dist/tools/project/developer-get-chart-as-code.js +39 -0
- package/dist/tools/project/developer-get-chart-as-code.test.d.ts +4 -0
- package/dist/tools/project/developer-get-chart-as-code.test.js +70 -0
- package/dist/tools/project/developer-helpers.d.ts +1 -1
- package/dist/tools/project/developer-helpers.js +1 -1
- package/dist/tools/project/get-dashboard-promote-diff.js +12 -2
- package/dist/tools/project/invariants.test.js +5 -3
- package/dist/tools/project/projects.js +6 -4
- package/dist/tools/project/projects.test.js +44 -5
- package/dist/tools/project/reader-export-chart-image.d.ts +6 -0
- package/dist/tools/project/reader-export-chart-image.js +78 -0
- package/dist/tools/project/reader-export-chart-image.test.d.ts +4 -0
- package/dist/tools/project/reader-export-chart-image.test.js +149 -0
- package/dist/tools/query/bounded-saved-query.js +1 -1
- package/dist/tools/query/lifecycle.d.ts +1 -1
- package/dist/tools/query/lifecycle.js +17 -25
- package/dist/tools/query/query-ledger.d.ts +15 -8
- package/dist/tools/query/query-ledger.js +21 -15
- package/dist/tools/query/query-ledger.test.js +13 -11
- package/dist/tools/query/reader-tool-helpers.js +4 -6
- package/dist/tools/query/reader-tool-helpers.test.js +8 -4
- package/dist/tools/registry.d.ts +63 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/shared.d.ts +27 -8
- package/dist/tools/shared.js +61 -28
- package/dist/tools/shared.test.js +100 -4
- package/dist/transports/streamable-http.js +48 -206
- package/dist/transports/streamable-http.test.js +10 -3
- package/package.json +5 -6
- package/dist/destructive/confirmation-claim.d.ts +0 -21
- package/dist/destructive/confirmation-claim.js +0 -87
- package/dist/destructive/confirmation-claim.test.js +0 -50
- package/dist/store/config.d.ts +0 -11
- package/dist/store/config.js +0 -50
- package/dist/store/config.test.js +0 -56
- package/dist/store/create-oauth-broker-store.d.ts +0 -6
- package/dist/store/create-oauth-broker-store.js +0 -16
- package/dist/store/create-preview-store.d.ts +0 -10
- package/dist/store/create-preview-store.js +0 -30
- package/dist/store/create-session-store.d.ts +0 -19
- package/dist/store/create-session-store.js +0 -24
- package/dist/store/in-memory-preview-store.d.ts +0 -17
- package/dist/store/in-memory-preview-store.js +0 -72
- package/dist/store/redis-client.d.ts +0 -11
- package/dist/store/redis-client.js +0 -48
- package/dist/store/redis-oauth-broker-store.d.ts +0 -42
- package/dist/store/redis-oauth-broker-store.js +0 -167
- package/dist/store/redis-oauth-broker-store.test.js +0 -80
- package/dist/store/redis-preview-store.d.ts +0 -23
- package/dist/store/redis-preview-store.js +0 -94
- package/dist/store/redis-preview-store.test.d.ts +0 -1
- package/dist/store/redis-preview-store.test.js +0 -39
- package/dist/store/redis-session-index.d.ts +0 -33
- package/dist/store/redis-session-index.js +0 -49
- package/dist/store/types.d.ts +0 -13
- package/dist/store/types.js +0 -8
- package/dist/transports/http-request-utils.d.ts +0 -2
- package/dist/transports/http-request-utils.js +0 -13
- package/dist/transports/session-store.d.ts +0 -72
- package/dist/transports/session-store.js +0 -143
- package/dist/transports/session-store.test.d.ts +0 -1
- package/dist/transports/session-store.test.js +0 -111
- /package/dist/{destructive/confirmation-claim.test.d.ts → governance/client-capabilities-cache.test.d.ts} +0 -0
- /package/dist/{store/config.test.d.ts → server/upstream-errors.test.d.ts} +0 -0
- /package/dist/{store/redis-oauth-broker-store.test.d.ts → tools/ai-agents/agents.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,171 +1,55 @@
|
|
|
1
1
|
# [@lightdash-tools/mcp](https://www.npmjs.com/package/@lightdash-tools/mcp) <!-- markdown-link-check-disable-line -->
|
|
2
2
|
|
|
3
|
-
MCP server for Lightdash with **persona-scoped** surfaces:
|
|
3
|
+
MCP server for Lightdash with **persona-scoped** surfaces. One package, six personas: explore/compile, org audit, saved-content reads, chart/dashboard authoring, soft-delete governance, and AI-agent ops. Uses [`@lightdash-tools/client`](https://www.npmjs.com/package/@lightdash-tools/client) for API access. <!-- markdown-link-check-disable-line -->
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Developing this package? See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Choose a persona
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
| Persona | Use when | HTTP path | Stdio | Catalog |
|
|
10
|
+
| :------------------- | :--------------------------------------- | :--------------------------- | :------------------- | :--------------------------------------------------------------- |
|
|
11
|
+
| `semantic-layer` | Explore metrics, compile queries | `/semantic-layer/v1/mcp` | **default** | — |
|
|
12
|
+
| `organization-audit` | Read-only org governance | `/organization-audit/v1/mcp` | `organization-audit` | [inventory](../../docs/organization-audit-endpoint-inventory.md) |
|
|
13
|
+
| `content-reader` | Discover and run saved content | `/content-reader/v1/mcp` | `content-reader` | [inventory](../../docs/content-reader-endpoint-inventory.md) |
|
|
14
|
+
| `content-developer` | Author charts/dashboards (preview gate) | `/content-developer/v1/mcp` | `content-developer` | [inventory](../../docs/content-developer-endpoint-inventory.md) |
|
|
15
|
+
| `content-governance` | Soft-delete / promote (form elicitation) | `/content-governance/v1/mcp` | `content-governance` | [inventory](../../docs/content-governance-endpoint-inventory.md) |
|
|
16
|
+
| `ai-agent-ops` | Thin AI-agent APIs + product eval runs | `/ai-agent-ops/v1/mcp` | `ai-agent-ops` | [inventory](../../docs/ai-agent-ops-endpoint-inventory.md) |
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
| :------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------ |
|
|
13
|
-
| Shared tools / registry | `src/tools/` (`registry.ts`, domain modules) |
|
|
14
|
-
| Persona (tools allowlist, prompts, playbook, HTTP path) | `src/personas/<id>/` |
|
|
15
|
-
| Destructive confirmation (form elicitation / MRTR) | `src/destructive/` |
|
|
16
|
-
| HTTP transport / sessions | `src/transports/` |
|
|
17
|
-
| HTTP auth | `src/auth/` |
|
|
18
|
-
| Runtime client + guardrail env | `src/config/runtime.ts` |
|
|
19
|
-
| HTTP env / loader | `src/config/env.ts`, `src/config/load-mcp-config.ts` |
|
|
20
|
-
| Ephemeral store (memory/redis) | `src/store/` ([ADR-0016](../../docs/adr/0016-mcp-pluggable-ephemeral-store-for-http-preview-sessions-and-oauth.md)) |
|
|
21
|
-
| Audit logging helpers | `src/audit/` |
|
|
22
|
-
| Entrypoints | `src/bin.ts`, `src/index.ts` (stdio), `src/http.ts` |
|
|
18
|
+
Tool names are prefixed with `lightdash_`. MCP display names are shortened where needed for client length limits (e.g. `lightdash-mcp-content`).
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Replaces `@lightdash-tools/semantic-layer-mcp`
|
|
27
|
-
|
|
28
|
-
That package was removed (ADR-0006). Migrate as follows:
|
|
29
|
-
|
|
30
|
-
| Removed | Use instead |
|
|
31
|
-
| ------------------------------------- | ------------------------ |
|
|
32
|
-
| `@lightdash-tools/semantic-layer-mcp` | `@lightdash-tools/mcp` |
|
|
33
|
-
| Binary `lightdash-semantic-layer-mcp` | `lightdash-mcp` |
|
|
34
|
-
| HTTP `/mcp` (old) | `/semantic-layer/v1/mcp` |
|
|
35
|
-
| Unprefixed tool names | `lightdash_*` |
|
|
36
|
-
|
|
37
|
-
## Installation
|
|
38
|
-
|
|
39
|
-
You can run the MCP server using `npx`:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npx @lightdash-tools/mcp
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Or install it globally:
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npm install -g @lightdash-tools/mcp
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Transports
|
|
52
|
-
|
|
53
|
-
- **Stdio** — for local use (e.g. Claude Desktop, IDE). One process per client.
|
|
54
|
-
- **Streamable HTTP** — for remote use. Session-based; supports optional endpoint auth.
|
|
55
|
-
|
|
56
|
-
### SDK / protocol compatibility
|
|
57
|
-
|
|
58
|
-
- Uses MCP TypeScript SDK v2 (`@modelcontextprotocol/server`, `@modelcontextprotocol/node`).
|
|
59
|
-
- Speaks the established 2025-era protocol by default (not `2026-07-28` unless a future flag).
|
|
60
|
-
- Hosted OAuth client setup: [docs/cursor-lightdash-oauth-mcp.md](../../docs/cursor-lightdash-oauth-mcp.md). Protocol/auth details: [docs/mcp-oauth-http.md](../../docs/mcp-oauth-http.md).
|
|
61
|
-
|
|
62
|
-
### Hosted OAuth (primary HTTP)
|
|
63
|
-
|
|
64
|
-
Auth is **inferred** from credentials ([ADR-0007](../../docs/adr/0007-mcp-http-transport-auth-modes-sdk-v2.md)). The MCP host holds the Lightdash OAuth app client id/secret and brokers login; Claude Code / Cursor use URL-only config. Protocol reference: [MCP Authorization 2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization).
|
|
65
|
-
|
|
66
|
-
| What works | Gap |
|
|
67
|
-
| :-------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
68
|
-
| Server-held confidential client + `{PUBLIC_URL}/oauth/callback` | Full RFC 8707 audience binding on opaque Lightdash tokens |
|
|
69
|
-
| PRM + broker AS metadata; per-user Bearer to Lightdash | MCP-local scope enforcement for opaque tokens |
|
|
70
|
-
| Session binding to `userUuid` / `organizationUuid` | Multi-instance scale: default in-memory needs sticky routing; opt into Redis via `LIGHTDASH_TOOLS_MCP_STORE=redis` ([ADR-0016](../../docs/adr/0016-mcp-pluggable-ephemeral-store-for-http-preview-sessions-and-oauth.md)) |
|
|
71
|
-
|
|
72
|
-
Authorization: Lightdash RBAC + persona tool surface ([ADR-0006](../../docs/adr/0006-mcp-personas-shared-registry-fixed-paths.md)) + optional `X-Lightdash-Project` pin. See [mcp-oauth-http.md](../../docs/mcp-oauth-http.md).
|
|
73
|
-
|
|
74
|
-
## Environment variables
|
|
75
|
-
|
|
76
|
-
Preferred names use the `LIGHTDASH_TOOLS_*` prefixes (see [ADR-0009](../../docs/adr/0009-cross-cutting-conventions.md)). Prefer env vars from the parent process. Avoid plaintext `.env` when AI agents have file access. If using `.env`, use [dotenvx](https://dotenvx.com/). See [docs/secrets-and-credentials.md](../../docs/secrets-and-credentials.md).
|
|
77
|
-
|
|
78
|
-
### Stdio (secondary)
|
|
79
|
-
|
|
80
|
-
| Required | Optional |
|
|
81
|
-
| :----------------------------------- | :-------------------------- |
|
|
82
|
-
| `LIGHTDASH_URL`, `LIGHTDASH_API_KEY` | `LIGHTDASH_TOOLS_AUDIT_LOG` |
|
|
83
|
-
|
|
84
|
-
Do **not** set OAuth client secrets for stdio. MCP does not use CLI `SAFETY_MODE` / `ALLOWED_PROJECTS` / `DRY_RUN`.
|
|
85
|
-
|
|
86
|
-
### HTTP OAuth (primary)
|
|
87
|
-
|
|
88
|
-
| Required | Common optional |
|
|
89
|
-
| :-------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------- |
|
|
90
|
-
| `LIGHTDASH_URL`, `LIGHTDASH_TOOLS_MCP_PUBLIC_URL`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_ID`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET` | port, `ALLOWED_ORIGINS`, audit log, token cache TTL |
|
|
91
|
-
|
|
92
|
-
Register Lightdash redirect URI: `{PUBLIC_URL}/oauth/callback`. Clients: URL only to `/semantic-layer/v1/mcp`, `/organization-audit/v1/mcp`, `/content-reader/v1/mcp`, `/content-developer/v1/mcp`, or `/content-governance/v1/mcp`.
|
|
93
|
-
|
|
94
|
-
### Content-governance (destructive soft-delete)
|
|
95
|
-
|
|
96
|
-
| Required (non-test) | Notes |
|
|
97
|
-
| :-------------------------------------- | :------------------------------------------------------------------------------------------ |
|
|
98
|
-
| `LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY` | ≥32-byte secret for HMAC-signed opaque `requestState` (not encrypted; fail closed if unset) |
|
|
99
|
-
| Client form elicitation | Missing capability → `ELICITATION_REQUIRED`; no DELETE / promote |
|
|
100
|
-
|
|
101
|
-
### HTTP shared-key / local (secondary)
|
|
102
|
-
|
|
103
|
-
| Mode | Env |
|
|
104
|
-
| :--------- | :----------------------------------------------------- |
|
|
105
|
-
| Shared-key | `LIGHTDASH_API_KEY` + `LIGHTDASH_TOOLS_MCP_SHARED_KEY` |
|
|
106
|
-
| Local none | `NODE_ENV=development` (not `production`) |
|
|
107
|
-
|
|
108
|
-
Obsolete `LIGHTDASH_TOOLS_MCP_AUTH_MODE`, `EXPERIMENTAL_*`, `DANGEROUSLY_*`, and `INSECURE_DEV` vars are **rejected**. Endpoint path is persona-owned (`LIGHTDASH_TOOLS_MCP_PATH` rejected).
|
|
109
|
-
|
|
110
|
-
### Ephemeral store (HTTP sessions / preview / OAuth)
|
|
111
|
-
|
|
112
|
-
Start with **memory** (default). Add **Redis** when scaling beyond a single HTTP instance ([ADR-0016](../../docs/adr/0016-mcp-pluggable-ephemeral-store-for-http-preview-sessions-and-oauth.md)).
|
|
113
|
-
|
|
114
|
-
| Env | Default | Notes |
|
|
115
|
-
| :------------------------------ | :------- | :---------------------------------------- |
|
|
116
|
-
| `LIGHTDASH_TOOLS_MCP_STORE` | `memory` | `memory` \| `redis` |
|
|
117
|
-
| `LIGHTDASH_TOOLS_MCP_REDIS_URL` | — | Required when `STORE=redis` (fail closed) |
|
|
118
|
-
|
|
119
|
-
What Redis shares vs what stays local:
|
|
120
|
-
|
|
121
|
-
| Concern | memory | redis |
|
|
122
|
-
| :---------------------------------- | :------------ | :-------------------------------------------------------------------------------------------------- |
|
|
123
|
-
| Content-developer preview ledger | process-local | shared |
|
|
124
|
-
| OAuth pending / codes / DCR clients | process-local | shared (full multi-instance OAuth) |
|
|
125
|
-
| Streamable HTTP session transports | process-local | process-local + Redis session _index_; sticky or single instance still required for live transports |
|
|
126
|
-
|
|
127
|
-
Stdio and tests use memory. Production may use memory on a single instance (HTTP logs a multi-instance/restart warning).
|
|
128
|
-
|
|
129
|
-
See also: [mcp-oauth-http.md](../../docs/mcp-oauth-http.md), [cursor-lightdash-oauth-mcp.md](../../docs/cursor-lightdash-oauth-mcp.md), [cloud-run-mcp-oauth.md](../../docs/cloud-run-mcp-oauth.md), [threat model](../../docs/security/mcp-oauth-threat-model.md).
|
|
130
|
-
|
|
131
|
-
## Running
|
|
20
|
+
## Quick start
|
|
132
21
|
|
|
133
22
|
### Stdio (local)
|
|
134
23
|
|
|
135
|
-
For use with Claude Desktop or IDEs, use `npx`:
|
|
136
|
-
|
|
137
24
|
```bash
|
|
138
|
-
npx @lightdash-tools/mcp
|
|
139
|
-
#
|
|
140
|
-
npx @lightdash-tools/mcp semantic-layer
|
|
141
|
-
npx @lightdash-tools/mcp organization-audit
|
|
142
|
-
npx @lightdash-tools/mcp content-reader
|
|
143
|
-
npx @lightdash-tools/mcp content-developer
|
|
144
|
-
npx @lightdash-tools/mcp content-governance
|
|
25
|
+
npx @lightdash-tools/mcp # semantic-layer (default)
|
|
26
|
+
npx @lightdash-tools/mcp content-reader # other personas by name
|
|
145
27
|
```
|
|
146
28
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
lightdash
|
|
29
|
+
Required env: `LIGHTDASH_URL`, `LIGHTDASH_API_KEY`. Logs go to **stderr**; stdout is JSON-RPC only ([stdio transport](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/stdio)).
|
|
30
|
+
|
|
31
|
+
Example Cursor / Claude Desktop config:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"lightdash": {
|
|
37
|
+
"command": "npx",
|
|
38
|
+
"args": ["@lightdash-tools/mcp", "content-reader"],
|
|
39
|
+
"env": {
|
|
40
|
+
"LIGHTDASH_URL": "https://app.lightdash.cloud",
|
|
41
|
+
"LIGHTDASH_API_KEY": "your_pat"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
155
46
|
```
|
|
156
47
|
|
|
157
|
-
|
|
48
|
+
Or install globally: `npm install -g @lightdash-tools/mcp`, then `lightdash-mcp [persona]`.
|
|
158
49
|
|
|
159
50
|
### Streamable HTTP (remote)
|
|
160
51
|
|
|
161
52
|
```bash
|
|
162
|
-
# Backward-compatible
|
|
163
|
-
npx @lightdash-tools/mcp --http
|
|
164
|
-
|
|
165
|
-
# Explicit subcommand
|
|
166
|
-
npx @lightdash-tools/mcp serve-http
|
|
167
|
-
|
|
168
|
-
# Hosted OAuth (server-held Lightdash confidential client)
|
|
169
53
|
export LIGHTDASH_URL="https://app.lightdash.cloud"
|
|
170
54
|
export LIGHTDASH_TOOLS_MCP_PUBLIC_URL="https://lightdash-mcp.example.com"
|
|
171
55
|
export LIGHTDASH_TOOLS_OAUTH_CLIENT_ID="..."
|
|
@@ -173,135 +57,122 @@ export LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET="..."
|
|
|
173
57
|
npx @lightdash-tools/mcp serve-http
|
|
174
58
|
```
|
|
175
59
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
- `POST/GET/DELETE /semantic-layer/v1/mcp`
|
|
179
|
-
- `POST/GET/DELETE /organization-audit/v1/mcp`
|
|
180
|
-
- `POST/GET/DELETE /content-reader/v1/mcp`
|
|
181
|
-
- `POST/GET/DELETE /content-developer/v1/mcp`
|
|
182
|
-
- `POST/GET/DELETE /content-governance/v1/mcp`
|
|
183
|
-
|
|
184
|
-
Register `{PUBLIC_URL}/oauth/callback` in Lightdash. See [mcp-oauth-http.md](../../docs/mcp-oauth-http.md).
|
|
185
|
-
|
|
186
|
-
**Local Compose (dev):**
|
|
60
|
+
Persona MCP endpoints accept **POST** only ([Streamable HTTP 2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http); no protocol sessions). Default listen port: `3100` (`LIGHTDASH_TOOLS_MCP_HTTP_PORT`).
|
|
187
61
|
|
|
188
|
-
-
|
|
189
|
-
-
|
|
62
|
+
- Hosted OAuth (Cursor URL-only): [docs/cursor-lightdash-oauth-mcp.md](../../docs/cursor-lightdash-oauth-mcp.md)
|
|
63
|
+
- Operator guide: [docs/mcp-oauth-http.md](../../docs/mcp-oauth-http.md)
|
|
190
64
|
|
|
191
|
-
|
|
65
|
+
Local Compose smoke: `docker compose -f docker-compose.dev.yml --profile semantic-layer up --build` → `http://localhost:8080/semantic-layer/v1/mcp`.
|
|
192
66
|
|
|
193
|
-
|
|
67
|
+
## Configuration
|
|
194
68
|
|
|
195
|
-
|
|
69
|
+
Prefer `LIGHTDASH_TOOLS_*` env from the parent process. Avoid plaintext `.env` when agents can read files; if needed, use [dotenvx](https://dotenvx.com/). See [docs/secrets-and-credentials.md](../../docs/secrets-and-credentials.md).
|
|
196
70
|
|
|
197
|
-
|
|
198
|
-
- **Explores**: `list_explores`, `get_explore`, `list_dimensions`, `get_field_lineage`
|
|
199
|
-
- **Metrics**: `list_metrics`, `get_metric`
|
|
200
|
-
- **Query**: `compile_query` (empty SELECT → `isError`; no run-query)
|
|
71
|
+
### Stdio
|
|
201
72
|
|
|
202
|
-
|
|
73
|
+
| Required | Optional |
|
|
74
|
+
| :----------------------------------- | :-------------------------------------------------------------------------------------------- |
|
|
75
|
+
| `LIGHTDASH_URL`, `LIGHTDASH_API_KEY` | `LIGHTDASH_TOOLS_AUDIT_LOG` (file; else stderr JSON), `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS` |
|
|
203
76
|
|
|
204
|
-
|
|
77
|
+
Do **not** set OAuth client secrets for stdio. MCP ignores CLI `SAFETY_MODE` / `DRY_RUN`.
|
|
205
78
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
- **Inventory**: `get_org_profile`, `list_org_members`, `get_org_member`, `list_org_groups`, `list_org_projects`
|
|
209
|
-
- **Access**: `list_org_role_assignments`, `list_custom_roles`, `get_custom_role`, `list_project_roles`, `list_project_direct_access`, `list_space_access`, `resolve_effective_access`
|
|
210
|
-
- **Content / health**: `list_content`, `get_dashboard_meta`, `list_validation_results`, `get_project_user_activity`
|
|
211
|
-
- **Delivery**: `list_project_schedulers`, `get_scheduler`
|
|
212
|
-
|
|
213
|
-
Prompts and playbook: `lightdash://playbooks/organization-audit` (host orchestrates multi-step audits via primitives). No mutation, warehouse queries, or user-activity CSV download.
|
|
214
|
-
|
|
215
|
-
### `content-reader` persona
|
|
79
|
+
### HTTP OAuth (primary)
|
|
216
80
|
|
|
217
|
-
|
|
81
|
+
| Required | Common optional |
|
|
82
|
+
| :-------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------- |
|
|
83
|
+
| `LIGHTDASH_URL`, `LIGHTDASH_TOOLS_MCP_PUBLIC_URL`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_ID`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET` | port, `ALLOWED_ORIGINS`, `ALLOWED_PROJECT_UUIDS`, token cache TTL |
|
|
218
84
|
|
|
219
|
-
|
|
220
|
-
- **Metadata**: `get_dashboard`, `get_chart`, `list_project_parameters`, `get_project_parameters`, `explain_content`
|
|
221
|
-
- **Execution**: `run_chart`, `run_dashboard_tile` (semantic saved content only; SQL charts disabled by default)
|
|
222
|
-
- **Lifecycle**: `get_query_result`, `cancel_query` (session-owned ledger)
|
|
85
|
+
On Cloud Run / hosted HTTP, leave `LIGHTDASH_TOOLS_AUDIT_LOG` unset — tool audits are stderr JSON (`channel: "audit"`) → Cloud Logging. See [cloud-run-mcp-oauth.md](../../docs/cloud-run-mcp-oauth.md).
|
|
223
86
|
|
|
224
|
-
|
|
87
|
+
Register Lightdash redirect URI: `{PUBLIC_URL}/oauth/callback`. Clients connect with URL only to a persona path above. Protocol: [MCP Authorization 2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization).
|
|
225
88
|
|
|
226
|
-
###
|
|
89
|
+
### Content-developer / content-governance signing
|
|
227
90
|
|
|
228
|
-
|
|
91
|
+
| Required (non-test) | Notes |
|
|
92
|
+
| :-------------------------------------- | :---------------------------------------------------------------------------------------------- |
|
|
93
|
+
| `LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY` | ≥32-byte secret for HMAC `previewToken` / `requestState` (fail closed if unset; not encryption) |
|
|
229
94
|
|
|
230
|
-
-
|
|
231
|
-
- **Preview / confirm / validate / diff**: `preview_chart_changes`, `preview_dashboard_changes`, `preview_content_move`, `confirm_preview`, `validate_chart`, `validate_dashboard`, `compare_chart_versions`, `compare_dashboard_versions`
|
|
232
|
-
- **Charts (as-code)**: `create_chart`, `update_chart`, `duplicate_chart`
|
|
233
|
-
- **Dashboards (REST)**: `create_dashboard`, `update_dashboard`, `duplicate_dashboard`
|
|
234
|
-
- **Layout**: `add_dashboard_tile`, `move_dashboard_tile`, `remove_dashboard_tile`, `resize_dashboard_tile`
|
|
235
|
-
- **Spaces**: `list_spaces`, `get_space`, `move_content` (no create/update space; use `preview_content_move` before apply)
|
|
95
|
+
Governance soft-delete needs client form elicitation; missing capability → `ELICITATION_REQUIRED`.
|
|
236
96
|
|
|
237
|
-
|
|
97
|
+
### HTTP shared-key / local (secondary)
|
|
238
98
|
|
|
239
|
-
|
|
99
|
+
| Mode | Env |
|
|
100
|
+
| :--------- | :----------------------------------------------------- |
|
|
101
|
+
| Shared-key | `LIGHTDASH_API_KEY` + `LIGHTDASH_TOOLS_MCP_SHARED_KEY` |
|
|
102
|
+
| Local none | `NODE_ENV=development` (not `production`) |
|
|
240
103
|
|
|
241
|
-
|
|
104
|
+
Obsolete vars (`AUTH_MODE`, `EXPERIMENTAL_*`, `DANGEROUSLY_*`, `INSECURE_DEV`, `MCP_STORE`, `MCP_REDIS_URL`, free-form `MCP_PATH`) are **rejected**. See [ADR-0019](../../docs/adr/0019-mcp-stateless-protocol-core-without-redis-ephemeral-store.md).
|
|
242
105
|
|
|
243
|
-
|
|
244
|
-
- **Promote**: `get_dashboard_promote_diff`, elicitation-gated `promote_dashboard` (upstream via Data Ops config)
|
|
245
|
-
- **Confirmation**: MCP form elicitation (`decision` + typed `confirmationText`) + HMAC-signed opaque `requestState` (do not put secrets in the token payload); fail closed without form capability
|
|
246
|
-
- **Not included**: bulk delete, space delete, permanent purge, chart/SQL promote, authoring, warehouse queries
|
|
106
|
+
## Personas at a glance
|
|
247
107
|
|
|
248
|
-
|
|
108
|
+
### `semantic-layer`
|
|
249
109
|
|
|
250
|
-
|
|
110
|
+
Projects, explores, metrics, and `compile_query` (no warehouse run). Playbook: `lightdash://playbooks/semantic-layer`.
|
|
251
111
|
|
|
252
|
-
|
|
112
|
+
### `organization-audit`
|
|
253
113
|
|
|
254
|
-
|
|
255
|
-
lightdash-mcp --help
|
|
256
|
-
```
|
|
114
|
+
Read-only inventory, access, content health, usage, and schedulers. No mutations or warehouse queries. Server name: `lightdash-mcp-org-audit`.
|
|
257
115
|
|
|
258
|
-
###
|
|
116
|
+
### `content-reader`
|
|
259
117
|
|
|
260
|
-
-
|
|
261
|
-
- `stdio` / `semantic-layer` / `organization-audit` / `content-reader` / `content-developer` / `content-governance` / `serve-http` — Explicit transport/persona subcommands.
|
|
118
|
+
Project-scoped discovery, metadata, bounded `run_chart` / `run_dashboard_tile`, and `export_chart_image` (PNG). SQL charts off by default. Project: `X-Lightdash-Project` or tool `projectUuid`. Server name: `lightdash-mcp-content`.
|
|
262
119
|
|
|
263
|
-
|
|
120
|
+
### `content-developer`
|
|
264
121
|
|
|
265
|
-
|
|
122
|
+
Author charts (as-code) and dashboards behind preview → `confirm_preview` → apply with HMAC `previewToken`. No warehouse execution or hard delete. Server name: `lightdash-mcp-cdev`.
|
|
266
123
|
|
|
267
|
-
|
|
268
|
-
| :----------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
269
|
-
| Which tools | Persona `toolIds` in code (including `content-governance` soft-delete) |
|
|
270
|
-
| Who | Auth mode + Lightdash API RBAC |
|
|
271
|
-
| Where (HTTP) | Optional `X-Lightdash-Project` pin; content-reader/content-developer also use `LIGHTDASH_TOOLS_PROJECT_UUID` |
|
|
272
|
-
| Hardening | Input validation + audit log + org-audit GET asserts + preview ledger + elicitation/`requestState` for soft-delete |
|
|
124
|
+
### `content-governance`
|
|
273
125
|
|
|
274
|
-
|
|
126
|
+
Soft-delete charts/dashboards and elicitation-gated dashboard promote. Permanent purge stays off MCP. Server name: `lightdash-mcp-gov`.
|
|
275
127
|
|
|
276
|
-
###
|
|
128
|
+
### `ai-agent-ops`
|
|
277
129
|
|
|
278
|
-
|
|
130
|
+
Thin AI-agent inventory, readiness, thread reads, and product evaluation suite/run APIs. No agent CRUD or thread generate on MCP. Server name: `lightdash-mcp-aops`. Loop engineering: [docs/ai-agent-ops-loop.md](../../docs/ai-agent-ops-loop.md).
|
|
279
131
|
|
|
280
|
-
|
|
132
|
+
## Safety
|
|
281
133
|
|
|
282
|
-
|
|
134
|
+
- **Off MCP:** irrecoverable admin deletes, permanent content purge, broad org mutations — use `@lightdash-tools/client` or the CLI ([ADR-0004](../../docs/adr/0004-agent-safe-exposure-mcp-cli-vs-client-only.md)).
|
|
135
|
+
- **Writes:** only on `content-developer` (preview gate). Soft-delete / promote: only on `content-governance` (form elicitation).
|
|
136
|
+
- **Redaction:** emails masked unless `includeEmail=true`; scheduler destinations redacted unless `revealDestinations=true`; warehouse/dbt connection secrets never on MCP ([ADR-0011](../../docs/adr/0011-mcp-tool-response-sensitivity-classes.md)).
|
|
137
|
+
- **Project scope:** optional HTTP pin `X-Lightdash-Project`, else tool `projectUuid`; optional ceiling `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS`.
|
|
283
138
|
|
|
284
|
-
|
|
139
|
+
Persona tool allowlists are the capability surface — not CLI safety-mode.
|
|
285
140
|
|
|
286
|
-
|
|
141
|
+
## Upstream API failures
|
|
287
142
|
|
|
288
|
-
|
|
143
|
+
When a tool handler throws (for example a Lightdash HTTP/API failure), MCP returns a **tool execution error** (`isError: true`) with structured `{ error: { code, message } }` — not a JSON-RPC protocol error — so clients/models can self-correct ([MCP tools error handling](https://modelcontextprotocol.io/specification/2025-11-25/server/tools#error-handling)).
|
|
289
144
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
145
|
+
| Code | Typical cause |
|
|
146
|
+
| :---------------------- | :--------------------------------------------- |
|
|
147
|
+
| `RATE_LIMITED` | HTTP 429 |
|
|
148
|
+
| `UPSTREAM_TRANSIENT` | Network errors, 408, 5xx |
|
|
149
|
+
| `UPSTREAM_NOT_FOUND` | HTTP 404 |
|
|
150
|
+
| `UPSTREAM_FORBIDDEN` | HTTP 403 |
|
|
151
|
+
| `UPSTREAM_UNSUPPORTED` | HTTP 501 |
|
|
152
|
+
| `UPSTREAM_VALIDATION` | HTTP 400 / 422 (including new required fields) |
|
|
153
|
+
| `UPSTREAM_CLIENT_ERROR` | Other 4xx |
|
|
154
|
+
| `UPSTREAM_CONTRACT` | Success HTTP but unexpected response shape |
|
|
155
|
+
| `IMAGE_TOO_LARGE` | Chart PNG over size limit |
|
|
156
|
+
| `UPSTREAM_UNKNOWN` | Non-API throws |
|
|
293
157
|
|
|
294
|
-
|
|
158
|
+
Intentional API upgrades still go through the pinned OpenAPI sync (`config/lightdash-openapi-ref.txt`). This layer only makes runtime drift fail safely and legibly.
|
|
295
159
|
|
|
296
|
-
|
|
160
|
+
## Migration from `@lightdash-tools/semantic-layer-mcp`
|
|
297
161
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
162
|
+
| Removed | Use instead |
|
|
163
|
+
| :------------------------------------ | :----------------------- |
|
|
164
|
+
| `@lightdash-tools/semantic-layer-mcp` | `@lightdash-tools/mcp` |
|
|
165
|
+
| Binary `lightdash-semantic-layer-mcp` | `lightdash-mcp` |
|
|
166
|
+
| HTTP `/mcp` (old) | `/semantic-layer/v1/mcp` |
|
|
167
|
+
| Unprefixed tool names | `lightdash_*` |
|
|
301
168
|
|
|
302
|
-
|
|
169
|
+
## Further reading
|
|
303
170
|
|
|
304
|
-
|
|
171
|
+
- Architecture / contributing — [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
172
|
+
- OAuth operator guide — [docs/mcp-oauth-http.md](../../docs/mcp-oauth-http.md)
|
|
173
|
+
- Cursor hosted OAuth — [docs/cursor-lightdash-oauth-mcp.md](../../docs/cursor-lightdash-oauth-mcp.md)
|
|
174
|
+
- Architecture decisions — [docs/adr/](../../docs/adr/)
|
|
175
|
+
- MCP transports — [2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports)
|
|
305
176
|
|
|
306
177
|
## License
|
|
307
178
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bind an MCP server instance to a persona id for audit attribution.
|
|
3
|
+
* Call once in registerCapabilities before registering tools; registerToolSafe
|
|
4
|
+
* reads it at wrap time. Tool behavior that needs personaId still uses
|
|
5
|
+
* registerToolsByIds options (e.g. get_project) — that path is separate.
|
|
6
|
+
*/
|
|
7
|
+
/** Associate a persona id with an MCP server (call before registering tools). */
|
|
8
|
+
export declare function bindServerPersona(server: object, personaId: string): void;
|
|
9
|
+
/** Persona id bound to this server, if any. */
|
|
10
|
+
export declare function getServerPersona(server: object): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bind an MCP server instance to a persona id for audit attribution.
|
|
4
|
+
* Call once in registerCapabilities before registering tools; registerToolSafe
|
|
5
|
+
* reads it at wrap time. Tool behavior that needs personaId still uses
|
|
6
|
+
* registerToolsByIds options (e.g. get_project) — that path is separate.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.bindServerPersona = bindServerPersona;
|
|
10
|
+
exports.getServerPersona = getServerPersona;
|
|
11
|
+
const serverPersona = new WeakMap();
|
|
12
|
+
/** Associate a persona id with an MCP server (call before registering tools). */
|
|
13
|
+
function bindServerPersona(server, personaId) {
|
|
14
|
+
serverPersona.set(server, personaId);
|
|
15
|
+
}
|
|
16
|
+
/** Persona id bound to this server, if any. */
|
|
17
|
+
function getServerPersona(server) {
|
|
18
|
+
return serverPersona.get(server);
|
|
19
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OAuth broker pending / codes / DCR clients (ADR-0007 / ADR-
|
|
2
|
+
* OAuth broker pending / codes / DCR clients (ADR-0007 / ADR-0019).
|
|
3
3
|
*
|
|
4
|
-
* All values are JSON-serializable
|
|
5
|
-
*
|
|
6
|
-
* handoff for authorize → callback → token when STORE=redis.
|
|
4
|
+
* All values are JSON-serializable. Backend: in-memory only — process-local.
|
|
5
|
+
* Multi-instance OAuth needs sticky `/oauth/*` or a single replica until signed-state/CIMD.
|
|
7
6
|
*/
|
|
8
7
|
export interface PendingAuthorization {
|
|
9
8
|
/** Broker state sent to Lightdash (opaque). */
|
|
@@ -54,8 +53,8 @@ export type OAuthBrokerStoreOptions = {
|
|
|
54
53
|
maxClients?: number;
|
|
55
54
|
};
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
56
|
+
* OAuth broker ephemeral store (ADR-0019). In-memory only (process-local).
|
|
57
|
+
* Async methods keep call sites await-uniform for future backends if needed.
|
|
59
58
|
*/
|
|
60
59
|
export interface OAuthBrokerStore {
|
|
61
60
|
registerClient(redirectUris: readonly string[]): Promise<RegisteredClient | undefined>;
|
|
@@ -69,7 +68,7 @@ export interface OAuthBrokerStore {
|
|
|
69
68
|
tokenType?: string;
|
|
70
69
|
scope?: string;
|
|
71
70
|
}): Promise<IssuedAuthorizationCode | undefined>;
|
|
72
|
-
/** Atomic get+delete
|
|
71
|
+
/** Atomic get+delete for one-time code consume. */
|
|
73
72
|
takeCode(code: string): Promise<IssuedAuthorizationCode | undefined>;
|
|
74
73
|
/**
|
|
75
74
|
* Re-insert a previously taken code with remaining TTL based on `createdAt`
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* OAuth broker pending / codes / DCR clients (ADR-0007 / ADR-
|
|
3
|
+
* OAuth broker pending / codes / DCR clients (ADR-0007 / ADR-0019).
|
|
4
4
|
*
|
|
5
|
-
* All values are JSON-serializable
|
|
6
|
-
*
|
|
7
|
-
* handoff for authorize → callback → token when STORE=redis.
|
|
5
|
+
* All values are JSON-serializable. Backend: in-memory only — process-local.
|
|
6
|
+
* Multi-instance OAuth needs sticky `/oauth/*` or a single replica until signed-state/CIMD.
|
|
8
7
|
*/
|
|
9
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
9
|
exports.InMemoryOAuthBrokerStore = exports.DEFAULT_MAX_CLIENTS = exports.DEFAULT_MAX_CODES = exports.DEFAULT_MAX_PENDING = exports.DEFAULT_CLIENT_TTL_MS = exports.DEFAULT_CODE_TTL_MS = exports.DEFAULT_PENDING_TTL_MS = void 0;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* In-memory OAuthBrokerStore unit tests (ADR-0016).
|
|
3
|
-
* Redis
|
|
4
|
-
* (skipped otherwise — no Redis required for default CI).
|
|
2
|
+
* In-memory OAuthBrokerStore unit tests (ADR-0016 / ADR-0019).
|
|
3
|
+
* Redis backend removed per ADR-0019; always memory.
|
|
5
4
|
*/
|
|
6
5
|
export {};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* In-memory OAuthBrokerStore unit tests (ADR-0016).
|
|
4
|
-
* Redis
|
|
5
|
-
* (skipped otherwise — no Redis required for default CI).
|
|
3
|
+
* In-memory OAuthBrokerStore unit tests (ADR-0016 / ADR-0019).
|
|
4
|
+
* Redis backend removed per ADR-0019; always memory.
|
|
6
5
|
*/
|
|
7
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
7
|
const vitest_1 = require("vitest");
|
|
9
|
-
const create_oauth_broker_store_js_1 = require("../../store/create-oauth-broker-store.js");
|
|
10
|
-
const redis_client_js_1 = require("../../store/redis-client.js");
|
|
11
8
|
const pending_store_js_1 = require("./pending-store.js");
|
|
12
9
|
(0, vitest_1.describe)('InMemoryOAuthBrokerStore', () => {
|
|
13
10
|
(0, vitest_1.it)('createPending / takePending is single-use', async () => {
|
|
@@ -110,37 +107,3 @@ const pending_store_js_1 = require("./pending-store.js");
|
|
|
110
107
|
(0, vitest_1.expect)(await store.registerClient(['http://127.0.0.1:1/cb2'])).toBeUndefined();
|
|
111
108
|
});
|
|
112
109
|
});
|
|
113
|
-
(0, vitest_1.describe)('createOAuthBrokerStore', () => {
|
|
114
|
-
var _a;
|
|
115
|
-
(0, vitest_1.it)('returns memory store by default', async () => {
|
|
116
|
-
const store = (0, create_oauth_broker_store_js_1.createOAuthBrokerStore)({ backend: 'memory' });
|
|
117
|
-
const pending = await store.createPending({
|
|
118
|
-
clientId: 'c1',
|
|
119
|
-
redirectUri: 'http://127.0.0.1:1/cb',
|
|
120
|
-
codeChallenge: 'ch',
|
|
121
|
-
codeChallengeMethod: 'S256',
|
|
122
|
-
});
|
|
123
|
-
(0, vitest_1.expect)(pending === null || pending === void 0 ? void 0 : pending.brokerState).toBeTruthy();
|
|
124
|
-
});
|
|
125
|
-
const redisUrl = (_a = process.env.LIGHTDASH_TOOLS_MCP_REDIS_URL) === null || _a === void 0 ? void 0 : _a.trim();
|
|
126
|
-
const describeRedis = redisUrl ? vitest_1.describe : vitest_1.describe.skip;
|
|
127
|
-
describeRedis('redis backend', () => {
|
|
128
|
-
(0, vitest_1.afterEach)(async () => {
|
|
129
|
-
await (0, redis_client_js_1.resetSharedRedisClientForTests)();
|
|
130
|
-
});
|
|
131
|
-
(0, vitest_1.it)('persists pending across store instances', async () => {
|
|
132
|
-
const config = { backend: 'redis', redisUrl: redisUrl };
|
|
133
|
-
const a = (0, create_oauth_broker_store_js_1.createOAuthBrokerStore)(config);
|
|
134
|
-
const pending = await a.createPending({
|
|
135
|
-
clientId: 'c1',
|
|
136
|
-
redirectUri: 'http://127.0.0.1:1/cb',
|
|
137
|
-
codeChallenge: 'ch',
|
|
138
|
-
codeChallengeMethod: 'S256',
|
|
139
|
-
});
|
|
140
|
-
(0, vitest_1.expect)(pending).toBeDefined();
|
|
141
|
-
const b = (0, create_oauth_broker_store_js_1.createOAuthBrokerStore)(config);
|
|
142
|
-
const taken = await b.takePending(pending.brokerState);
|
|
143
|
-
(0, vitest_1.expect)(taken === null || taken === void 0 ? void 0 : taken.clientId).toBe('c1');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
@@ -8,6 +8,6 @@ export interface OAuthBroker {
|
|
|
8
8
|
export declare function isOAuthBrokerPath(path: string): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Creates the OAuth broker request handler for co-located AS façade routes.
|
|
11
|
-
*
|
|
11
|
+
* Pending state is process-local (InMemoryOAuthBrokerStore); sticky `/oauth/*` for multi-instance.
|
|
12
12
|
*/
|
|
13
13
|
export declare function createOAuthBroker(config: McpHttpConfig, store?: OAuthBrokerStore): OAuthBroker;
|
|
@@ -4,11 +4,11 @@ exports.isOAuthBrokerPath = isOAuthBrokerPath;
|
|
|
4
4
|
exports.createOAuthBroker = createOAuthBroker;
|
|
5
5
|
const env_js_1 = require("../../config/env.js");
|
|
6
6
|
const normalize_url_js_1 = require("../../config/normalize-url.js");
|
|
7
|
-
const create_oauth_broker_store_js_1 = require("../../store/create-oauth-broker-store.js");
|
|
8
7
|
const http_body_js_1 = require("../../transports/http-body.js");
|
|
9
8
|
const http_response_js_1 = require("../../transports/http-response.js");
|
|
10
9
|
const as_metadata_js_1 = require("./as-metadata.js");
|
|
11
10
|
const lightdash_token_js_1 = require("./lightdash-token.js");
|
|
11
|
+
const pending_store_js_1 = require("./pending-store.js");
|
|
12
12
|
const pkce_js_1 = require("./pkce.js");
|
|
13
13
|
/** Schemes that must never be used as OAuth redirect targets. */
|
|
14
14
|
const BLOCKED_REDIRECT_SCHEMES = new Set(['javascript:', 'data:', 'vbscript:', 'file:']);
|
|
@@ -414,9 +414,9 @@ function isOAuthBrokerPath(path) {
|
|
|
414
414
|
}
|
|
415
415
|
/**
|
|
416
416
|
* Creates the OAuth broker request handler for co-located AS façade routes.
|
|
417
|
-
*
|
|
417
|
+
* Pending state is process-local (InMemoryOAuthBrokerStore); sticky `/oauth/*` for multi-instance.
|
|
418
418
|
*/
|
|
419
|
-
function createOAuthBroker(config, store =
|
|
419
|
+
function createOAuthBroker(config, store = new pending_store_js_1.InMemoryOAuthBrokerStore()) {
|
|
420
420
|
return {
|
|
421
421
|
async handle(req, res, path) {
|
|
422
422
|
if (!isOAuthBrokerPath(path)) {
|