@lightdash-tools/mcp 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -170
- package/dist/audit/server-persona.d.ts +10 -0
- package/dist/audit/server-persona.js +19 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +69 -19
- package/dist/auth/oauth-broker/pending-store.js +52 -26
- package/dist/auth/oauth-broker/pending-store.test.d.ts +5 -0
- package/dist/auth/oauth-broker/pending-store.test.js +109 -0
- package/dist/auth/oauth-broker/routes.d.ts +6 -2
- package/dist/auth/oauth-broker/routes.js +25 -20
- package/dist/auth/oauth-broker/routes.test.js +33 -28
- package/dist/auth/request-state-key.d.ts +19 -0
- package/dist/auth/request-state-key.js +49 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +0 -2
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +0 -19
- package/dist/auth/resource-server/www-authenticate.test.js +12 -8
- package/dist/bin.js +30 -2
- package/dist/config/env.d.ts +5 -8
- package/dist/config/env.js +6 -9
- package/dist/config/load-mcp-config.d.ts +0 -4
- package/dist/config/load-mcp-config.js +8 -5
- package/dist/config/load-mcp-config.test.js +7 -0
- package/dist/config/normalize-url.test.js +16 -7
- package/dist/config/runtime.d.ts +3 -3
- package/dist/config/runtime.js +19 -23
- package/dist/config/runtime.test.js +23 -9
- package/dist/config/test-mcp-http-config.js +1 -1
- package/dist/destructive/capability.d.ts +13 -0
- package/dist/destructive/capability.js +37 -0
- package/dist/destructive/capability.test.js +46 -0
- package/dist/destructive/confirmation.d.ts +58 -0
- package/dist/destructive/confirmation.js +99 -0
- package/dist/destructive/confirmation.test.d.ts +1 -0
- package/dist/destructive/confirmation.test.js +75 -0
- package/dist/destructive/content-promote.d.ts +8 -0
- package/dist/destructive/content-promote.js +150 -0
- package/dist/destructive/content-soft-delete.d.ts +7 -0
- package/dist/destructive/content-soft-delete.js +106 -0
- package/dist/destructive/destructive-contract.test.d.ts +1 -0
- package/dist/destructive/destructive-contract.test.js +269 -0
- package/dist/destructive/precondition.d.ts +14 -0
- package/dist/destructive/precondition.js +31 -0
- package/dist/destructive/precondition.test.d.ts +1 -0
- package/dist/destructive/precondition.test.js +72 -0
- package/dist/destructive/promote-contract.test.d.ts +1 -0
- package/dist/destructive/promote-contract.test.js +398 -0
- package/dist/destructive/register-destructive-tool.d.ts +54 -0
- package/dist/destructive/register-destructive-tool.js +283 -0
- package/dist/destructive/request-state.d.ts +12 -0
- package/dist/destructive/request-state.js +41 -0
- package/dist/destructive/types.d.ts +65 -0
- package/dist/destructive/types.js +10 -0
- package/dist/governance/available-projects.d.ts +37 -0
- package/dist/governance/available-projects.js +132 -0
- package/dist/governance/available-projects.test.d.ts +4 -0
- package/dist/governance/available-projects.test.js +107 -0
- package/dist/governance/client-capabilities-cache.d.ts +44 -0
- package/dist/governance/client-capabilities-cache.js +142 -0
- package/dist/governance/client-capabilities-cache.test.d.ts +1 -0
- package/dist/governance/client-capabilities-cache.test.js +148 -0
- package/dist/governance/mcp-client-session.d.ts +10 -0
- package/dist/governance/mcp-client-session.js +31 -0
- package/dist/governance/mcp-client-session.test.d.ts +1 -0
- package/dist/governance/mcp-client-session.test.js +31 -0
- package/dist/governance/project-scope.d.ts +24 -0
- package/dist/governance/project-scope.js +71 -0
- package/dist/governance/project-scope.test.d.ts +4 -0
- package/dist/governance/project-scope.test.js +80 -0
- package/dist/governance/promote-allowlist.d.ts +18 -0
- package/dist/governance/promote-allowlist.js +66 -0
- package/dist/governance/promote-allowlist.test.d.ts +4 -0
- package/dist/governance/promote-allowlist.test.js +87 -0
- package/dist/http.integration.test.js +151 -262
- package/dist/http.test.js +0 -12
- package/dist/index.integration.test.js +0 -4
- package/dist/index.js +3 -1
- package/dist/personas/ai-agent-ops/v1/index.d.ts +8 -0
- package/dist/personas/ai-agent-ops/v1/index.js +41 -0
- package/dist/personas/ai-agent-ops/v1/prompts.d.ts +5 -0
- package/dist/personas/ai-agent-ops/v1/prompts.js +141 -0
- package/dist/personas/ai-agent-ops/v1/prompts.test.d.ts +4 -0
- package/dist/personas/ai-agent-ops/v1/prompts.test.js +26 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/ai-agent-ops/v1/resources/playbooks.js +41 -0
- package/dist/personas/content-developer/v1/index.d.ts +10 -0
- package/dist/personas/content-developer/v1/index.js +52 -0
- package/dist/personas/content-developer/v1/prompts.d.ts +8 -0
- package/dist/personas/content-developer/v1/prompts.js +157 -0
- package/dist/personas/content-developer/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-developer/v1/prompts.test.js +231 -0
- package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
- package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +22 -0
- package/dist/personas/content-developer/v1/resources/playbooks/core.md +105 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
- package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +103 -0
- package/dist/personas/content-developer/v1/resources/playbooks/index.md +15 -0
- package/dist/personas/content-developer/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-developer/v1/resources/playbooks.js +63 -0
- package/dist/personas/content-governance/v1/index.d.ts +9 -0
- package/dist/personas/content-governance/v1/index.js +29 -0
- package/dist/personas/content-governance/v1/prompts.d.ts +5 -0
- package/dist/personas/content-governance/v1/prompts.js +87 -0
- package/dist/personas/content-governance/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-governance/v1/prompts.test.js +75 -0
- package/dist/personas/content-governance/v1/resources/playbooks/charts.md +29 -0
- package/dist/personas/content-governance/v1/resources/playbooks/core.md +52 -0
- package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +48 -0
- package/dist/personas/content-governance/v1/resources/playbooks/index.md +13 -0
- package/dist/personas/content-governance/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-governance/v1/resources/playbooks.js +41 -0
- package/dist/personas/content-reader/v1/index.d.ts +8 -0
- package/dist/personas/content-reader/v1/index.js +38 -0
- package/dist/personas/content-reader/v1/prompts.d.ts +5 -0
- package/dist/personas/content-reader/v1/prompts.js +162 -0
- package/dist/personas/content-reader/v1/prompts.test.d.ts +4 -0
- package/dist/personas/content-reader/v1/prompts.test.js +25 -0
- package/dist/personas/content-reader/v1/resources/playbooks/compare.md +36 -0
- package/dist/personas/content-reader/v1/resources/playbooks/core.md +67 -0
- package/dist/personas/content-reader/v1/resources/playbooks/discover.md +35 -0
- package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +49 -0
- package/dist/personas/content-reader/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/content-reader/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/content-reader/v1/resources/playbooks.js +49 -0
- package/dist/personas/index.d.ts +4 -0
- package/dist/personas/index.js +31 -10
- package/dist/personas/index.test.js +92 -26
- package/dist/personas/lib/playbook-resources.d.ts +80 -0
- package/dist/personas/lib/playbook-resources.js +169 -0
- package/dist/personas/organization-audit/v1/index.js +2 -2
- package/dist/personas/organization-audit/v1/prompts.js +79 -66
- package/dist/personas/organization-audit/v1/prompts.test.js +4 -4
- package/dist/personas/organization-audit/v1/resources/playbooks/access.md +21 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/content.md +19 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/core.md +69 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +14 -0
- package/dist/personas/organization-audit/v1/resources/playbooks/index.md +14 -0
- package/dist/personas/organization-audit/v1/resources/playbooks.d.ts +10 -0
- package/dist/personas/organization-audit/v1/resources/playbooks.js +41 -0
- package/dist/personas/persona.parity.test.d.ts +1 -0
- package/dist/personas/persona.parity.test.js +30 -0
- package/dist/personas/semantic-layer/v1/index.js +2 -2
- package/dist/personas/semantic-layer/v1/prompts.js +56 -67
- package/dist/personas/semantic-layer/v1/prompts.test.d.ts +4 -0
- package/dist/personas/semantic-layer/v1/prompts.test.js +19 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +60 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +71 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +79 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +13 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks.d.ts +13 -0
- package/dist/personas/semantic-layer/v1/resources/playbooks.js +39 -0
- package/dist/personas/types.d.ts +1 -1
- package/dist/policy/content-developer.d.ts +35 -0
- package/dist/policy/content-developer.js +91 -0
- package/dist/policy/content-developer.test.d.ts +4 -0
- package/dist/policy/content-developer.test.js +54 -0
- package/dist/policy/content-reader.d.ts +28 -0
- package/dist/policy/content-reader.js +67 -0
- package/dist/policy/content-reader.test.d.ts +4 -0
- package/dist/policy/content-reader.test.js +23 -0
- package/dist/policy/envelope.d.ts +31 -0
- package/dist/policy/envelope.js +24 -0
- package/dist/policy/preview-ledger-fault.test.d.ts +1 -0
- package/dist/policy/preview-ledger-fault.test.js +202 -0
- package/dist/policy/preview-ledger.d.ts +82 -0
- package/dist/policy/preview-ledger.js +165 -0
- package/dist/policy/preview-ledger.test.d.ts +1 -0
- package/dist/policy/preview-ledger.test.js +393 -0
- package/dist/policy/result-limits.d.ts +32 -0
- package/dist/policy/result-limits.js +106 -0
- package/dist/policy/result-limits.test.d.ts +4 -0
- package/dist/policy/result-limits.test.js +37 -0
- package/dist/server/capabilities.js +3 -1
- package/dist/server/capabilities.test.js +5 -1
- package/dist/server/server.js +16 -1
- package/dist/server/upstream-errors.d.ts +17 -0
- package/dist/server/upstream-errors.js +60 -0
- package/dist/server/upstream-errors.test.d.ts +1 -0
- package/dist/server/upstream-errors.test.js +50 -0
- package/dist/stdio.process.test.js +150 -0
- package/dist/tools/ai-agents/agents.d.ts +7 -0
- package/dist/tools/ai-agents/agents.js +32 -0
- package/dist/tools/ai-agents/agents.test.d.ts +1 -0
- package/dist/tools/ai-agents/agents.test.js +176 -0
- package/dist/tools/ai-agents/discovery.d.ts +9 -0
- package/dist/tools/ai-agents/discovery.js +73 -0
- package/dist/tools/ai-agents/evaluations.d.ts +14 -0
- package/dist/tools/ai-agents/evaluations.js +177 -0
- package/dist/tools/ai-agents/helpers.d.ts +64 -0
- package/dist/tools/ai-agents/helpers.js +323 -0
- package/dist/tools/ai-agents/threads.d.ts +7 -0
- package/dist/tools/ai-agents/threads.js +40 -0
- package/dist/tools/composition/explain-content.d.ts +6 -0
- package/dist/tools/composition/explain-content.js +108 -0
- package/dist/tools/lib/api-errors.d.ts +2 -0
- package/dist/tools/lib/api-errors.js +5 -0
- package/dist/tools/lib/stable-stringify.d.ts +9 -0
- package/dist/tools/lib/stable-stringify.js +35 -0
- package/dist/tools/organization/inventory.js +2 -1
- package/dist/tools/project/content.js +5 -1
- package/dist/tools/project/delete-chart.d.ts +4 -0
- package/dist/tools/project/delete-chart.js +8 -0
- package/dist/tools/project/delete-dashboard.d.ts +4 -0
- package/dist/tools/project/delete-dashboard.js +8 -0
- package/dist/tools/project/developer-content-preview.d.ts +13 -0
- package/dist/tools/project/developer-content-preview.js +291 -0
- package/dist/tools/project/developer-content-shared.d.ts +24 -0
- package/dist/tools/project/developer-content-shared.js +50 -0
- package/dist/tools/project/developer-content-shared.test.d.ts +1 -0
- package/dist/tools/project/developer-content-shared.test.js +25 -0
- package/dist/tools/project/developer-content.d.ts +38 -0
- package/dist/tools/project/developer-content.js +589 -0
- package/dist/tools/project/developer-get-chart-as-code.d.ts +9 -0
- package/dist/tools/project/developer-get-chart-as-code.js +39 -0
- package/dist/tools/project/developer-get-chart-as-code.test.d.ts +4 -0
- package/dist/tools/project/developer-get-chart-as-code.test.js +70 -0
- package/dist/tools/project/developer-helpers.d.ts +180 -0
- package/dist/tools/project/developer-helpers.js +484 -0
- package/dist/tools/project/developer-helpers.test.d.ts +1 -0
- package/dist/tools/project/developer-helpers.test.js +509 -0
- package/dist/tools/project/get-dashboard-promote-diff.d.ts +6 -0
- package/dist/tools/project/get-dashboard-promote-diff.js +52 -0
- package/dist/tools/project/invariants.test.d.ts +4 -0
- package/dist/tools/project/invariants.test.js +44 -0
- package/dist/tools/project/parameters.d.ts +7 -0
- package/dist/tools/project/parameters.js +74 -0
- package/dist/tools/project/projects.d.ts +4 -1
- package/dist/tools/project/projects.js +68 -6
- package/dist/tools/project/projects.test.js +77 -1
- package/dist/tools/project/promote-dashboard.d.ts +4 -0
- package/dist/tools/project/promote-dashboard.js +8 -0
- package/dist/tools/project/reader-content.d.ts +9 -0
- package/dist/tools/project/reader-content.js +208 -0
- package/dist/tools/project/reader-execution.d.ts +7 -0
- package/dist/tools/project/reader-execution.js +214 -0
- package/dist/tools/project/reader-export-chart-image.d.ts +6 -0
- package/dist/tools/project/reader-export-chart-image.js +78 -0
- package/dist/tools/project/reader-export-chart-image.test.d.ts +4 -0
- package/dist/tools/project/reader-export-chart-image.test.js +149 -0
- package/dist/tools/project/schemas/chart-upsert.d.ts +33 -0
- package/dist/tools/project/schemas/chart-upsert.js +66 -0
- package/dist/tools/project/schemas/dashboard-tile.d.ts +29 -0
- package/dist/tools/project/schemas/dashboard-tile.js +57 -0
- package/dist/tools/project/schemas/dashboard.d.ts +70 -0
- package/dist/tools/project/schemas/dashboard.js +101 -0
- package/dist/tools/project/schemas/duplicate.d.ts +30 -0
- package/dist/tools/project/schemas/duplicate.js +86 -0
- package/dist/tools/project/schemas/index.d.ts +7 -0
- package/dist/tools/project/schemas/index.js +26 -0
- package/dist/tools/project/schemas/parse-helpers.d.ts +14 -0
- package/dist/tools/project/schemas/parse-helpers.js +34 -0
- package/dist/tools/project/schemas/payload-schemas.test.d.ts +1 -0
- package/dist/tools/project/schemas/payload-schemas.test.js +204 -0
- package/dist/tools/project/spaces.d.ts +7 -0
- package/dist/tools/project/spaces.js +101 -0
- package/dist/tools/query/bounded-saved-query.d.ts +37 -0
- package/dist/tools/query/bounded-saved-query.js +80 -0
- package/dist/tools/query/bounded-saved-query.test.d.ts +4 -0
- package/dist/tools/query/bounded-saved-query.test.js +82 -0
- package/dist/tools/query/chart-source.d.ts +10 -0
- package/dist/tools/query/chart-source.js +36 -0
- package/dist/tools/query/chart-source.test.d.ts +1 -0
- package/dist/tools/query/chart-source.test.js +62 -0
- package/dist/tools/query/filter-overrides.d.ts +34 -0
- package/dist/tools/query/filter-overrides.js +75 -0
- package/dist/tools/query/filter-overrides.test.d.ts +1 -0
- package/dist/tools/query/filter-overrides.test.js +21 -0
- package/dist/tools/query/lifecycle.d.ts +7 -0
- package/dist/tools/query/lifecycle.js +104 -0
- package/dist/tools/query/query-ledger.d.ts +41 -0
- package/dist/tools/query/query-ledger.js +92 -0
- package/dist/tools/query/query-ledger.test.d.ts +1 -0
- package/dist/tools/query/query-ledger.test.js +75 -0
- package/dist/tools/query/reader-tool-helpers.d.ts +12 -0
- package/dist/tools/query/reader-tool-helpers.js +57 -0
- package/dist/tools/query/reader-tool-helpers.test.d.ts +1 -0
- package/dist/tools/query/reader-tool-helpers.test.js +53 -0
- package/dist/tools/query/result-normalizer.d.ts +27 -0
- package/dist/tools/query/result-normalizer.js +133 -0
- package/dist/tools/query/result-normalizer.test.d.ts +1 -0
- package/dist/tools/query/result-normalizer.test.js +41 -0
- package/dist/tools/query/wait-for-async.d.ts +10 -0
- package/dist/tools/query/wait-for-async.js +46 -0
- package/dist/tools/query/wait-for-async.test.d.ts +1 -0
- package/dist/tools/query/wait-for-async.test.js +45 -0
- package/dist/tools/registry.d.ts +187 -3
- package/dist/tools/registry.js +89 -7
- package/dist/tools/shared.d.ts +52 -10
- package/dist/tools/shared.js +127 -41
- package/dist/tools/shared.test.js +103 -3
- package/dist/transports/streamable-http.js +47 -198
- package/dist/transports/streamable-http.test.js +21 -9
- package/package.json +5 -5
- package/dist/personas/organization-audit/v1/resources/playbook.d.ts +0 -11
- package/dist/personas/organization-audit/v1/resources/playbook.js +0 -40
- package/dist/personas/organization-audit/v1/resources/playbook.md +0 -52
- package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +0 -12
- package/dist/personas/semantic-layer/v1/resources/playbook.js +0 -42
- package/dist/personas/semantic-layer/v1/resources/playbook.md +0 -153
- package/dist/transports/http-request-utils.d.ts +0 -2
- package/dist/transports/http-request-utils.js +0 -13
- package/dist/transports/session-store.d.ts +0 -40
- package/dist/transports/session-store.js +0 -88
- package/dist/transports/session-store.test.js +0 -111
- /package/dist/{transports/session-store.test.d.ts → destructive/capability.test.d.ts} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Semantic-layer — explore / discover
|
|
2
|
+
|
|
3
|
+
URI: `lightdash://playbooks/semantic-layer/explore`
|
|
4
|
+
|
|
5
|
+
## Always search explores
|
|
6
|
+
|
|
7
|
+
On large projects, **never** rely on an unfiltered explore list (alphabetical noise across domains). Always call `lightdash_list_explores` with **`search` + `limit` (≤15)**.
|
|
8
|
+
|
|
9
|
+
Warehouse table / dataset names are **search hints**, not explore IDs. Explore `name` is usually compound (often `{warehouse}__{dataset}__{table}`-style).
|
|
10
|
+
|
|
11
|
+
## From warehouse inventory → explore
|
|
12
|
+
|
|
13
|
+
| Inventory hint | MCP use |
|
|
14
|
+
| ---------------------------- | ----------------------------------------------------------------- |
|
|
15
|
+
| Dataset | Prefer matching **`schemaName`** |
|
|
16
|
+
| TABLE | `search` = table token; prefer **exact `label`** = table |
|
|
17
|
+
| Partition / time field | Candidate dimension for time-grain compiles |
|
|
18
|
+
| Full `project.dataset.table` | `databaseName` ≈ project, `schemaName` ≈ dataset, `label` ≈ table |
|
|
19
|
+
|
|
20
|
+
Some inventory tables have **no** explore. Empty or irrelevant search → say so; try a related curated/summary table the user cares about.
|
|
21
|
+
|
|
22
|
+
## Explore disambiguation (do not pick the first hit)
|
|
23
|
+
|
|
24
|
+
Search for `{table}` often returns siblings: staging / EDA / reporting / MRE variants, empty-schema stubs, and the warehouse table.
|
|
25
|
+
|
|
26
|
+
1. Skip explores with non-empty `errors`.
|
|
27
|
+
2. Skip rows with **empty `schemaName`** / empty tags / junk `name` (e.g. `_`) unless nothing else matches.
|
|
28
|
+
3. If the user named a dataset, prefer matching **`schemaName`**.
|
|
29
|
+
4. Match table via **exact `label`** = `{table}` **or** explore **`name`** containing `__{table}`.
|
|
30
|
+
5. Prefer tags such as `lightdash` when still tied; deprioritize `eda_` / `reporting_` / staging-style prefixes unless asked.
|
|
31
|
+
6. Duplicate labels / `_vN` suffixes: prefer the explore **`name`** without an extra version suffix unless the user asked for that version.
|
|
32
|
+
7. State chosen explore **`name`**, `label`, `schemaName`, and `databaseName` in the answer.
|
|
33
|
+
|
|
34
|
+
Remember: `databaseName` may differ from the Lightdash project’s usual warehouse — stay on the given `projectUuid`.
|
|
35
|
+
|
|
36
|
+
## Progressive discovery
|
|
37
|
+
|
|
38
|
+
1. `list_explores` → disambiguate → lock `exploreId` (= explore `name`).
|
|
39
|
+
2. `list_dimensions` (default `baseTableOnly=true`). Set `baseTableOnly=false` only if you need joined-table fields (payload grows a lot).
|
|
40
|
+
3. Metrics: **`get_explore` → `tables[baseTable].metrics` only** (see below). Do not dump the explore JSON.
|
|
41
|
+
4. Stop at a shortlist unless the user asked to compile.
|
|
42
|
+
|
|
43
|
+
## Metrics: catalog vs explore-local (critical)
|
|
44
|
+
|
|
45
|
+
`list_metrics` searches the **project catalog**, not “metrics on this explore”.
|
|
46
|
+
|
|
47
|
+
| Search token | Typical result |
|
|
48
|
+
| -------------------------------------------- | --------------------------------------------------- |
|
|
49
|
+
| Full explore id | **Often zero** hits |
|
|
50
|
+
| Warehouse table label alone | **Often zero** |
|
|
51
|
+
| Broad domain tokens (`session`, `medico`, …) | Hundreds of **other** tables — flood |
|
|
52
|
+
| Goal keyword from the question | May hit this explore **and** siblings — must filter |
|
|
53
|
+
|
|
54
|
+
Rules:
|
|
55
|
+
|
|
56
|
+
1. Once the explore is known, prefer **`get_explore` → `tables[baseTable].metrics`** for the local menu (names + labels only). Ignore other keys under `tables` (joins).
|
|
57
|
+
2. Optional catalog: at most **one** `list_metrics` page. Keep rows where `tableName` **equals the full explore id**.
|
|
58
|
+
3. `get_metric` `tableName` must be the full explore id. Short labels → “Metric not found”. Call only when definition/SQL is needed; summarize — payloads include huge `availableTimeDimensions` from joins.
|
|
59
|
+
4. Compile metric ids as `{exploreId}_{metricName}` (same pattern as dimension `fieldId` from `list_dimensions`).
|
|
60
|
+
5. Dimension-only (`metrics: []`) is valid for volume-by-time; for “insights” prefer real explore metrics when available.
|
|
61
|
+
|
|
62
|
+
## Dimension shortlist (large explores)
|
|
63
|
+
|
|
64
|
+
Base tables can expose **hundreds** of dimensions; many are nested (`a.b.c` paths / event arrays). Do **not** dump the list.
|
|
65
|
+
|
|
66
|
+
Prefer high-signal fields that **appear in `list_dimensions`**, by **role**:
|
|
67
|
+
|
|
68
|
+
- Time grains that exist as real `fieldId`s (day / week / month; prefer local timezone grains when both UTC and local exist — e.g. `*_jst_day`)
|
|
69
|
+
- Channel / platform / traffic source
|
|
70
|
+
- Segment / demographic / cohort dimensions relevant to the question
|
|
71
|
+
- Core product or entity attributes named in the question
|
|
72
|
+
|
|
73
|
+
Skip nested event dumps and deep struct paths unless the question targets them.
|
|
74
|
+
|
|
75
|
+
**Copy `fieldId` literally.** Do not invent grains like `{explore}_session_day` if that string is not in `list_dimensions`.
|
|
76
|
+
|
|
77
|
+
## Field lineage
|
|
78
|
+
|
|
79
|
+
`get_field_lineage` accepts full `fieldId` or short `name`. Default: skip. If used once, answer with a short summary (e.g. “upstream models: A → B → explore”) — never paste the graph.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Semantic-layer playbooks
|
|
2
|
+
|
|
3
|
+
URI: `lightdash://playbooks/semantic-layer`
|
|
4
|
+
|
|
5
|
+
Workflow-scoped playbooks (always load **core** plus one topic with a prompt):
|
|
6
|
+
|
|
7
|
+
| Topic | URI |
|
|
8
|
+
| --------------------------------- | ------------------------------------------------------ |
|
|
9
|
+
| Core (bans, budgets, scope, stop) | `lightdash://playbooks/semantic-layer/core` |
|
|
10
|
+
| Explore / discover | `lightdash://playbooks/semantic-layer/explore` |
|
|
11
|
+
| Compose & compile | `lightdash://playbooks/semantic-layer/compose-compile` |
|
|
12
|
+
|
|
13
|
+
Discover the Lightdash semantic layer and **compose + compile** metric queries under default budgets. Stop after a verified compile (or clear compile errors). Do **not** run warehouse queries or mutate content.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic-layer multi-playbook resources (core + topics + index).
|
|
3
|
+
*/
|
|
4
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
+
export type SemanticLayerPlaybookTopic = 'compose-compile' | 'explore';
|
|
6
|
+
export declare const SEMANTIC_LAYER_CORE_URI: string;
|
|
7
|
+
export declare const SEMANTIC_LAYER_EXPLORE_URI: string;
|
|
8
|
+
export declare const SEMANTIC_LAYER_COMPOSE_COMPILE_URI: string;
|
|
9
|
+
export declare const SEMANTIC_LAYER_HARD_BANS: string;
|
|
10
|
+
export declare const getAllPlaybookMarkdown: () => string;
|
|
11
|
+
export declare const SEMANTIC_LAYER_CORE_PLAYBOOK: import("../../../lib/playbook-resources.js").EmbeddedPlaybook;
|
|
12
|
+
export declare const SEMANTIC_LAYER_TOPIC_PLAYBOOKS: Readonly<Record<SemanticLayerPlaybookTopic, import("../../../lib/playbook-resources.js").EmbeddedPlaybook>>;
|
|
13
|
+
export declare function registerSemanticLayerPlaybook(server: McpServer): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Semantic-layer multi-playbook resources (core + topics + index).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SEMANTIC_LAYER_TOPIC_PLAYBOOKS = exports.SEMANTIC_LAYER_CORE_PLAYBOOK = exports.getAllPlaybookMarkdown = exports.SEMANTIC_LAYER_HARD_BANS = exports.SEMANTIC_LAYER_COMPOSE_COMPILE_URI = exports.SEMANTIC_LAYER_EXPLORE_URI = exports.SEMANTIC_LAYER_CORE_URI = void 0;
|
|
7
|
+
exports.registerSemanticLayerPlaybook = registerSemanticLayerPlaybook;
|
|
8
|
+
const playbook_resources_js_1 = require("../../../lib/playbook-resources.js");
|
|
9
|
+
const playbooks = (0, playbook_resources_js_1.definePersonaPlaybooks)({
|
|
10
|
+
personaId: 'semantic-layer',
|
|
11
|
+
moduleDir: __dirname,
|
|
12
|
+
/** Shared hard-ban text for prompts (keep in sync with playbooks/core.md Hard bans section). */
|
|
13
|
+
hardBans: 'Do not run metric/SQL/chart queries, use SQL runner, trigger validation jobs, mutate content, switch away from the given projectUuid, invent fieldIds, dump full explore/metric/lineage payloads, or call AI/identity tools. Those are not available on this server.',
|
|
14
|
+
coreDescription: 'Hard bans, budgets, allowed tools, project scope, and stop criteria',
|
|
15
|
+
topics: [
|
|
16
|
+
{
|
|
17
|
+
id: 'explore',
|
|
18
|
+
title: 'Semantic-layer explore playbook',
|
|
19
|
+
description: 'Explore discovery, disambiguation, and field shortlisting',
|
|
20
|
+
file: 'explore.md',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'compose-compile',
|
|
24
|
+
title: 'Semantic-layer compose/compile playbook',
|
|
25
|
+
description: 'Compose metric queries and compile without warehouse execution',
|
|
26
|
+
file: 'compose-compile.md',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
exports.SEMANTIC_LAYER_CORE_URI = playbooks.URIs.core;
|
|
31
|
+
exports.SEMANTIC_LAYER_EXPLORE_URI = playbooks.URIs.topics.explore;
|
|
32
|
+
exports.SEMANTIC_LAYER_COMPOSE_COMPILE_URI = playbooks.URIs.topics['compose-compile'];
|
|
33
|
+
exports.SEMANTIC_LAYER_HARD_BANS = playbooks.HARD_BANS;
|
|
34
|
+
exports.getAllPlaybookMarkdown = playbooks.getAllPlaybookMarkdown;
|
|
35
|
+
exports.SEMANTIC_LAYER_CORE_PLAYBOOK = playbooks.CORE_PLAYBOOK;
|
|
36
|
+
exports.SEMANTIC_LAYER_TOPIC_PLAYBOOKS = playbooks.TOPIC_PLAYBOOKS;
|
|
37
|
+
function registerSemanticLayerPlaybook(server) {
|
|
38
|
+
playbooks.registerPlaybooks(server);
|
|
39
|
+
}
|
package/dist/personas/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { ToolId } from '../tools/registry.js';
|
|
5
5
|
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
-
export type PersonaId = 'organization-audit' | 'semantic-layer';
|
|
6
|
+
export type PersonaId = 'ai-agent-ops' | 'content-developer' | 'content-governance' | 'content-reader' | 'organization-audit' | 'semantic-layer';
|
|
7
7
|
export type PersonaDefinition = {
|
|
8
8
|
id: PersonaId;
|
|
9
9
|
/** Fixed Streamable HTTP MCP endpoint path for this persona. */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-developer safety policy and registration helper (ADR-0014).
|
|
3
|
+
*
|
|
4
|
+
* Mutation boundary: no warehouse query execution, no row/bulk results; every
|
|
5
|
+
* write is gated behind a validated preview (see `preview-ledger.ts`).
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolHandler, ToolOptions, TextContent } from '../tools/shared.js';
|
|
8
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
9
|
+
declare const MUTABILITY_WRITE_NONDESTRUCTIVE = "write-nondestructive";
|
|
10
|
+
export type DeveloperOperationSafety = {
|
|
11
|
+
mutability: typeof MUTABILITY_WRITE_NONDESTRUCTIVE | 'none' | 'preview';
|
|
12
|
+
queryCapability: 'none';
|
|
13
|
+
resultCapability: 'diff' | 'metadata';
|
|
14
|
+
agentExposure: 'agent';
|
|
15
|
+
};
|
|
16
|
+
/** Discovery / passthrough reads (get_project, search_content, list_spaces, ...). */
|
|
17
|
+
export declare const DISCOVERY_SAFETY: DeveloperOperationSafety;
|
|
18
|
+
/** preview_* — computes a diff and issues a HMAC-signed previewToken (ADR-0019), never persists. */
|
|
19
|
+
export declare const PREVIEW_SAFETY: DeveloperOperationSafety;
|
|
20
|
+
/** validate_* — optional saved-resource health check; never unlocks the preview. */
|
|
21
|
+
export declare const VALIDATE_SAFETY: DeveloperOperationSafety;
|
|
22
|
+
/** compare_*_versions — reads two historical versions and returns a diff, never persists. */
|
|
23
|
+
export declare const COMPARE_SAFETY: DeveloperOperationSafety;
|
|
24
|
+
/** SAFE_WRITE apply tools gated by a validated previewToken. */
|
|
25
|
+
export declare const WRITE_SAFETY: DeveloperOperationSafety;
|
|
26
|
+
/** Throws when a tool violates content-developer capability policy. */
|
|
27
|
+
export declare function assertContentDeveloperSafe(safety: DeveloperOperationSafety): void;
|
|
28
|
+
/** Register a content-developer tool after safety asserts. */
|
|
29
|
+
export declare function registerContentDeveloperTool(server: McpServer, shortName: string, options: Omit<ToolOptions, 'annotations'> & {
|
|
30
|
+
annotations?: ToolOptions['annotations'];
|
|
31
|
+
safety: DeveloperOperationSafety;
|
|
32
|
+
}, handler: ToolHandler): void;
|
|
33
|
+
/** Map ProjectScopeError / PreviewLedgerError to a coded tool error result; rethrow anything else. */
|
|
34
|
+
export declare function developerErrorResult(err: unknown): TextContent;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-developer safety policy and registration helper (ADR-0014).
|
|
4
|
+
*
|
|
5
|
+
* Mutation boundary: no warehouse query execution, no row/bulk results; every
|
|
6
|
+
* write is gated behind a validated preview (see `preview-ledger.ts`).
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WRITE_SAFETY = exports.COMPARE_SAFETY = exports.VALIDATE_SAFETY = exports.PREVIEW_SAFETY = exports.DISCOVERY_SAFETY = void 0;
|
|
10
|
+
exports.assertContentDeveloperSafe = assertContentDeveloperSafe;
|
|
11
|
+
exports.registerContentDeveloperTool = registerContentDeveloperTool;
|
|
12
|
+
exports.developerErrorResult = developerErrorResult;
|
|
13
|
+
const common_1 = require("@lightdash-tools/common");
|
|
14
|
+
const reader_tool_helpers_js_1 = require("../tools/query/reader-tool-helpers.js");
|
|
15
|
+
const shared_js_1 = require("../tools/shared.js");
|
|
16
|
+
const preview_ledger_js_1 = require("./preview-ledger.js");
|
|
17
|
+
const MUTABILITY_WRITE_NONDESTRUCTIVE = 'write-nondestructive';
|
|
18
|
+
/** Discovery / passthrough reads (get_project, search_content, list_spaces, ...). */
|
|
19
|
+
exports.DISCOVERY_SAFETY = {
|
|
20
|
+
mutability: 'none',
|
|
21
|
+
queryCapability: 'none',
|
|
22
|
+
resultCapability: 'metadata',
|
|
23
|
+
agentExposure: 'agent',
|
|
24
|
+
};
|
|
25
|
+
/** preview_* — computes a diff and issues a HMAC-signed previewToken (ADR-0019), never persists. */
|
|
26
|
+
exports.PREVIEW_SAFETY = {
|
|
27
|
+
mutability: 'preview',
|
|
28
|
+
queryCapability: 'none',
|
|
29
|
+
resultCapability: 'diff',
|
|
30
|
+
agentExposure: 'agent',
|
|
31
|
+
};
|
|
32
|
+
/** validate_* — optional saved-resource health check; never unlocks the preview. */
|
|
33
|
+
exports.VALIDATE_SAFETY = {
|
|
34
|
+
mutability: 'none',
|
|
35
|
+
queryCapability: 'none',
|
|
36
|
+
resultCapability: 'metadata',
|
|
37
|
+
agentExposure: 'agent',
|
|
38
|
+
};
|
|
39
|
+
/** compare_*_versions — reads two historical versions and returns a diff, never persists. */
|
|
40
|
+
exports.COMPARE_SAFETY = {
|
|
41
|
+
mutability: 'none',
|
|
42
|
+
queryCapability: 'none',
|
|
43
|
+
resultCapability: 'diff',
|
|
44
|
+
agentExposure: 'agent',
|
|
45
|
+
};
|
|
46
|
+
/** SAFE_WRITE apply tools gated by a validated previewToken. */
|
|
47
|
+
exports.WRITE_SAFETY = {
|
|
48
|
+
mutability: MUTABILITY_WRITE_NONDESTRUCTIVE,
|
|
49
|
+
queryCapability: 'none',
|
|
50
|
+
resultCapability: 'metadata',
|
|
51
|
+
agentExposure: 'agent',
|
|
52
|
+
};
|
|
53
|
+
/** Throws when a tool violates content-developer capability policy. */
|
|
54
|
+
function assertContentDeveloperSafe(safety) {
|
|
55
|
+
if (safety.mutability !== 'none' &&
|
|
56
|
+
safety.mutability !== 'preview' &&
|
|
57
|
+
safety.mutability !== MUTABILITY_WRITE_NONDESTRUCTIVE) {
|
|
58
|
+
throw new Error('content-developer forbids destructive or unbounded mutability');
|
|
59
|
+
}
|
|
60
|
+
if (safety.queryCapability !== 'none') {
|
|
61
|
+
throw new Error('content-developer forbids warehouse query execution');
|
|
62
|
+
}
|
|
63
|
+
if (safety.resultCapability !== 'metadata' && safety.resultCapability !== 'diff') {
|
|
64
|
+
throw new Error('content-developer forbids row-level and bulk results');
|
|
65
|
+
}
|
|
66
|
+
if (safety.agentExposure !== 'agent') {
|
|
67
|
+
throw new Error('Operation is client-only');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Register a content-developer tool after safety asserts. */
|
|
71
|
+
function registerContentDeveloperTool(server, shortName, options, handler) {
|
|
72
|
+
var _a;
|
|
73
|
+
assertContentDeveloperSafe(options.safety);
|
|
74
|
+
const annotations = (_a = options.annotations) !== null && _a !== void 0 ? _a : common_1.READ_ONLY_DEFAULT;
|
|
75
|
+
if ((options.safety.mutability === 'none' || options.safety.mutability === 'preview') &&
|
|
76
|
+
annotations.readOnlyHint !== true) {
|
|
77
|
+
throw new Error(`content-developer requires readOnlyHint for '${shortName}'`);
|
|
78
|
+
}
|
|
79
|
+
if (options.safety.mutability === MUTABILITY_WRITE_NONDESTRUCTIVE &&
|
|
80
|
+
annotations.readOnlyHint === true) {
|
|
81
|
+
throw new Error(`content-developer write tool '${shortName}' must not set readOnlyHint`);
|
|
82
|
+
}
|
|
83
|
+
(0, shared_js_1.registerToolSafe)(server, shortName, Object.assign(Object.assign({}, options), { annotations }), handler);
|
|
84
|
+
}
|
|
85
|
+
/** Map ProjectScopeError / PreviewLedgerError to a coded tool error result; rethrow anything else. */
|
|
86
|
+
function developerErrorResult(err) {
|
|
87
|
+
if (err instanceof preview_ledger_js_1.PreviewLedgerError) {
|
|
88
|
+
return (0, reader_tool_helpers_js_1.codedErrorResult)(err.code, err.message);
|
|
89
|
+
}
|
|
90
|
+
return (0, reader_tool_helpers_js_1.projectScopeErrorResult)(err);
|
|
91
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-developer safety assert + error-mapping unit tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const project_scope_js_1 = require("../governance/project-scope.js");
|
|
8
|
+
const content_developer_js_1 = require("./content-developer.js");
|
|
9
|
+
const preview_ledger_js_1 = require("./preview-ledger.js");
|
|
10
|
+
(0, vitest_1.describe)('assertContentDeveloperSafe', () => {
|
|
11
|
+
(0, vitest_1.it)('accepts all built-in safety presets', () => {
|
|
12
|
+
for (const safety of [
|
|
13
|
+
content_developer_js_1.DISCOVERY_SAFETY,
|
|
14
|
+
content_developer_js_1.PREVIEW_SAFETY,
|
|
15
|
+
content_developer_js_1.VALIDATE_SAFETY,
|
|
16
|
+
content_developer_js_1.COMPARE_SAFETY,
|
|
17
|
+
content_developer_js_1.WRITE_SAFETY,
|
|
18
|
+
]) {
|
|
19
|
+
(0, vitest_1.expect)(() => (0, content_developer_js_1.assertContentDeveloperSafe)(safety)).not.toThrow();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('rejects a non-none query capability', () => {
|
|
23
|
+
(0, vitest_1.expect)(() => (0, content_developer_js_1.assertContentDeveloperSafe)(Object.assign(Object.assign({}, content_developer_js_1.DISCOVERY_SAFETY), { queryCapability: 'sql' }))).toThrow(/warehouse query/);
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('rejects row-level/bulk result capability', () => {
|
|
26
|
+
(0, vitest_1.expect)(() => (0, content_developer_js_1.assertContentDeveloperSafe)(Object.assign(Object.assign({}, content_developer_js_1.DISCOVERY_SAFETY), { resultCapability: 'row_level' }))).toThrow(/row-level/i);
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('rejects client-only exposure', () => {
|
|
29
|
+
(0, vitest_1.expect)(() => (0, content_developer_js_1.assertContentDeveloperSafe)(Object.assign(Object.assign({}, content_developer_js_1.DISCOVERY_SAFETY), { agentExposure: 'client-only' }))).toThrow(/client-only/);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.describe)('developerErrorResult', () => {
|
|
33
|
+
(0, vitest_1.it)('maps ProjectScopeError to a coded blocked result', () => {
|
|
34
|
+
const result = (0, content_developer_js_1.developerErrorResult)(new project_scope_js_1.ProjectScopeError('PROJECT_SCOPE_REQUIRED', 'no project'));
|
|
35
|
+
(0, vitest_1.expect)(result.isError).toBe(true);
|
|
36
|
+
const first = result.content[0];
|
|
37
|
+
(0, vitest_1.expect)(first === null || first === void 0 ? void 0 : first.type).toBe('text');
|
|
38
|
+
if ((first === null || first === void 0 ? void 0 : first.type) === 'text') {
|
|
39
|
+
(0, vitest_1.expect)(first.text).toContain('PROJECT_SCOPE_REQUIRED');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('maps PreviewLedgerError to a coded blocked result', () => {
|
|
43
|
+
const result = (0, content_developer_js_1.developerErrorResult)(new preview_ledger_js_1.PreviewLedgerError('PREVIEW_STALE', 'stale preview'));
|
|
44
|
+
(0, vitest_1.expect)(result.isError).toBe(true);
|
|
45
|
+
const first = result.content[0];
|
|
46
|
+
(0, vitest_1.expect)(first === null || first === void 0 ? void 0 : first.type).toBe('text');
|
|
47
|
+
if ((first === null || first === void 0 ? void 0 : first.type) === 'text') {
|
|
48
|
+
(0, vitest_1.expect)(first.text).toContain('PREVIEW_STALE');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.it)('rethrows unrelated errors', () => {
|
|
52
|
+
(0, vitest_1.expect)(() => (0, content_developer_js_1.developerErrorResult)(new Error('boom'))).toThrow('boom');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-reader safety policy and registration helper (ADR-0012).
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolHandler, ToolOptions } from '../tools/shared.js';
|
|
5
|
+
import type { ToolAnnotations } from '@lightdash-tools/common';
|
|
6
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
7
|
+
export type ReaderOperationSafety = {
|
|
8
|
+
mutability: 'none' | 'transient';
|
|
9
|
+
queryCapability: 'arbitrary_semantic' | 'none' | 'raw_sql' | 'saved_content' | 'underlying_data';
|
|
10
|
+
resultCapability: 'bounded_aggregate_rows' | 'bulk_export' | 'image_snapshot' | 'metadata' | 'row_level';
|
|
11
|
+
usesWarehouse: boolean;
|
|
12
|
+
agentExposure: 'agent' | 'client-only';
|
|
13
|
+
};
|
|
14
|
+
/** Computational read-only (warehouse run) but not idempotent — run/cancel/poll. */
|
|
15
|
+
export declare const SAVED_EXECUTION_ANNOTATIONS: ToolAnnotations;
|
|
16
|
+
/** Headless PNG export — read-only but not idempotent (expensive render). */
|
|
17
|
+
export declare const IMAGE_SNAPSHOT_ANNOTATIONS: ToolAnnotations;
|
|
18
|
+
export declare const METADATA_SAFETY: ReaderOperationSafety;
|
|
19
|
+
export declare const SAVED_EXECUTION_SAFETY: ReaderOperationSafety;
|
|
20
|
+
/** Single saved-chart PNG snapshot via headless export (ADR-0012 carve-out). */
|
|
21
|
+
export declare const IMAGE_SNAPSHOT_SAFETY: ReaderOperationSafety;
|
|
22
|
+
/** Throws when a tool violates content-reader capability policy. */
|
|
23
|
+
export declare function assertContentReaderSafe(safety: ReaderOperationSafety): void;
|
|
24
|
+
/** Register a content-reader tool after safety asserts. */
|
|
25
|
+
export declare function registerContentReaderTool(server: McpServer, shortName: string, options: Omit<ToolOptions, 'annotations'> & {
|
|
26
|
+
annotations?: ToolOptions['annotations'];
|
|
27
|
+
safety: ReaderOperationSafety;
|
|
28
|
+
}, handler: ToolHandler): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-reader safety policy and registration helper (ADR-0012).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IMAGE_SNAPSHOT_SAFETY = exports.SAVED_EXECUTION_SAFETY = exports.METADATA_SAFETY = exports.IMAGE_SNAPSHOT_ANNOTATIONS = exports.SAVED_EXECUTION_ANNOTATIONS = void 0;
|
|
7
|
+
exports.assertContentReaderSafe = assertContentReaderSafe;
|
|
8
|
+
exports.registerContentReaderTool = registerContentReaderTool;
|
|
9
|
+
const common_1 = require("@lightdash-tools/common");
|
|
10
|
+
const shared_js_1 = require("../tools/shared.js");
|
|
11
|
+
/** Computational read-only (warehouse run) but not idempotent — run/cancel/poll. */
|
|
12
|
+
exports.SAVED_EXECUTION_ANNOTATIONS = common_1.READ_ONLY_TRANSIENT;
|
|
13
|
+
/** Headless PNG export — read-only but not idempotent (expensive render). */
|
|
14
|
+
exports.IMAGE_SNAPSHOT_ANNOTATIONS = common_1.READ_ONLY_TRANSIENT;
|
|
15
|
+
exports.METADATA_SAFETY = {
|
|
16
|
+
mutability: 'none',
|
|
17
|
+
queryCapability: 'none',
|
|
18
|
+
resultCapability: 'metadata',
|
|
19
|
+
usesWarehouse: false,
|
|
20
|
+
agentExposure: 'agent',
|
|
21
|
+
};
|
|
22
|
+
exports.SAVED_EXECUTION_SAFETY = {
|
|
23
|
+
mutability: 'transient',
|
|
24
|
+
queryCapability: 'saved_content',
|
|
25
|
+
resultCapability: 'bounded_aggregate_rows',
|
|
26
|
+
usesWarehouse: true,
|
|
27
|
+
agentExposure: 'agent',
|
|
28
|
+
};
|
|
29
|
+
/** Single saved-chart PNG snapshot via headless export (ADR-0012 carve-out). */
|
|
30
|
+
exports.IMAGE_SNAPSHOT_SAFETY = {
|
|
31
|
+
mutability: 'none',
|
|
32
|
+
queryCapability: 'saved_content',
|
|
33
|
+
resultCapability: 'image_snapshot',
|
|
34
|
+
usesWarehouse: true,
|
|
35
|
+
agentExposure: 'agent',
|
|
36
|
+
};
|
|
37
|
+
/** Throws when a tool violates content-reader capability policy. */
|
|
38
|
+
function assertContentReaderSafe(safety) {
|
|
39
|
+
if (safety.mutability !== 'none' && safety.mutability !== 'transient') {
|
|
40
|
+
throw new Error('Persisted mutation is forbidden');
|
|
41
|
+
}
|
|
42
|
+
if (safety.queryCapability !== 'none' && safety.queryCapability !== 'saved_content') {
|
|
43
|
+
throw new Error('Only saved-content queries are allowed');
|
|
44
|
+
}
|
|
45
|
+
if (safety.resultCapability !== 'metadata' &&
|
|
46
|
+
safety.resultCapability !== 'bounded_aggregate_rows' &&
|
|
47
|
+
safety.resultCapability !== 'image_snapshot') {
|
|
48
|
+
throw new Error('Row-level and bulk results are forbidden');
|
|
49
|
+
}
|
|
50
|
+
if (safety.agentExposure !== 'agent') {
|
|
51
|
+
throw new Error('Operation is client-only');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Register a content-reader tool after safety asserts. */
|
|
55
|
+
function registerContentReaderTool(server, shortName, options, handler) {
|
|
56
|
+
var _a;
|
|
57
|
+
const annotations = (_a = options.annotations) !== null && _a !== void 0 ? _a : (options.safety === exports.SAVED_EXECUTION_SAFETY
|
|
58
|
+
? exports.SAVED_EXECUTION_ANNOTATIONS
|
|
59
|
+
: options.safety === exports.IMAGE_SNAPSHOT_SAFETY
|
|
60
|
+
? exports.IMAGE_SNAPSHOT_ANNOTATIONS
|
|
61
|
+
: common_1.READ_ONLY_DEFAULT);
|
|
62
|
+
assertContentReaderSafe(options.safety);
|
|
63
|
+
if (annotations.readOnlyHint !== true) {
|
|
64
|
+
throw new Error(`content-reader requires readOnlyHint for '${shortName}'`);
|
|
65
|
+
}
|
|
66
|
+
(0, shared_js_1.registerToolSafe)(server, shortName, Object.assign(Object.assign({}, options), { annotations }), handler);
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-reader safety assert unit tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const content_reader_js_1 = require("./content-reader.js");
|
|
8
|
+
(0, vitest_1.describe)('assertContentReaderSafe', () => {
|
|
9
|
+
(0, vitest_1.it)('accepts metadata, saved-execution, and image-snapshot presets', () => {
|
|
10
|
+
(0, vitest_1.expect)(() => (0, content_reader_js_1.assertContentReaderSafe)(content_reader_js_1.METADATA_SAFETY)).not.toThrow();
|
|
11
|
+
(0, vitest_1.expect)(() => (0, content_reader_js_1.assertContentReaderSafe)(content_reader_js_1.SAVED_EXECUTION_SAFETY)).not.toThrow();
|
|
12
|
+
(0, vitest_1.expect)(() => (0, content_reader_js_1.assertContentReaderSafe)(content_reader_js_1.IMAGE_SNAPSHOT_SAFETY)).not.toThrow();
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.it)('rejects arbitrary query capability', () => {
|
|
15
|
+
(0, vitest_1.expect)(() => (0, content_reader_js_1.assertContentReaderSafe)(Object.assign(Object.assign({}, content_reader_js_1.METADATA_SAFETY), { queryCapability: 'raw_sql' }))).toThrow(/saved-content/);
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('rejects row-level results', () => {
|
|
18
|
+
(0, vitest_1.expect)(() => (0, content_reader_js_1.assertContentReaderSafe)(Object.assign(Object.assign({}, content_reader_js_1.SAVED_EXECUTION_SAFETY), { resultCapability: 'row_level' }))).toThrow(/Row-level/);
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.it)('rejects client-only exposure', () => {
|
|
21
|
+
(0, vitest_1.expect)(() => (0, content_reader_js_1.assertContentReaderSafe)(Object.assign(Object.assign({}, content_reader_js_1.METADATA_SAFETY), { agentExposure: 'client-only' }))).toThrow(/client-only/);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-reader response envelope helpers (RFC §10).
|
|
3
|
+
*/
|
|
4
|
+
export type ContentReaderWarningCode = 'CACHE_STALE' | 'FILTER_IGNORED' | 'PARAMETER_DEFAULTED' | 'PARTIAL_RESULT' | 'QUERY_RUNNING' | 'QUERY_TIMEOUT' | 'REDACTED' | 'SQL_EXECUTION_DISABLED' | 'STALE_CONTENT' | 'TRUNCATED' | 'UNSUPPORTED_TILE' | 'UNVERIFIED_CONTENT';
|
|
5
|
+
export type ContentReaderWarning = {
|
|
6
|
+
code: ContentReaderWarningCode;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type ContentReaderEnvelope<T> = {
|
|
10
|
+
data: T;
|
|
11
|
+
context: {
|
|
12
|
+
persona: 'content-reader';
|
|
13
|
+
projectUuid: string;
|
|
14
|
+
projectPinned: boolean;
|
|
15
|
+
observedAt: string;
|
|
16
|
+
};
|
|
17
|
+
coverage: {
|
|
18
|
+
complete: boolean;
|
|
19
|
+
truncated: boolean;
|
|
20
|
+
inaccessibleResources: string[];
|
|
21
|
+
};
|
|
22
|
+
warnings: ContentReaderWarning[];
|
|
23
|
+
};
|
|
24
|
+
export declare function contentReaderEnvelope<T>(data: T, opts: {
|
|
25
|
+
projectUuid: string;
|
|
26
|
+
projectPinned: boolean;
|
|
27
|
+
complete?: boolean;
|
|
28
|
+
truncated?: boolean;
|
|
29
|
+
inaccessibleResources?: string[];
|
|
30
|
+
warnings?: ContentReaderWarning[];
|
|
31
|
+
}): ContentReaderEnvelope<T>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content-reader response envelope helpers (RFC §10).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.contentReaderEnvelope = contentReaderEnvelope;
|
|
7
|
+
function contentReaderEnvelope(data, opts) {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
return {
|
|
10
|
+
data,
|
|
11
|
+
context: {
|
|
12
|
+
persona: 'content-reader',
|
|
13
|
+
projectUuid: opts.projectUuid,
|
|
14
|
+
projectPinned: opts.projectPinned,
|
|
15
|
+
observedAt: new Date().toISOString(),
|
|
16
|
+
},
|
|
17
|
+
coverage: {
|
|
18
|
+
complete: (_a = opts.complete) !== null && _a !== void 0 ? _a : true,
|
|
19
|
+
truncated: (_b = opts.truncated) !== null && _b !== void 0 ? _b : false,
|
|
20
|
+
inaccessibleResources: (_c = opts.inaccessibleResources) !== null && _c !== void 0 ? _c : [],
|
|
21
|
+
},
|
|
22
|
+
warnings: (_d = opts.warnings) !== null && _d !== void 0 ? _d : [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|