@lightdash-tools/mcp 0.5.0 → 0.7.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 +133 -58
- package/dist/audit/audit.d.ts +5 -0
- package/dist/{audit.js → audit/audit.js} +1 -2
- package/dist/audit/tool-audit-context.d.ts +6 -0
- package/dist/audit/tool-audit-context.js +12 -0
- package/dist/audit/tool-audit-context.test.d.ts +1 -0
- package/dist/audit/tool-audit-context.test.js +19 -0
- package/dist/auth/auth-mode.d.ts +4 -0
- package/dist/auth/auth-mode.js +6 -0
- package/dist/auth/bearer.d.ts +3 -0
- package/dist/auth/bearer.js +13 -0
- package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
- package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
- package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
- package/dist/auth/oauth-broker/as-metadata.js +20 -0
- package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
- package/dist/auth/oauth-broker/lightdash-token.js +76 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +76 -0
- package/dist/auth/oauth-broker/pending-store.js +124 -0
- package/dist/auth/oauth-broker/pkce.d.ts +2 -0
- package/dist/auth/oauth-broker/pkce.js +17 -0
- package/dist/auth/oauth-broker/routes.d.ts +9 -0
- package/dist/auth/oauth-broker/routes.js +447 -0
- package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
- package/dist/auth/oauth-broker/routes.test.js +237 -0
- package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
- package/dist/auth/providers/bearer-context-provider.js +52 -0
- package/dist/auth/providers/env-context-provider.d.ts +13 -0
- package/dist/auth/providers/env-context-provider.js +19 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
- package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
- package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
- package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
- package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
- package/dist/auth/resource-server/shared-key-middleware.js +24 -0
- package/dist/auth/resource-server/token-scopes.d.ts +15 -0
- package/dist/auth/resource-server/token-scopes.js +76 -0
- package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
- package/dist/auth/resource-server/token-scopes.test.js +51 -0
- package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
- package/dist/auth/resource-server/token-validation-cache.js +44 -0
- package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
- package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
- package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
- package/dist/auth/resource-server/token-validation-error.js +13 -0
- package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
- package/dist/auth/resource-server/www-authenticate.js +24 -0
- package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
- package/dist/auth/resource-server/www-authenticate.test.js +64 -0
- package/dist/auth/token-hash.d.ts +2 -0
- package/dist/auth/token-hash.js +8 -0
- package/dist/bin.d.ts +0 -4
- package/dist/bin.js +41 -33
- package/dist/config/env.d.ts +50 -0
- package/dist/config/env.js +53 -0
- package/dist/config/load-mcp-config.d.ts +30 -0
- package/dist/config/load-mcp-config.js +282 -0
- package/dist/config/load-mcp-config.test.d.ts +1 -0
- package/dist/config/load-mcp-config.test.js +195 -0
- package/dist/config/normalize-url.d.ts +13 -0
- package/dist/config/normalize-url.js +52 -0
- package/dist/config/normalize-url.test.d.ts +1 -0
- package/dist/config/normalize-url.test.js +41 -0
- package/dist/config/public-url.d.ts +3 -0
- package/dist/config/public-url.js +10 -0
- package/dist/config/runtime.d.ts +15 -0
- package/dist/config/runtime.js +48 -0
- package/dist/config/runtime.test.d.ts +1 -0
- package/dist/config/runtime.test.js +69 -0
- package/dist/config/test-mcp-http-config.d.ts +3 -0
- package/dist/config/test-mcp-http-config.js +7 -0
- package/dist/governance/project-pin.d.ts +14 -0
- package/dist/governance/project-pin.js +44 -0
- package/dist/governance/project-pin.test.d.ts +1 -0
- package/dist/governance/project-pin.test.js +35 -0
- package/dist/http.d.ts +1 -2
- package/dist/http.integration.test.d.ts +1 -0
- package/dist/http.integration.test.js +688 -0
- package/dist/http.js +3 -170
- package/dist/http.test.d.ts +4 -0
- package/dist/http.test.js +131 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.integration.test.js +73 -30
- package/dist/index.js +28 -27
- package/dist/index.test.js +3 -3
- package/dist/logging/structured.d.ts +27 -0
- package/dist/logging/structured.js +32 -0
- package/dist/logging/structured.test.d.ts +1 -0
- package/dist/logging/structured.test.js +33 -0
- package/dist/personas/index.d.ts +19 -0
- package/dist/personas/index.js +57 -0
- package/dist/personas/index.test.d.ts +1 -0
- package/dist/personas/index.test.js +58 -0
- package/dist/personas/organization-audit/v1/index.d.ts +8 -0
- package/dist/personas/organization-audit/v1/index.js +42 -0
- package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
- package/dist/personas/organization-audit/v1/prompts.js +111 -0
- package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
- package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
- package/dist/personas/organization-audit/v1/resources/playbook.d.ts +11 -0
- package/dist/personas/organization-audit/v1/resources/playbook.js +40 -0
- package/dist/personas/organization-audit/v1/resources/playbook.md +52 -0
- package/dist/personas/semantic-layer/v1/index.d.ts +8 -0
- package/dist/personas/semantic-layer/v1/index.js +32 -0
- package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
- package/dist/personas/semantic-layer/v1/prompts.js +107 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +12 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.js +42 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.md +153 -0
- package/dist/personas/types.d.ts +19 -0
- package/dist/personas/types.js +5 -0
- package/dist/protocol-contract.test.d.ts +1 -0
- package/dist/protocol-contract.test.js +42 -0
- package/dist/server/capabilities.d.ts +15 -0
- package/dist/server/capabilities.js +19 -0
- package/dist/server/capabilities.test.d.ts +1 -0
- package/dist/server/capabilities.test.js +39 -0
- package/dist/server/errors.test.d.ts +1 -0
- package/dist/server/errors.test.js +53 -0
- package/dist/server/request-context.d.ts +13 -0
- package/dist/server/request-context.js +2 -0
- package/dist/server/server.d.ts +4 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.test.d.ts +1 -0
- package/dist/server/server.test.js +15 -0
- package/dist/server/version.d.ts +1 -0
- package/dist/server/version.js +7 -0
- package/dist/server/version.test.d.ts +1 -0
- package/dist/server/version.test.js +9 -0
- package/dist/stdio.process.test.d.ts +1 -0
- package/dist/stdio.process.test.js +126 -0
- package/dist/tools/index.d.ts +2 -4
- package/dist/tools/index.js +4 -30
- package/dist/tools/index.test.d.ts +1 -0
- package/dist/tools/index.test.js +72 -0
- package/dist/tools/lib/api-errors.d.ts +9 -0
- package/dist/tools/lib/api-errors.js +22 -0
- package/dist/tools/lib/api-shape.d.ts +16 -0
- package/dist/tools/lib/api-shape.js +47 -0
- package/dist/tools/lib/assert-safe.d.ts +13 -0
- package/dist/tools/lib/assert-safe.js +21 -0
- package/dist/tools/lib/assert-safe.test.d.ts +4 -0
- package/dist/tools/lib/assert-safe.test.js +32 -0
- package/dist/tools/lib/concurrency.d.ts +4 -0
- package/dist/tools/lib/concurrency.js +24 -0
- package/dist/tools/lib/contracts.d.ts +34 -0
- package/dist/tools/lib/contracts.js +30 -0
- package/dist/tools/lib/redaction.d.ts +107 -0
- package/dist/tools/lib/redaction.js +299 -0
- package/dist/tools/lib/redaction.test.d.ts +4 -0
- package/dist/tools/lib/redaction.test.js +216 -0
- package/dist/tools/lib/register-org-audit.d.ts +9 -0
- package/dist/tools/lib/register-org-audit.js +20 -0
- package/dist/tools/lib/schema-fields.d.ts +9 -0
- package/dist/tools/lib/schema-fields.js +19 -0
- package/dist/tools/organization/binding.d.ts +14 -0
- package/dist/tools/organization/binding.js +31 -0
- package/dist/tools/organization/invariants.test.d.ts +4 -0
- package/dist/tools/organization/invariants.test.js +28 -0
- package/dist/tools/organization/inventory.d.ts +10 -0
- package/dist/tools/organization/inventory.js +189 -0
- package/dist/tools/organization/roles.d.ts +10 -0
- package/dist/tools/organization/roles.js +213 -0
- package/dist/tools/project/content.d.ts +9 -0
- package/dist/tools/project/content.js +192 -0
- package/dist/tools/project/projects.d.ts +7 -0
- package/dist/tools/project/projects.js +42 -0
- package/dist/tools/project/projects.test.d.ts +1 -0
- package/dist/tools/project/projects.test.js +117 -0
- package/dist/tools/project/schedulers.d.ts +7 -0
- package/dist/tools/project/schedulers.js +115 -0
- package/dist/tools/registry.d.ts +104 -0
- package/dist/tools/registry.js +59 -0
- package/dist/tools/semantic/explore-helpers.d.ts +56 -0
- package/dist/tools/semantic/explore-helpers.js +115 -0
- package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
- package/dist/tools/semantic/explore-helpers.test.js +170 -0
- package/dist/tools/semantic/explores.d.ts +9 -0
- package/dist/tools/semantic/explores.js +80 -0
- package/dist/tools/semantic/metrics.d.ts +7 -0
- package/dist/tools/semantic/metrics.js +53 -0
- package/dist/tools/semantic/query.d.ts +6 -0
- package/dist/tools/semantic/query.js +42 -0
- package/dist/tools/semantic/schema-fields.d.ts +3 -0
- package/dist/tools/semantic/schema-fields.js +7 -0
- package/dist/tools/shared.d.ts +26 -13
- package/dist/tools/shared.js +112 -157
- package/dist/tools/shared.test.js +132 -183
- package/dist/tools/space/access.d.ts +66 -0
- package/dist/tools/space/access.js +322 -0
- package/dist/tools/space/access.test.d.ts +4 -0
- package/dist/tools/space/access.test.js +90 -0
- package/dist/transports/http-body.d.ts +5 -0
- package/dist/transports/http-body.js +50 -0
- package/dist/transports/http-request-utils.d.ts +2 -0
- package/dist/transports/http-request-utils.js +13 -0
- package/dist/transports/http-response.d.ts +6 -0
- package/dist/transports/http-response.js +56 -0
- package/dist/transports/session-store.d.ts +40 -0
- package/dist/transports/session-store.js +88 -0
- package/dist/transports/session-store.test.d.ts +1 -0
- package/dist/transports/session-store.test.js +111 -0
- package/dist/transports/streamable-http.d.ts +9 -0
- package/dist/transports/streamable-http.js +454 -0
- package/dist/transports/streamable-http.test.d.ts +1 -0
- package/dist/transports/streamable-http.test.js +95 -0
- package/package.json +25 -10
- package/dist/audit.d.ts +0 -6
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -82
- package/dist/tools/ai-agents.d.ts +0 -6
- package/dist/tools/ai-agents.js +0 -388
- package/dist/tools/charts.d.ts +0 -6
- package/dist/tools/charts.js +0 -55
- package/dist/tools/content.d.ts +0 -6
- package/dist/tools/content.js +0 -37
- package/dist/tools/dashboards.d.ts +0 -6
- package/dist/tools/dashboards.js +0 -28
- package/dist/tools/explores.d.ts +0 -6
- package/dist/tools/explores.js +0 -65
- package/dist/tools/groups.d.ts +0 -6
- package/dist/tools/groups.js +0 -121
- package/dist/tools/metrics.d.ts +0 -6
- package/dist/tools/metrics.js +0 -45
- package/dist/tools/projects.d.ts +0 -6
- package/dist/tools/projects.js +0 -58
- package/dist/tools/query.d.ts +0 -6
- package/dist/tools/query.js +0 -34
- package/dist/tools/schedulers.d.ts +0 -6
- package/dist/tools/schedulers.js +0 -45
- package/dist/tools/spaces.d.ts +0 -6
- package/dist/tools/spaces.js +0 -128
- package/dist/tools/tags.d.ts +0 -6
- package/dist/tools/tags.js +0 -28
- package/dist/tools/users.d.ts +0 -6
- package/dist/tools/users.js +0 -50
- package/src/audit.ts +0 -6
- package/src/bin.ts +0 -58
- package/src/config.ts +0 -83
- package/src/errors.ts +0 -27
- package/src/http.ts +0 -187
- package/src/index.integration.test.ts +0 -57
- package/src/index.test.ts +0 -8
- package/src/index.ts +0 -31
- package/src/tools/ai-agents.ts +0 -759
- package/src/tools/charts.ts +0 -85
- package/src/tools/content.ts +0 -44
- package/src/tools/dashboards.ts +0 -25
- package/src/tools/explores.ts +0 -98
- package/src/tools/groups.ts +0 -180
- package/src/tools/index.ts +0 -35
- package/src/tools/metrics.ts +0 -42
- package/src/tools/projects.ts +0 -74
- package/src/tools/query.ts +0 -47
- package/src/tools/schedulers.ts +0 -42
- package/src/tools/shared.test.ts +0 -365
- package/src/tools/shared.ts +0 -274
- package/src/tools/spaces.ts +0 -217
- package/src/tools/tags.ts +0 -25
- package/src/tools/users.ts +0 -64
- package/tsconfig.json +0 -13
- /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
- /package/dist/{errors.js → server/errors.js} +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Semantic-layer MCP playbook
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Discover the Lightdash semantic layer and **compose + compile** metric queries. Stop after a good compile (or clear compile errors). Do **not** run warehouse queries or mutate content.
|
|
6
|
+
|
|
7
|
+
## Allowed tools (always `lightdash_` prefix)
|
|
8
|
+
|
|
9
|
+
| Tool | Use for |
|
|
10
|
+
| --------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `lightdash_list_projects` / `lightdash_get_project` | Confirm project UUID ↔ name via `{ data, warnings }` metadata (no warehouse/dbt credentials) |
|
|
12
|
+
| `lightdash_list_explores` | Summaries (`name`, `label`, `tags`, `databaseName`, `schemaName`, `errors?`); **always** pass `search` + `limit` |
|
|
13
|
+
| `lightdash_list_dimensions` | Compact `{ name, label, table, type, fieldId }`; **default = `table === explore.baseTable`** |
|
|
14
|
+
| `lightdash_list_metrics` / `lightdash_get_metric` | Catalog search; **always** filter `tableName === exploreId` client-side |
|
|
15
|
+
| `lightdash_compile_query` | Compile only — never “run” |
|
|
16
|
+
| `lightdash_get_explore` | Use when catalog filter yields **zero** explore-local metrics; extract `tables[baseTable].metrics` only |
|
|
17
|
+
| `lightdash_get_field_lineage` | Optional; summarize, don’t dump |
|
|
18
|
+
|
|
19
|
+
## Hard bans
|
|
20
|
+
|
|
21
|
+
Do **not** attempt or invent: run-query / SQL runner / validation jobs / charts / dashboards / spaces / users / groups / ACL / AI agents / agentops. Those tools are not on this server. Use Lightdash **compile** only (not warehouse execution).
|
|
22
|
+
|
|
23
|
+
## Project scope
|
|
24
|
+
|
|
25
|
+
1. If the user gave a **project UUID**, use it on every tool. Prefer `lightdash_get_project` to confirm the name.
|
|
26
|
+
2. Without an HTTP project pin, `lightdash_list_projects` may return the **entire org** — do **not** switch to another project from that list.
|
|
27
|
+
3. Lightdash **project UUID** ≠ warehouse cloud project. `list_projects` / `get_project` return metadata only (no `warehouseConnection` / `dbtConnection`). Match inventory project/dataset to explore **`databaseName`** / **`schemaName`** from `list_explores`.
|
|
28
|
+
|
|
29
|
+
## From warehouse inventory → explore
|
|
30
|
+
|
|
31
|
+
When the user pastes warehouse inventory (dataset / table / partition field):
|
|
32
|
+
|
|
33
|
+
| Inventory hint | MCP use |
|
|
34
|
+
| ------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
35
|
+
| Dataset (`{dataset}`) | Prefer explores with matching **`schemaName`** |
|
|
36
|
+
| TABLE (`{table}`) | `lightdash_list_explores` **`search`** = that table token; prefer **exact `label` match** |
|
|
37
|
+
| Partition / time field | Candidate **dimension** `fieldId` for time-grain compiles |
|
|
38
|
+
| Full id `project.dataset.table` | `databaseName` ≈ project, `schemaName` ≈ dataset, `label` ≈ table |
|
|
39
|
+
|
|
40
|
+
Warehouse names are **search hints**, not explore IDs. Explore ids are usually compound (often `{project}__{dataset}__{table}`-style); use the explore `name` returned by tools.
|
|
41
|
+
|
|
42
|
+
Some inventory tables have **no** explore. Empty `list_explores` → say so; try a related curated/summary table the user cares about.
|
|
43
|
+
|
|
44
|
+
## Always search explores
|
|
45
|
+
|
|
46
|
+
On large projects, **never** use the default first-N explore list (alphabetical across unrelated domains). Always `search` + `limit`.
|
|
47
|
+
|
|
48
|
+
## Explore disambiguation
|
|
49
|
+
|
|
50
|
+
Search for `{table}` often returns siblings (staging / EDA / reporting variants, and the warehouse table). **Do not pick the first hit.**
|
|
51
|
+
|
|
52
|
+
1. Skip explores with non-empty `errors`.
|
|
53
|
+
2. If the user named a dataset, prefer matching **`schemaName`**. Skip rows with **empty** `schemaName` unless nothing else matches.
|
|
54
|
+
3. Match warehouse table via **exact `label`** = `{table}`, **or** explore **`name`** ending with / containing `__{table}` (labels may be humanized).
|
|
55
|
+
4. Prefer tags such as `lightdash` when still tied.
|
|
56
|
+
5. Deprioritize staging / EDA / reporting-style name prefixes unless the user asked for them.
|
|
57
|
+
6. Duplicate labels with version suffixes: prefer the explore **`name`** without an extra `_vN` unless the user asked for that version.
|
|
58
|
+
7. State chosen explore **`name`**, `label`, and `schemaName` in the answer.
|
|
59
|
+
|
|
60
|
+
## Progressive discovery
|
|
61
|
+
|
|
62
|
+
1. `lightdash_list_explores` with search → disambiguate → note explore id (`name`, `label`, `schemaName`).
|
|
63
|
+
2. `lightdash_list_dimensions` (default: `table === explore.baseTable`, which may differ from explore id) for `fieldId`s. Set `baseTableOnly=false` only if you need joined-table fields (payload grows a lot).
|
|
64
|
+
3. Discover metrics (see below). Prefer **explore-local** metrics on the base table over unrelated catalog hits.
|
|
65
|
+
4. `lightdash_compile_query` with `fieldId`s → verify SQL columns → **stop** (or next insight if the user asked for several).
|
|
66
|
+
|
|
67
|
+
## Metrics: catalog vs explore-local (critical)
|
|
68
|
+
|
|
69
|
+
`lightdash_list_metrics` searches the **org catalog**, not “metrics on this explore”.
|
|
70
|
+
|
|
71
|
+
| Search token | Typical result |
|
|
72
|
+
| ------------------------------ | --------------------------------------------------- |
|
|
73
|
+
| Warehouse table / explore id | **Often zero** hits |
|
|
74
|
+
| Broad domain / entity tokens | Hundreds of **other** tables — flood |
|
|
75
|
+
| Goal keyword from the question | May hit this explore **and** siblings — must filter |
|
|
76
|
+
|
|
77
|
+
Rules:
|
|
78
|
+
|
|
79
|
+
1. Once the explore is known, prefer **`lightdash_get_explore` → `tables[baseTable].metrics` only** for the full local menu (names + labels). Do **not** paste the full explore JSON. Ignore join tables under `tables`.
|
|
80
|
+
2. Optional: keyword `lightdash_list_metrics` for discovery. Response shape `{ pagination, data: Metric[] }`. Keep rows where `tableName` **equals the full explore id**. Table/explore-id search often returns **zero**.
|
|
81
|
+
3. `lightdash_get_metric` `tableName` must be the full explore id. Short warehouse labels → “Metric not found”. Summarize; do not paste huge `availableTimeDimensions` payloads.
|
|
82
|
+
4. Compile metric ids as `{exploreId}_{metricName}` (same pattern as dimension `fieldId`).
|
|
83
|
+
5. Dimension-only (`metrics: []`) is valid for volume-by-time; for “insights” prefer real explore metrics when available.
|
|
84
|
+
|
|
85
|
+
## Dimension shortlist (large explores)
|
|
86
|
+
|
|
87
|
+
Base tables can expose **hundreds** of dimensions (nested structs, event arrays). Do **not** dump the full list.
|
|
88
|
+
|
|
89
|
+
Prefer high-signal fields that appear in `list_dimensions`, by **role**:
|
|
90
|
+
|
|
91
|
+
- Time grains (day / week / month; prefer local timezone grains when both UTC and local exist)
|
|
92
|
+
- Channel / platform / traffic source
|
|
93
|
+
- Segment / demographic / cohort dimensions relevant to the question
|
|
94
|
+
- Core product or entity attributes named in the question
|
|
95
|
+
|
|
96
|
+
Skip nested event dumps and deep struct paths unless the question targets them.
|
|
97
|
+
|
|
98
|
+
## Multi-insight composition (“compose N queries”)
|
|
99
|
+
|
|
100
|
+
When the user asks for several insights on one table/explore:
|
|
101
|
+
|
|
102
|
+
1. Disambiguate explore once; reuse the same `exploreId` and metric shortlist.
|
|
103
|
+
2. Pick **diverse** cuts from available metrics/dims (don’t repeat the same grain N times)—e.g. trend, breakdown by a categorical dim, quality/rate metrics, outcome metrics, acquisition/source—only when those fields exist.
|
|
104
|
+
3. Compile each with `lightdash_compile_query`; verify SELECT columns; present **insight title + metric/dimension fieldIds + compiled SQL** (or errors). Do not paste full dimension/explore payloads.
|
|
105
|
+
4. Metrics that join other tables may produce large CTE SQL — still OK; mention the join briefly.
|
|
106
|
+
|
|
107
|
+
## Field IDs and empty SELECT
|
|
108
|
+
|
|
109
|
+
Prefer `fieldId` from `lightdash_list_dimensions` / `{exploreId}_{metricName}`.
|
|
110
|
+
|
|
111
|
+
Short names alone are unsafe:
|
|
112
|
+
|
|
113
|
+
1. Upstream may “succeed” with an **empty `SELECT`** — this server returns **`isError`**. Fix to `fieldId`s and re-compile once.
|
|
114
|
+
2. Or hard-error on unknown field id.
|
|
115
|
+
|
|
116
|
+
Compiled SQL may include **extra related metrics** the semantic layer pulls in — verify columns against the goal; unexpected helpers can be OK if the requested fields are present.
|
|
117
|
+
|
|
118
|
+
## Field lineage
|
|
119
|
+
|
|
120
|
+
`lightdash_get_field_lineage` accepts full `fieldId` or short `name`. Summarize; do not paste the full graph.
|
|
121
|
+
|
|
122
|
+
## Answer shape
|
|
123
|
+
|
|
124
|
+
Shortlists only: explore `name` / `label` / `schemaName` / why chosen; metric/dimension names + `fieldId`; compiled SQL or compile errors. Never paste full `get_explore`, full dimension arrays, full `get_metric`, or full lineage JSON.
|
|
125
|
+
|
|
126
|
+
## metricQuery skeleton
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"exploreName": "{exploreId}",
|
|
131
|
+
"dimensions": ["{exploreId}_{dim}"],
|
|
132
|
+
"metrics": ["{exploreId}_{metric}"],
|
|
133
|
+
"filters": {},
|
|
134
|
+
"sorts": [{ "fieldId": "{exploreId}_{dim}", "descending": false }],
|
|
135
|
+
"limit": 50,
|
|
136
|
+
"tableCalculations": []
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`metrics` may be `[]`.
|
|
141
|
+
|
|
142
|
+
## Recommended sequence
|
|
143
|
+
|
|
144
|
+
1. Scope: `lightdash_get_project` with the user-given project UUID (do not switch from an org-wide list)
|
|
145
|
+
2. Discover: search explores → disambiguate → base-table dimensions (shortlist) + explore-local metrics (`get_explore` metrics map; catalog keyword optional)
|
|
146
|
+
3. `lightdash_compile_query` with `fieldId`s (repeat for multi-insight)
|
|
147
|
+
4. Verify SELECT columns; stop
|
|
148
|
+
|
|
149
|
+
## Stop / deliverables
|
|
150
|
+
|
|
151
|
+
- **Explore prompt:** shortlist only — do not compile unless asked.
|
|
152
|
+
- **Compose / debug:** compiled SQL or errors; stop after a good compile (re-compile only while debugging).
|
|
153
|
+
- **Multi-insight:** N titled queries with fieldIds + SQL; one explore resolution shared across them.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persona type definitions (tools selected from shared registry).
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolId } from '../tools/registry.js';
|
|
5
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
|
+
export type PersonaId = 'organization-audit' | 'semantic-layer';
|
|
7
|
+
export type PersonaDefinition = {
|
|
8
|
+
id: PersonaId;
|
|
9
|
+
/** Fixed Streamable HTTP MCP endpoint path for this persona. */
|
|
10
|
+
path: `/${string}`;
|
|
11
|
+
/**
|
|
12
|
+
* MCP server display name. Defaults to `lightdash-mcp-${id}`.
|
|
13
|
+
* Use a shorter name when combined with `lightdash_*` tools would exceed ~60 chars.
|
|
14
|
+
*/
|
|
15
|
+
serverName?: string;
|
|
16
|
+
toolIds: readonly ToolId[];
|
|
17
|
+
registerPrompts: (server: McpServer) => void;
|
|
18
|
+
registerResources: (server: McpServer) => void;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* In-memory protocol contract: createLightdashMcpServer + Client via InMemoryTransport.
|
|
5
|
+
* No Lightdash network calls — stub McpContextProvider only.
|
|
6
|
+
*/
|
|
7
|
+
const client_1 = require("@modelcontextprotocol/client");
|
|
8
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
9
|
+
const vitest_1 = require("vitest");
|
|
10
|
+
const server_js_1 = require("./server/server.js");
|
|
11
|
+
const shared_js_1 = require("./tools/shared.js");
|
|
12
|
+
function createStubContextProvider() {
|
|
13
|
+
return {
|
|
14
|
+
getContext: async () => ({
|
|
15
|
+
lightdashClient: {},
|
|
16
|
+
auth: { mode: 'env' },
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
(0, vitest_1.describe)('MCP protocol contract (InMemoryTransport)', () => {
|
|
21
|
+
let server;
|
|
22
|
+
let mcpClient;
|
|
23
|
+
(0, vitest_1.afterEach)(async () => {
|
|
24
|
+
await (mcpClient === null || mcpClient === void 0 ? void 0 : mcpClient.close().catch(() => undefined));
|
|
25
|
+
await (server === null || server === void 0 ? void 0 : server.close().catch(() => undefined));
|
|
26
|
+
mcpClient = undefined;
|
|
27
|
+
server = undefined;
|
|
28
|
+
});
|
|
29
|
+
(0, vitest_1.it)('initialize and tools/list expose lightdash_ tools including list_projects', async () => {
|
|
30
|
+
const contextProvider = createStubContextProvider();
|
|
31
|
+
server = (0, server_js_1.createLightdashMcpServer)(contextProvider);
|
|
32
|
+
const [serverTransport, clientTransport] = server_1.InMemoryTransport.createLinkedPair();
|
|
33
|
+
await server.connect(serverTransport);
|
|
34
|
+
mcpClient = new client_1.Client({ name: 'protocol-contract-test', version: '0.0.0' });
|
|
35
|
+
await mcpClient.connect(clientTransport);
|
|
36
|
+
const { tools } = await mcpClient.listTools();
|
|
37
|
+
(0, vitest_1.expect)(tools).toHaveLength(9);
|
|
38
|
+
(0, vitest_1.expect)(tools.every((t) => t.name.startsWith(shared_js_1.TOOL_PREFIX))).toBe(true);
|
|
39
|
+
(0, vitest_1.expect)(tools.some((t) => t.name === `${shared_js_1.TOOL_PREFIX}list_projects`)).toBe(true);
|
|
40
|
+
(0, vitest_1.expect)(tools.some((t) => t.name === `${shared_js_1.TOOL_PREFIX}compile_query`)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register tools / prompts / resources for a persona.
|
|
3
|
+
*/
|
|
4
|
+
import type { McpContextProvider } from './request-context.js';
|
|
5
|
+
import type { PersonaDefinition } from '../personas/types.js';
|
|
6
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
7
|
+
export type RegisterCapabilitiesOptions = {
|
|
8
|
+
/** Persona to register (defaults to the sole shipped persona). */
|
|
9
|
+
persona?: PersonaDefinition;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Registers MCP capabilities for the given persona.
|
|
13
|
+
* Tools come from the shared registry via persona.toolIds.
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerCapabilities(server: McpServer, contextProvider: McpContextProvider, options?: RegisterCapabilitiesOptions): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Register tools / prompts / resources for a persona.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerCapabilities = registerCapabilities;
|
|
7
|
+
const index_js_1 = require("../personas/index.js");
|
|
8
|
+
const registry_js_1 = require("../tools/registry.js");
|
|
9
|
+
/**
|
|
10
|
+
* Registers MCP capabilities for the given persona.
|
|
11
|
+
* Tools come from the shared registry via persona.toolIds.
|
|
12
|
+
*/
|
|
13
|
+
function registerCapabilities(server, contextProvider, options) {
|
|
14
|
+
var _a;
|
|
15
|
+
const persona = (_a = options === null || options === void 0 ? void 0 : options.persona) !== null && _a !== void 0 ? _a : (0, index_js_1.getDefaultPersona)();
|
|
16
|
+
(0, registry_js_1.registerToolsByIds)(server, contextProvider, persona.toolIds);
|
|
17
|
+
persona.registerPrompts(server);
|
|
18
|
+
persona.registerResources(server);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const index_js_1 = require("../personas/index.js");
|
|
6
|
+
const registry_js_1 = require("../tools/registry.js");
|
|
7
|
+
const capabilities_js_1 = require("./capabilities.js");
|
|
8
|
+
vitest_1.vi.mock('../tools/registry.js', async (importOriginal) => {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- vitest importOriginal
|
|
10
|
+
const actual = await importOriginal();
|
|
11
|
+
return Object.assign(Object.assign({}, actual), { registerToolsByIds: vitest_1.vi.fn() });
|
|
12
|
+
});
|
|
13
|
+
function createMockContextProvider(lightdashClient = {}) {
|
|
14
|
+
return {
|
|
15
|
+
getContext: async () => ({
|
|
16
|
+
lightdashClient: lightdashClient,
|
|
17
|
+
auth: { mode: 'env' },
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
(0, vitest_1.describe)('registerCapabilities', () => {
|
|
22
|
+
const mockContextProvider = createMockContextProvider();
|
|
23
|
+
let server;
|
|
24
|
+
let registerPromptSpy;
|
|
25
|
+
let registerResourceSpy;
|
|
26
|
+
(0, vitest_1.beforeEach)(() => {
|
|
27
|
+
server = new server_1.McpServer({ name: 'test', version: '0.0.0' });
|
|
28
|
+
registerPromptSpy = vitest_1.vi.spyOn(server, 'registerPrompt');
|
|
29
|
+
registerResourceSpy = vitest_1.vi.spyOn(server, 'registerResource');
|
|
30
|
+
vitest_1.vi.mocked(registry_js_1.registerToolsByIds).mockClear();
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('registers persona tool allowlist and prompts/resources', () => {
|
|
33
|
+
const persona = (0, index_js_1.getDefaultPersona)();
|
|
34
|
+
(0, capabilities_js_1.registerCapabilities)(server, mockContextProvider, { persona });
|
|
35
|
+
(0, vitest_1.expect)(registry_js_1.registerToolsByIds).toHaveBeenCalledWith(server, mockContextProvider, persona.toolIds);
|
|
36
|
+
(0, vitest_1.expect)(registerPromptSpy).toHaveBeenCalled();
|
|
37
|
+
(0, vitest_1.expect)(registerResourceSpy).toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@lightdash-tools/client");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const mockRequest = { method: 'GET', url: '/api/v1/test' };
|
|
7
|
+
(0, vitest_1.describe)('toMcpErrorMessage', () => {
|
|
8
|
+
(0, vitest_1.describe)('RateLimitError', () => {
|
|
9
|
+
(0, vitest_1.it)('should include status code and retry-after when present', () => {
|
|
10
|
+
const err = new client_1.RateLimitError(429, { name: 'TooManyRequests', statusCode: 429 }, mockRequest, undefined, 60);
|
|
11
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(err)).toBe('Rate limited (429). Retry after 60s.');
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.it)('should omit retry-after when not present', () => {
|
|
14
|
+
const err = new client_1.RateLimitError(429, { name: 'TooManyRequests', statusCode: 429 }, mockRequest);
|
|
15
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(err)).toBe('Rate limited (429).');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.describe)('LightdashApiError', () => {
|
|
19
|
+
(0, vitest_1.it)('should include API error message when present', () => {
|
|
20
|
+
const err = new client_1.LightdashApiError(400, { name: 'BadRequest', statusCode: 400, message: 'Invalid input' }, mockRequest);
|
|
21
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(err)).toBe('Lightdash API error: Invalid input');
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)('should fall back to HTTP status when message is missing', () => {
|
|
24
|
+
const err = new client_1.LightdashApiError(500, { name: 'InternalError', statusCode: 500 }, mockRequest);
|
|
25
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(err)).toBe('Lightdash API error: HTTP 500');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.describe)('NetworkError', () => {
|
|
29
|
+
(0, vitest_1.it)('should prefix network error message', () => {
|
|
30
|
+
const err = new client_1.NetworkError('Connection refused', new Error('ECONNREFUSED'));
|
|
31
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(err)).toBe('Network error: Connection refused');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.describe)('generic Error', () => {
|
|
35
|
+
(0, vitest_1.it)('should return error message', () => {
|
|
36
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(new Error('something went wrong'))).toBe('something went wrong');
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.it)('should return "Unknown error" when message is empty', () => {
|
|
39
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(new Error(''))).toBe('Unknown error');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.describe)('non-Error values', () => {
|
|
43
|
+
(0, vitest_1.it)('should stringify string values', () => {
|
|
44
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)('plain string')).toBe('plain string');
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('should stringify number values', () => {
|
|
47
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(42)).toBe('42');
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('should stringify null', () => {
|
|
50
|
+
(0, vitest_1.expect)((0, errors_js_1.toMcpErrorMessage)(null)).toBe('null');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { McpAuthMode } from '../auth/auth-mode.js';
|
|
2
|
+
import type { LightdashClient } from '@lightdash-tools/client';
|
|
3
|
+
export interface LightdashMcpRequestContext {
|
|
4
|
+
lightdashClient: LightdashClient;
|
|
5
|
+
auth: {
|
|
6
|
+
mode: McpAuthMode;
|
|
7
|
+
subject?: string;
|
|
8
|
+
tokenHash?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface McpContextProvider<TExtra = unknown> {
|
|
12
|
+
getContext(extra?: TExtra): Promise<LightdashMcpRequestContext>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { RegisterCapabilitiesOptions } from './capabilities.js';
|
|
3
|
+
import type { McpContextProvider } from './request-context.js';
|
|
4
|
+
export declare function createLightdashMcpServer(contextProvider: McpContextProvider, options?: RegisterCapabilitiesOptions): McpServer;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLightdashMcpServer = createLightdashMcpServer;
|
|
4
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
5
|
+
const index_js_1 = require("../personas/index.js");
|
|
6
|
+
const capabilities_js_1 = require("./capabilities.js");
|
|
7
|
+
const version_js_1 = require("./version.js");
|
|
8
|
+
function createLightdashMcpServer(contextProvider, options) {
|
|
9
|
+
var _a;
|
|
10
|
+
const persona = (_a = options === null || options === void 0 ? void 0 : options.persona) !== null && _a !== void 0 ? _a : (0, index_js_1.getDefaultPersona)();
|
|
11
|
+
const server = new server_1.McpServer({
|
|
12
|
+
name: (0, index_js_1.getPersonaServerName)(persona),
|
|
13
|
+
version: version_js_1.PACKAGE_VERSION,
|
|
14
|
+
});
|
|
15
|
+
(0, capabilities_js_1.registerCapabilities)(server, contextProvider, Object.assign(Object.assign({}, options), { persona }));
|
|
16
|
+
return server;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const server_js_1 = require("./server.js");
|
|
5
|
+
const version_js_1 = require("./version.js");
|
|
6
|
+
(0, vitest_1.describe)('createLightdashMcpServer', () => {
|
|
7
|
+
(0, vitest_1.it)('creates server with package version', () => {
|
|
8
|
+
const contextProvider = {
|
|
9
|
+
getContext: async () => ({ lightdashClient: {} }),
|
|
10
|
+
};
|
|
11
|
+
const server = (0, server_js_1.createLightdashMcpServer)(contextProvider);
|
|
12
|
+
(0, vitest_1.expect)(server).toBeDefined();
|
|
13
|
+
(0, vitest_1.expect)(version_js_1.PACKAGE_VERSION).toBeTruthy();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PACKAGE_VERSION: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PACKAGE_VERSION = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const pkgRequire = (0, node_module_1.createRequire)(__filename);
|
|
6
|
+
const { version } = pkgRequire('../../package.json');
|
|
7
|
+
exports.PACKAGE_VERSION = version;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const version_js_1 = require("./version.js");
|
|
5
|
+
(0, vitest_1.describe)('PACKAGE_VERSION', () => {
|
|
6
|
+
(0, vitest_1.it)('matches semantic version pattern', () => {
|
|
7
|
+
(0, vitest_1.expect)(version_js_1.PACKAGE_VERSION).toMatch(/^\d+\.\d+\.\d+$/);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Process-level stdio smoke: spawn dist/bin.js, initialize, tools/list.
|
|
8
|
+
* Exercises the real MCP SDK transport — no SDK mocks. Avoids Lightdash network calls.
|
|
9
|
+
*/
|
|
10
|
+
const node_child_process_1 = require("node:child_process");
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const vitest_1 = require("vitest");
|
|
13
|
+
/** Vitest runs from the monorepo root (`vitest.config.ts`). */
|
|
14
|
+
const repoRoot = process.cwd();
|
|
15
|
+
const binPath = node_path_1.default.join(repoRoot, 'packages/mcp/dist/bin.js');
|
|
16
|
+
const INIT_TIMEOUT_MS = 5000;
|
|
17
|
+
function writeLine(child, message) {
|
|
18
|
+
child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
19
|
+
}
|
|
20
|
+
async function readJsonRpcResponse(child, expectedId, timeoutMs, getStderr) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
let buffer = '';
|
|
23
|
+
const timer = setTimeout(() => {
|
|
24
|
+
cleanup();
|
|
25
|
+
reject(new Error(`Timed out waiting for JSON-RPC response id=${expectedId}`));
|
|
26
|
+
}, timeoutMs);
|
|
27
|
+
const onData = (chunk) => {
|
|
28
|
+
var _a;
|
|
29
|
+
buffer += chunk.toString('utf8');
|
|
30
|
+
const lines = buffer.split('\n');
|
|
31
|
+
buffer = (_a = lines.pop()) !== null && _a !== void 0 ? _a : '';
|
|
32
|
+
for (const line of lines) {
|
|
33
|
+
const trimmed = line.trim();
|
|
34
|
+
if (!trimmed || !trimmed.startsWith('{'))
|
|
35
|
+
continue;
|
|
36
|
+
let msg;
|
|
37
|
+
try {
|
|
38
|
+
msg = JSON.parse(trimmed);
|
|
39
|
+
}
|
|
40
|
+
catch (_b) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (msg.id === expectedId) {
|
|
44
|
+
cleanup();
|
|
45
|
+
resolve(msg);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const onExit = (code) => {
|
|
51
|
+
cleanup();
|
|
52
|
+
const stderr = getStderr().trim();
|
|
53
|
+
const suffix = stderr ? `\nstderr:\n${stderr}` : '';
|
|
54
|
+
reject(new Error(`MCP process exited early (code=${code}) before response id=${expectedId}${suffix}`));
|
|
55
|
+
};
|
|
56
|
+
const cleanup = () => {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
child.stdout.off('data', onData);
|
|
59
|
+
child.off('exit', onExit);
|
|
60
|
+
};
|
|
61
|
+
child.stdout.on('data', onData);
|
|
62
|
+
child.once('exit', onExit);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function killChild(child) {
|
|
66
|
+
if (!child || child.killed)
|
|
67
|
+
return;
|
|
68
|
+
child.kill('SIGTERM');
|
|
69
|
+
}
|
|
70
|
+
(0, vitest_1.describe)('stdio process smoke', () => {
|
|
71
|
+
let child;
|
|
72
|
+
(0, vitest_1.afterEach)(() => {
|
|
73
|
+
killChild(child);
|
|
74
|
+
child = undefined;
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('initialize then tools/list over stdio', async () => {
|
|
77
|
+
var _a;
|
|
78
|
+
let stderr = '';
|
|
79
|
+
child = (0, node_child_process_1.spawn)(process.execPath, [binPath], {
|
|
80
|
+
cwd: repoRoot,
|
|
81
|
+
env: Object.assign(Object.assign({}, process.env), { LIGHTDASH_URL: 'https://app.lightdash.cloud', LIGHTDASH_API_KEY: 'dummy-key-for-stdio-smoke', LIGHTDASH_TOOLS_MCP_STDIO_PERSONA: 'semantic-layer',
|
|
82
|
+
// Avoid inheriting real credentials or network-affecting settings.
|
|
83
|
+
LIGHTDASH_TOOLS_AUDIT_LOG: undefined }),
|
|
84
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
85
|
+
});
|
|
86
|
+
// Drain stderr so the child cannot block on a full pipe and preserve it for failures.
|
|
87
|
+
child.stderr.setEncoding('utf8');
|
|
88
|
+
child.stderr.on('data', (chunk) => {
|
|
89
|
+
stderr += chunk;
|
|
90
|
+
});
|
|
91
|
+
writeLine(child, {
|
|
92
|
+
jsonrpc: '2.0',
|
|
93
|
+
id: 1,
|
|
94
|
+
method: 'initialize',
|
|
95
|
+
params: {
|
|
96
|
+
protocolVersion: '2024-11-05',
|
|
97
|
+
capabilities: {},
|
|
98
|
+
clientInfo: { name: 'stdio-process-smoke', version: '0.0.0' },
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const initResponse = await readJsonRpcResponse(child, 1, INIT_TIMEOUT_MS, () => stderr);
|
|
102
|
+
(0, vitest_1.expect)(initResponse.error).toBeUndefined();
|
|
103
|
+
(0, vitest_1.expect)(initResponse.result).toBeDefined();
|
|
104
|
+
const initResult = initResponse.result;
|
|
105
|
+
(0, vitest_1.expect)((_a = initResult.serverInfo) === null || _a === void 0 ? void 0 : _a.name).toBe('lightdash-mcp-semantic-layer');
|
|
106
|
+
(0, vitest_1.expect)(initResult.protocolVersion).toBeTruthy();
|
|
107
|
+
writeLine(child, {
|
|
108
|
+
jsonrpc: '2.0',
|
|
109
|
+
method: 'notifications/initialized',
|
|
110
|
+
});
|
|
111
|
+
writeLine(child, {
|
|
112
|
+
jsonrpc: '2.0',
|
|
113
|
+
id: 2,
|
|
114
|
+
method: 'tools/list',
|
|
115
|
+
params: {},
|
|
116
|
+
});
|
|
117
|
+
const listResponse = await readJsonRpcResponse(child, 2, INIT_TIMEOUT_MS, () => stderr);
|
|
118
|
+
(0, vitest_1.expect)(listResponse.error).toBeUndefined();
|
|
119
|
+
const listResult = listResponse.result;
|
|
120
|
+
(0, vitest_1.expect)(Array.isArray(listResult.tools)).toBe(true);
|
|
121
|
+
(0, vitest_1.expect)(listResult.tools.length).toBeGreaterThan(0);
|
|
122
|
+
(0, vitest_1.expect)(listResult.tools.some((t) => t.name === 'lightdash_list_projects')).toBe(true);
|
|
123
|
+
killChild(child);
|
|
124
|
+
child = undefined;
|
|
125
|
+
});
|
|
126
|
+
});
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Tool registration: shared registry only (personas select via registerToolsByIds).
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
import type { LightdashClient } from '@lightdash-tools/client';
|
|
6
|
-
export declare function registerTools(server: McpServer, client: LightdashClient): void;
|
|
4
|
+
export { registerToolsByIds } from './registry.js';
|
package/dist/tools/index.js
CHANGED
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Tool registration: shared registry only (personas select via registerToolsByIds).
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const dashboards_js_1 = require("./dashboards.js");
|
|
10
|
-
const spaces_js_1 = require("./spaces.js");
|
|
11
|
-
const users_js_1 = require("./users.js");
|
|
12
|
-
const groups_js_1 = require("./groups.js");
|
|
13
|
-
const query_js_1 = require("./query.js");
|
|
14
|
-
const explores_js_1 = require("./explores.js");
|
|
15
|
-
const metrics_js_1 = require("./metrics.js");
|
|
16
|
-
const schedulers_js_1 = require("./schedulers.js");
|
|
17
|
-
const tags_js_1 = require("./tags.js");
|
|
18
|
-
const content_js_1 = require("./content.js");
|
|
19
|
-
const ai_agents_js_1 = require("./ai-agents.js");
|
|
20
|
-
function registerTools(server, client) {
|
|
21
|
-
(0, projects_js_1.registerProjectTools)(server, client);
|
|
22
|
-
(0, charts_js_1.registerChartTools)(server, client);
|
|
23
|
-
(0, dashboards_js_1.registerDashboardTools)(server, client);
|
|
24
|
-
(0, spaces_js_1.registerSpaceTools)(server, client);
|
|
25
|
-
(0, users_js_1.registerUserTools)(server, client);
|
|
26
|
-
(0, groups_js_1.registerGroupTools)(server, client);
|
|
27
|
-
(0, query_js_1.registerQueryTools)(server, client);
|
|
28
|
-
(0, explores_js_1.registerExploresTools)(server, client);
|
|
29
|
-
(0, metrics_js_1.registerMetricsTools)(server, client);
|
|
30
|
-
(0, schedulers_js_1.registerSchedulersTools)(server, client);
|
|
31
|
-
(0, tags_js_1.registerTagsTools)(server, client);
|
|
32
|
-
(0, content_js_1.registerContentTools)(server, client);
|
|
33
|
-
(0, ai_agents_js_1.registerAiAgentTools)(server, client);
|
|
34
|
-
}
|
|
6
|
+
exports.registerToolsByIds = void 0;
|
|
7
|
+
var registry_js_1 = require("./registry.js");
|
|
8
|
+
Object.defineProperty(exports, "registerToolsByIds", { enumerable: true, get: function () { return registry_js_1.registerToolsByIds; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|