@lightdash-tools/mcp 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +108 -237
  2. package/dist/audit/server-persona.d.ts +10 -0
  3. package/dist/audit/server-persona.js +19 -0
  4. package/dist/auth/oauth-broker/pending-store.d.ts +6 -7
  5. package/dist/auth/oauth-broker/pending-store.js +3 -4
  6. package/dist/auth/oauth-broker/pending-store.test.d.ts +2 -3
  7. package/dist/auth/oauth-broker/pending-store.test.js +2 -39
  8. package/dist/auth/oauth-broker/routes.d.ts +1 -1
  9. package/dist/auth/oauth-broker/routes.js +3 -3
  10. package/dist/auth/oauth-broker/routes.test.js +1 -1
  11. package/dist/auth/request-state-key.d.ts +19 -0
  12. package/dist/auth/request-state-key.js +49 -0
  13. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +0 -2
  14. package/dist/auth/resource-server/lightdash-oauth-middleware.js +0 -19
  15. package/dist/auth/resource-server/www-authenticate.test.js +0 -2
  16. package/dist/bin.js +9 -2
  17. package/dist/config/env.d.ts +5 -15
  18. package/dist/config/env.js +6 -16
  19. package/dist/config/load-mcp-config.d.ts +0 -4
  20. package/dist/config/load-mcp-config.js +8 -9
  21. package/dist/config/normalize-url.test.js +14 -11
  22. package/dist/config/runtime.d.ts +3 -3
  23. package/dist/config/runtime.js +19 -23
  24. package/dist/config/runtime.test.js +23 -9
  25. package/dist/config/test-mcp-http-config.js +1 -1
  26. package/dist/destructive/content-promote.js +7 -1
  27. package/dist/destructive/promote-contract.test.js +106 -47
  28. package/dist/destructive/register-destructive-tool.js +6 -24
  29. package/dist/destructive/request-state.d.ts +2 -6
  30. package/dist/destructive/request-state.js +3 -38
  31. package/dist/destructive/types.d.ts +2 -1
  32. package/dist/governance/available-projects.d.ts +37 -0
  33. package/dist/governance/available-projects.js +132 -0
  34. package/dist/governance/available-projects.test.d.ts +4 -0
  35. package/dist/governance/available-projects.test.js +107 -0
  36. package/dist/governance/client-capabilities-cache.d.ts +44 -0
  37. package/dist/governance/client-capabilities-cache.js +142 -0
  38. package/dist/governance/client-capabilities-cache.test.js +148 -0
  39. package/dist/governance/mcp-client-session.d.ts +3 -2
  40. package/dist/governance/mcp-client-session.js +3 -2
  41. package/dist/governance/project-scope.d.ts +8 -22
  42. package/dist/governance/project-scope.js +36 -44
  43. package/dist/governance/project-scope.test.d.ts +1 -1
  44. package/dist/governance/project-scope.test.js +21 -44
  45. package/dist/governance/promote-allowlist.d.ts +18 -0
  46. package/dist/governance/promote-allowlist.js +66 -0
  47. package/dist/governance/promote-allowlist.test.d.ts +4 -0
  48. package/dist/governance/promote-allowlist.test.js +87 -0
  49. package/dist/http.integration.test.js +117 -262
  50. package/dist/http.test.js +0 -12
  51. package/dist/index.integration.test.js +0 -4
  52. package/dist/index.js +3 -1
  53. package/dist/personas/ai-agent-ops/v1/index.d.ts +8 -0
  54. package/dist/personas/ai-agent-ops/v1/index.js +41 -0
  55. package/dist/personas/ai-agent-ops/v1/prompts.d.ts +5 -0
  56. package/dist/personas/ai-agent-ops/v1/prompts.js +141 -0
  57. package/dist/personas/ai-agent-ops/v1/prompts.test.d.ts +4 -0
  58. package/dist/personas/ai-agent-ops/v1/prompts.test.js +26 -0
  59. package/dist/personas/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
  60. package/dist/personas/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
  61. package/dist/personas/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
  62. package/dist/personas/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
  63. package/dist/personas/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
  64. package/dist/personas/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
  65. package/dist/personas/ai-agent-ops/v1/resources/playbooks.js +41 -0
  66. package/dist/personas/content-developer/v1/index.d.ts +1 -1
  67. package/dist/personas/content-developer/v1/index.js +1 -0
  68. package/dist/personas/content-developer/v1/prompts.d.ts +3 -0
  69. package/dist/personas/content-developer/v1/prompts.js +80 -61
  70. package/dist/personas/content-developer/v1/prompts.test.js +159 -3
  71. package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
  72. package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +13 -6
  73. package/dist/personas/content-developer/v1/resources/playbooks/core.md +91 -49
  74. package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
  75. package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +82 -34
  76. package/dist/personas/content-developer/v1/resources/playbooks/index.md +9 -7
  77. package/dist/personas/content-developer/v1/resources/playbooks.d.ts +1 -1
  78. package/dist/personas/content-developer/v1/resources/playbooks.js +29 -10
  79. package/dist/personas/content-governance/v1/resources/playbooks/core.md +1 -1
  80. package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +1 -1
  81. package/dist/personas/content-reader/v1/index.d.ts +1 -1
  82. package/dist/personas/content-reader/v1/index.js +1 -0
  83. package/dist/personas/content-reader/v1/prompts.js +64 -30
  84. package/dist/personas/content-reader/v1/resources/playbooks/compare.md +24 -9
  85. package/dist/personas/content-reader/v1/resources/playbooks/core.md +56 -29
  86. package/dist/personas/content-reader/v1/resources/playbooks/discover.md +27 -5
  87. package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +38 -8
  88. package/dist/personas/content-reader/v1/resources/playbooks/index.md +8 -8
  89. package/dist/personas/content-reader/v1/resources/playbooks.js +2 -2
  90. package/dist/personas/index.d.ts +1 -0
  91. package/dist/personas/index.js +27 -22
  92. package/dist/personas/index.test.js +68 -53
  93. package/dist/personas/lib/playbook-resources.d.ts +4 -3
  94. package/dist/personas/lib/playbook-resources.js +14 -10
  95. package/dist/personas/organization-audit/v1/prompts.js +68 -36
  96. package/dist/personas/organization-audit/v1/resources/playbooks/access.md +12 -4
  97. package/dist/personas/organization-audit/v1/resources/playbooks/content.md +13 -3
  98. package/dist/personas/organization-audit/v1/resources/playbooks/core.md +49 -16
  99. package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +8 -3
  100. package/dist/personas/organization-audit/v1/resources/playbooks/index.md +8 -8
  101. package/dist/personas/organization-audit/v1/resources/playbooks.js +1 -1
  102. package/dist/personas/persona.parity.test.js +14 -10
  103. package/dist/personas/semantic-layer/v1/prompts.js +50 -39
  104. package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +36 -31
  105. package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +53 -21
  106. package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +42 -39
  107. package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +6 -6
  108. package/dist/personas/semantic-layer/v1/resources/playbooks.js +2 -2
  109. package/dist/personas/types.d.ts +1 -1
  110. package/dist/policy/content-developer.d.ts +3 -3
  111. package/dist/policy/content-developer.js +3 -3
  112. package/dist/policy/content-developer.test.js +10 -4
  113. package/dist/policy/content-reader.d.ts +5 -1
  114. package/dist/policy/content-reader.js +18 -3
  115. package/dist/policy/content-reader.test.js +2 -1
  116. package/dist/policy/preview-ledger-fault.test.js +101 -426
  117. package/dist/policy/preview-ledger.d.ts +38 -74
  118. package/dist/policy/preview-ledger.js +108 -186
  119. package/dist/policy/preview-ledger.test.js +237 -111
  120. package/dist/policy/result-limits.d.ts +6 -1
  121. package/dist/policy/result-limits.js +28 -29
  122. package/dist/policy/result-limits.test.js +10 -1
  123. package/dist/server/capabilities.js +2 -0
  124. package/dist/server/capabilities.test.js +2 -0
  125. package/dist/server/server.js +12 -8
  126. package/dist/server/upstream-errors.d.ts +17 -0
  127. package/dist/server/upstream-errors.js +60 -0
  128. package/dist/server/upstream-errors.test.js +50 -0
  129. package/dist/stdio.process.test.js +4 -2
  130. package/dist/tools/ai-agents/agents.d.ts +7 -0
  131. package/dist/tools/ai-agents/agents.js +32 -0
  132. package/dist/tools/ai-agents/agents.test.js +176 -0
  133. package/dist/tools/ai-agents/discovery.d.ts +9 -0
  134. package/dist/tools/ai-agents/discovery.js +73 -0
  135. package/dist/tools/ai-agents/evaluations.d.ts +14 -0
  136. package/dist/tools/ai-agents/evaluations.js +177 -0
  137. package/dist/tools/ai-agents/helpers.d.ts +64 -0
  138. package/dist/tools/ai-agents/helpers.js +323 -0
  139. package/dist/tools/ai-agents/threads.d.ts +7 -0
  140. package/dist/tools/ai-agents/threads.js +40 -0
  141. package/dist/tools/organization/inventory.js +2 -1
  142. package/dist/tools/project/content.js +5 -1
  143. package/dist/tools/project/developer-content-preview.d.ts +2 -1
  144. package/dist/tools/project/developer-content-preview.js +40 -35
  145. package/dist/tools/project/developer-content-shared.d.ts +8 -2
  146. package/dist/tools/project/developer-content-shared.js +7 -3
  147. package/dist/tools/project/developer-content.d.ts +7 -8
  148. package/dist/tools/project/developer-content.js +72 -67
  149. package/dist/tools/project/developer-get-chart-as-code.d.ts +9 -0
  150. package/dist/tools/project/developer-get-chart-as-code.js +39 -0
  151. package/dist/tools/project/developer-get-chart-as-code.test.d.ts +4 -0
  152. package/dist/tools/project/developer-get-chart-as-code.test.js +70 -0
  153. package/dist/tools/project/developer-helpers.d.ts +1 -1
  154. package/dist/tools/project/developer-helpers.js +1 -1
  155. package/dist/tools/project/get-dashboard-promote-diff.js +12 -2
  156. package/dist/tools/project/invariants.test.js +5 -3
  157. package/dist/tools/project/projects.js +6 -4
  158. package/dist/tools/project/projects.test.js +44 -5
  159. package/dist/tools/project/reader-export-chart-image.d.ts +6 -0
  160. package/dist/tools/project/reader-export-chart-image.js +78 -0
  161. package/dist/tools/project/reader-export-chart-image.test.d.ts +4 -0
  162. package/dist/tools/project/reader-export-chart-image.test.js +149 -0
  163. package/dist/tools/query/bounded-saved-query.js +1 -1
  164. package/dist/tools/query/lifecycle.d.ts +1 -1
  165. package/dist/tools/query/lifecycle.js +17 -25
  166. package/dist/tools/query/query-ledger.d.ts +15 -8
  167. package/dist/tools/query/query-ledger.js +21 -15
  168. package/dist/tools/query/query-ledger.test.js +13 -11
  169. package/dist/tools/query/reader-tool-helpers.js +4 -6
  170. package/dist/tools/query/reader-tool-helpers.test.js +8 -4
  171. package/dist/tools/registry.d.ts +63 -0
  172. package/dist/tools/registry.js +26 -0
  173. package/dist/tools/shared.d.ts +27 -8
  174. package/dist/tools/shared.js +61 -28
  175. package/dist/tools/shared.test.js +100 -4
  176. package/dist/transports/streamable-http.js +48 -206
  177. package/dist/transports/streamable-http.test.js +10 -3
  178. package/package.json +5 -6
  179. package/dist/destructive/confirmation-claim.d.ts +0 -21
  180. package/dist/destructive/confirmation-claim.js +0 -87
  181. package/dist/destructive/confirmation-claim.test.js +0 -50
  182. package/dist/store/config.d.ts +0 -11
  183. package/dist/store/config.js +0 -50
  184. package/dist/store/config.test.js +0 -56
  185. package/dist/store/create-oauth-broker-store.d.ts +0 -6
  186. package/dist/store/create-oauth-broker-store.js +0 -16
  187. package/dist/store/create-preview-store.d.ts +0 -10
  188. package/dist/store/create-preview-store.js +0 -30
  189. package/dist/store/create-session-store.d.ts +0 -19
  190. package/dist/store/create-session-store.js +0 -24
  191. package/dist/store/in-memory-preview-store.d.ts +0 -17
  192. package/dist/store/in-memory-preview-store.js +0 -72
  193. package/dist/store/redis-client.d.ts +0 -11
  194. package/dist/store/redis-client.js +0 -48
  195. package/dist/store/redis-oauth-broker-store.d.ts +0 -42
  196. package/dist/store/redis-oauth-broker-store.js +0 -167
  197. package/dist/store/redis-oauth-broker-store.test.js +0 -80
  198. package/dist/store/redis-preview-store.d.ts +0 -23
  199. package/dist/store/redis-preview-store.js +0 -94
  200. package/dist/store/redis-preview-store.test.d.ts +0 -1
  201. package/dist/store/redis-preview-store.test.js +0 -39
  202. package/dist/store/redis-session-index.d.ts +0 -33
  203. package/dist/store/redis-session-index.js +0 -49
  204. package/dist/store/types.d.ts +0 -13
  205. package/dist/store/types.js +0 -8
  206. package/dist/transports/http-request-utils.d.ts +0 -2
  207. package/dist/transports/http-request-utils.js +0 -13
  208. package/dist/transports/session-store.d.ts +0 -72
  209. package/dist/transports/session-store.js +0 -143
  210. package/dist/transports/session-store.test.d.ts +0 -1
  211. package/dist/transports/session-store.test.js +0 -111
  212. /package/dist/{destructive/confirmation-claim.test.d.ts → governance/client-capabilities-cache.test.d.ts} +0 -0
  213. /package/dist/{store/config.test.d.ts → server/upstream-errors.test.d.ts} +0 -0
  214. /package/dist/{store/redis-oauth-broker-store.test.d.ts → tools/ai-agents/agents.test.d.ts} +0 -0
@@ -2,25 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const common_1 = require("@lightdash-tools/common");
4
4
  const vitest_1 = require("vitest");
5
- const index_js_1 = require("./content-developer/v1/index.js");
6
- const index_js_2 = require("./content-governance/v1/index.js");
7
- const index_js_3 = require("./content-reader/v1/index.js");
8
- const index_js_4 = require("./organization-audit/v1/index.js");
9
- const index_js_5 = require("./semantic-layer/v1/index.js");
5
+ const index_js_1 = require("./ai-agent-ops/v1/index.js");
6
+ const index_js_2 = require("./content-developer/v1/index.js");
7
+ const index_js_3 = require("./content-governance/v1/index.js");
8
+ const index_js_4 = require("./content-reader/v1/index.js");
9
+ const index_js_5 = require("./organization-audit/v1/index.js");
10
+ const index_js_6 = require("./semantic-layer/v1/index.js");
10
11
  (0, vitest_1.describe)('persona catalog parity', () => {
12
+ (0, vitest_1.it)('ai-agent-ops allowlist matches catalog ai-agent-ops profile', () => {
13
+ (0, vitest_1.expect)([...index_js_1.AI_AGENT_OPS_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('ai-agent-ops')].sort());
14
+ });
11
15
  (0, vitest_1.it)('semantic-layer allowlist matches catalog semantic-discovery profile', () => {
12
- (0, vitest_1.expect)([...index_js_5.SEMANTIC_LAYER_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('semantic-discovery')].sort());
16
+ (0, vitest_1.expect)([...index_js_6.SEMANTIC_LAYER_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('semantic-discovery')].sort());
13
17
  });
14
18
  (0, vitest_1.it)('organization-audit allowlist matches catalog org-audit-readonly profile', () => {
15
- (0, vitest_1.expect)([...index_js_4.ORGANIZATION_AUDIT_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('org-audit-readonly')].sort());
19
+ (0, vitest_1.expect)([...index_js_5.ORGANIZATION_AUDIT_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('org-audit-readonly')].sort());
16
20
  });
17
21
  (0, vitest_1.it)('content-reader allowlist matches catalog content-reader profile', () => {
18
- (0, vitest_1.expect)([...index_js_3.CONTENT_READER_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('content-reader')].sort());
22
+ (0, vitest_1.expect)([...index_js_4.CONTENT_READER_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('content-reader')].sort());
19
23
  });
20
24
  (0, vitest_1.it)('content-developer allowlist matches catalog content-developer profile', () => {
21
- (0, vitest_1.expect)([...index_js_1.CONTENT_DEVELOPER_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('content-developer')].sort());
25
+ (0, vitest_1.expect)([...index_js_2.CONTENT_DEVELOPER_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('content-developer')].sort());
22
26
  });
23
27
  (0, vitest_1.it)('content-governance allowlist matches catalog content-governance profile', () => {
24
- (0, vitest_1.expect)([...index_js_2.CONTENT_GOVERNANCE_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('content-governance')].sort());
28
+ (0, vitest_1.expect)([...index_js_3.CONTENT_GOVERNANCE_TOOL_IDS].sort()).toEqual([...(0, common_1.listMcpToolNamesByProfile)('content-governance')].sort());
25
29
  });
26
30
  });
@@ -22,18 +22,22 @@ function registerSemanticLayerPrompts(server) {
22
22
  question: zod_1.z.string().optional().describe('Natural-language question or topic'),
23
23
  }),
24
24
  }, async ({ projectUuid, question }) => {
25
- const topic = question ? ` Question/topic: ${question}.` : '';
26
- return userMessages([
27
- 'Discover the Lightdash semantic layer for this project. Compile is out of scope unless asked.',
28
- `Project: ${projectUuid}.${topic}`,
29
- playbooks_js_1.SEMANTIC_LAYER_HARD_BANS,
30
- 'Procedure:',
31
- '1) Stick to this projectUuid (do not switch from an org-wide list_projects). Warehouse/dataset/table hints are search keys only.',
32
- '2) Always lightdash_list_explores with search+limit; disambiguate per playbook (schemaName, label or name __{table}, skip empty schema when dataset known).',
33
- '3) Shortlist base-table dimensions by role; once explore is known prefer get_explore → tables[baseTable].metrics only (catalog keyword optional, still filter tableName === explore id).',
34
- 'Deliverable: shortlist name/label/schemaName/fieldId (+ why). Do not dump full explore/dimension/metric/lineage payloads.',
35
- `Follow the embedded playbooks (${playbooks_js_1.SEMANTIC_LAYER_CORE_URI}, ${playbooks_js_1.SEMANTIC_LAYER_EXPLORE_URI}). Use only lightdash_* tools.`,
36
- ].join('\n'), 'explore');
25
+ const topic = question ? `Question/topic: ${question}.` : '';
26
+ return userMessages(`Discover the Lightdash semantic layer for this project. Compile is out of scope unless asked.
27
+
28
+ Project UUID (required on every tool): ${projectUuid}.
29
+ ${topic}
30
+
31
+ ${playbooks_js_1.SEMANTIC_LAYER_HARD_BANS}
32
+
33
+ Procedure:
34
+ 1. get_project once to confirm name. Do not switch projects from org-wide list_projects.
35
+ 2. list_explores with search+limit (≤15). Disambiguate: skip empty schemaName / errors; prefer exact label or name __{table}; deprioritize eda_/reporting_ unless asked.
36
+ 3. list_dimensions (base table) → shortlist ≤12 fieldIds by role (time/channel/segment/entity). Copy fieldIds literally.
37
+ 4. get_explore → tables[baseTable].metrics only (≤8 names/labels). Skip list_metrics once explore is known. Skip get_metric / get_field_lineage unless needed.
38
+ 5. Deliverable: chosen explore (name/label/schemaName/databaseName + why) + field shortlist. Never dump full explore/dimension/metric/lineage payloads.
39
+
40
+ Follow embedded playbooks (${playbooks_js_1.SEMANTIC_LAYER_CORE_URI}, ${playbooks_js_1.SEMANTIC_LAYER_EXPLORE_URI}). Use only lightdash_* tools.`, 'explore');
37
41
  });
38
42
  server.registerPrompt('lightdash_semantic_compose_compile', {
39
43
  title: 'Compose and compile query',
@@ -44,20 +48,24 @@ function registerSemanticLayerPrompts(server) {
44
48
  exploreId: (0, schema_fields_js_2.exploreIdField)().optional(),
45
49
  }),
46
50
  }, async ({ projectUuid, question, exploreId }) => {
47
- const topic = question ? ` Goal: ${question}.` : '';
48
- const explore = exploreId ? ` Preferred explore: ${exploreId}.` : '';
49
- return userMessages([
50
- 'Compose a Lightdash metric query and compile it with lightdash_compile_query. Do not run the query.',
51
- `Project: ${projectUuid}.${topic}${explore}`,
52
- playbooks_js_1.SEMANTIC_LAYER_HARD_BANS,
53
- 'Procedure:',
54
- '1) If exploreId is missing, resolve it per playbook (search + disambiguation).',
55
- '2) Use full fieldIds from list_dimensions / {exploreId}_{metricName}; prefer get_explore → tables[baseTable].metrics once explore is known.',
56
- '3) If the user asked for N insights, reuse one explore and compile N diverse cuts from available fields.',
57
- '4) Compile with fieldIds only; on empty SELECT or unknown field id, fix fieldIds and re-compile once. Extra related metrics in SQL can be OK. Stop after a good compile.',
58
- 'Deliverable: insight title(s) + fieldIds + compiled SQL (or errors). Never paste full explore/dimension/metric/lineage payloads.',
59
- `Follow the embedded playbooks (${playbooks_js_1.SEMANTIC_LAYER_CORE_URI}, ${playbooks_js_1.SEMANTIC_LAYER_COMPOSE_COMPILE_URI}).`,
60
- ].join('\n'), 'compose-compile');
51
+ const topic = question ? `Goal: ${question}.` : '';
52
+ const explore = exploreId ? `Preferred explore: ${exploreId}.` : '';
53
+ return userMessages(`Compose a Lightdash metric query and compile it with lightdash_compile_query. Do not run the query.
54
+
55
+ Project UUID: ${projectUuid}.
56
+ ${topic}
57
+ ${explore}
58
+
59
+ ${playbooks_js_1.SEMANTIC_LAYER_HARD_BANS}
60
+
61
+ Procedure:
62
+ 1. If exploreId is missing, resolve it per explore playbook (search + disambiguation). Stay on this projectUuid.
63
+ 2. Copy fieldIds from list_dimensions and {exploreId}_{metricName} from get_explore → tables[baseTable].metrics. Never invent grains.
64
+ 3. If the user asked for N insights, reuse one explore and compile N diverse cuts.
65
+ 4. compile_query with fieldIds only. After each compile, verify every requested fieldId appears as a SELECT alias (missing alias = failure even without isError). ≤2 fix retries.
66
+ 5. Deliverable: insight title(s) + fieldIds + compiled SQL (or errors). Never paste full explore/dimension/metric/lineage payloads.
67
+
68
+ Follow embedded playbooks (${playbooks_js_1.SEMANTIC_LAYER_CORE_URI}, ${playbooks_js_1.SEMANTIC_LAYER_COMPOSE_COMPILE_URI}).`, 'compose-compile');
61
69
  });
62
70
  server.registerPrompt('lightdash_semantic_compile_debug', {
63
71
  title: 'Debug compile errors',
@@ -68,18 +76,21 @@ function registerSemanticLayerPrompts(server) {
68
76
  errorText: zod_1.z.string().optional().describe('Compile error text if already known'),
69
77
  }),
70
78
  }, async ({ projectUuid, exploreId, errorText }) => {
71
- const err = errorText ? ` Error: ${errorText}` : '';
72
- return userMessages([
73
- 'Debug a failing lightdash_compile_query call and re-compile until it succeeds or you explain blockers.',
74
- `Project: ${projectUuid}`,
75
- `Explore: ${exploreId}.${err}`,
76
- playbooks_js_1.SEMANTIC_LAYER_HARD_BANS,
77
- 'Checklist:',
78
- '- Empty SELECT or unknown field id → use fieldIds from lightdash_list_dimensions (base table).',
79
- '- Wrong explore → re-disambiguate per playbook (schemaName; label or name __{table}).',
80
- '- Metric not found / catalog empty → get_explore tables[baseTable].metrics; tableName must be the full explore id; compile as {exploreId}_{metricName}.',
81
- 'Deliverable: successful compile (SQL with expected columns) or a clear blocker. Stop after a good compile.',
82
- `Follow the embedded playbooks (${playbooks_js_1.SEMANTIC_LAYER_CORE_URI}, ${playbooks_js_1.SEMANTIC_LAYER_COMPOSE_COMPILE_URI}).`,
83
- ].join('\n'), 'compose-compile');
79
+ const err = errorText ? `Known error: ${errorText}` : '';
80
+ return userMessages(`Debug a failing lightdash_compile_query call and re-compile until it succeeds or you explain blockers.
81
+
82
+ Project UUID: ${projectUuid}
83
+ Explore: ${exploreId}
84
+ ${err}
85
+
86
+ ${playbooks_js_1.SEMANTIC_LAYER_HARD_BANS}
87
+
88
+ Checklist:
89
+ - unknown field id / empty SELECT / missing SELECT alias → use fieldIds from list_dimensions (base table) + explore-local metrics; re-compile (≤2 retries).
90
+ - Wrong explore → re-disambiguate (schemaName; label or name __{table}; skip empty schema / eda unless asked).
91
+ - Metric not found / catalog empty → get_explore tables[baseTable].metrics; tableName must be the full explore id; compile as {exploreId}_{metricName}.
92
+ - Verify SELECT aliases after every compile. Stop after a good compile or a clear blocker.
93
+
94
+ Follow embedded playbooks (${playbooks_js_1.SEMANTIC_LAYER_CORE_URI}, ${playbooks_js_1.SEMANTIC_LAYER_COMPOSE_COMPILE_URI}).`, 'compose-compile');
84
95
  });
85
96
  }
@@ -2,25 +2,12 @@
2
2
 
3
3
  URI: `lightdash://playbooks/semantic-layer/compose-compile`
4
4
 
5
- ## Multi-insight composition (“compose N queries”)
6
-
7
- When the user asks for several insights on one table/explore:
8
-
9
- 1. Disambiguate explore once; reuse the same `exploreId` and metric shortlist.
10
- 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.
11
- 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.
12
- 4. Metrics that join other tables may produce large CTE SQL — still OK; mention the join briefly.
13
-
14
- ## Field IDs and empty SELECT
15
-
16
- Prefer `fieldId` from `lightdash_list_dimensions` / `{exploreId}_{metricName}`.
17
-
18
- Short names alone are unsafe:
19
-
20
- 1. Upstream may “succeed” with an **empty `SELECT`** — this server returns **`isError`**. Fix to `fieldId`s and re-compile once.
21
- 2. Or hard-error on unknown field id.
5
+ ## Recommended sequence
22
6
 
23
- 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.
7
+ 1. Scope: `get_project` with the user-given project UUID (do not switch from org-wide `list_projects`).
8
+ 2. Discover: search explores → disambiguate → `list_dimensions` shortlist + `get_explore` → `tables[baseTable].metrics`.
9
+ 3. Build `metricQuery` using **only** copied `fieldId`s.
10
+ 4. `compile_query` → **verify SELECT aliases** → stop (or ≤2 fix retries).
24
11
 
25
12
  ## metricQuery skeleton
26
13
 
@@ -36,20 +23,38 @@ Compiled SQL may include **extra related metrics** the semantic layer pulls in
36
23
  }
37
24
  ```
38
25
 
39
- `metrics` may be `[]`.
26
+ `metrics` may be `[]`. Every string in `dimensions` / `metrics` / `sorts[].fieldId` must appear in prior tool output.
40
27
 
41
- ## Recommended sequence
28
+ ## Field IDs — failure modes
29
+
30
+ | Symptom | Cause | Fix |
31
+ | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
32
+ | `unknown field id` / hard error | Short names or typos | Use full `fieldId` from `list_dimensions` / `{exploreId}_{metricName}` |
33
+ | Server `isError` + empty SELECT | Upstream accepted bad ids with **zero** columns | Replace with real fieldIds; re-compile once |
34
+ | SQL “succeeds” but a requested dim/metric is **missing** from SELECT | Invented or wrong fieldId (e.g. non-existent `*_session_day`) while another field still projected | Re-check against `list_dimensions` / metrics map; re-compile |
35
+ | `Metric not found` on `get_metric` | `tableName` was warehouse label | Use full explore id |
36
+
37
+ Compiled SQL may include **extra related metrics** the semantic layer pulls in — OK if every **requested** fieldId still appears as a SELECT alias.
38
+
39
+ ## Verify after every compile (mandatory)
42
40
 
43
- 1. Scope: `lightdash_get_project` with the user-given project UUID (do not switch from an org-wide list)
44
- 2. Discover: search explores → disambiguate → base-table dimensions (shortlist) + explore-local metrics (`get_explore` metrics map; catalog keyword optional)
45
- 3. `lightdash_compile_query` with `fieldId`s (repeat for multi-insight)
46
- 4. Verify SELECT columns; stop
41
+ 1. Parse the compiled `query` SELECT list (aliases / AS names).
42
+ 2. Confirm **each** requested dimension and metric `fieldId` is present.
43
+ 3. If any are missing → treat as failure even when the tool did not set `isError`.
44
+ 4. Confirm `ORDER BY` / sorts only reference fields that exist in the SELECT (or known group keys).
45
+
46
+ ## Multi-insight composition
47
+
48
+ When the user asks for N insights on one table/explore:
49
+
50
+ 1. Disambiguate explore **once**; reuse the same `exploreId` and metric shortlist.
51
+ 2. Pick **diverse** cuts from available fields (trend, categorical breakdown, rate/quality, outcome, acquisition) — only when those fields exist. Don’t repeat the same grain N times.
52
+ 3. Compile each; verify aliases; present **title + fieldIds + SQL** (or errors).
53
+ 4. Metrics that join other tables may produce large CTE SQL — still OK; mention the join briefly.
47
54
 
48
- ## Compose / debug stop criteria
55
+ ## Debug checklist
49
56
 
50
- - Deliverable: insight title(s) + fieldIds + compiled SQL (or errors). Never paste full explore/dimension/metric/lineage payloads.
51
- - Stop after a good compile. Re-compile only while debugging (empty SELECT / unknown field id / wrong explore / metric not found).
52
- - Multi-insight: N titled queries with fieldIds + SQL; one explore resolution shared across them.
53
- - Empty SELECT or unknown field id → use fieldIds from `lightdash_list_dimensions` (base table) and re-compile once.
54
- - Wrong explore → re-disambiguate (schemaName; label or name `__{table}`).
55
- - Metric not found / catalog empty → `get_explore` `tables[baseTable].metrics`; `tableName` must be the full explore id; compile as `{exploreId}_{metricName}`.
57
+ - Empty SELECT / unknown field id / missing alias → fix fieldIds from `list_dimensions` + explore-local metrics; re-compile (≤2 retries).
58
+ - Wrong explore → re-disambiguate (`schemaName`; exact `label` or `name` `__{table}`; skip empty schema / eda unless asked).
59
+ - Catalog empty / metric not found → `get_explore` `tables[baseTable].metrics`; compile as `{exploreId}_{metricName}`.
60
+ - Stop after a good verified compile or a clear blocker.
@@ -4,36 +4,68 @@ URI: `lightdash://playbooks/semantic-layer/core`
4
4
 
5
5
  ## Purpose
6
6
 
7
- 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.
7
+ Discover the Lightdash semantic layer and **compose + compile** metric queries. Stop after a good compile (or a clear blocker). This server never runs warehouse queries or mutates content.
8
8
 
9
- ## Allowed tools (always `lightdash_` prefix)
9
+ ## Hard bans
10
10
 
11
- | Tool | Use for |
12
- | --------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
13
- | `lightdash_list_projects` / `lightdash_get_project` | Confirm project UUID ↔ name via `{ data, warnings }` metadata (no warehouse/dbt credentials) |
14
- | `lightdash_list_explores` | Summaries (`name`, `label`, `tags`, `databaseName`, `schemaName`, `errors?`); **always** pass `search` + `limit` |
15
- | `lightdash_list_dimensions` | Compact `{ name, label, table, type, fieldId }`; **default = `table === explore.baseTable`** |
16
- | `lightdash_list_metrics` / `lightdash_get_metric` | Catalog search; **always** filter `tableName === exploreId` client-side |
17
- | `lightdash_compile_query` | Compile only — never “run” |
18
- | `lightdash_get_explore` | Use when catalog filter yields **zero** explore-local metrics; extract `tables[baseTable].metrics` only |
19
- | `lightdash_get_field_lineage` | Optional; summarize, don’t dump |
11
+ - Do **not** run / execute metric queries, SQL runner, charts, dashboards, or underlying data.
12
+ - Do **not** invent tools for validation jobs, spaces, users, groups, ACL, AI agents, or agentops — they are not on this server.
13
+ - Do **not** switch away from the user-given **Lightdash project UUID** after seeing `list_projects` (org-wide) or explore tags that mention other warehouses.
14
+ - Do **not** paste full `get_explore`, full dimension arrays, full `get_metric`, or full lineage JSON into the answer.
15
+ - Do **not** invent `fieldId`s or time-grain names — copy them from tool output only.
20
16
 
21
- ## Hard bans
17
+ ## Default budgets (override only if the user expands scope)
18
+
19
+ | Resource | Default |
20
+ | ----------------------------------- | ------------------------------------------------------------------------ |
21
+ | Explore search candidates inspected | **≤10** rows from `list_explores` (`search` + `limit≤15`) |
22
+ | Explores opened with `get_explore` | **1** chosen explore (retry only if wrong explore) |
23
+ | Dimension shortlist in the answer | **≤12** fieldIds |
24
+ | Metrics shortlisted / used | **≤8** (from `tables[baseTable].metrics`) |
25
+ | `list_metrics` catalog pages | **0** once explore is known; else **≤1** page (`pageSize≤20`) and filter |
26
+ | `get_metric` | **0** by default; **≤2** only when SQL/definition is required |
27
+ | `get_field_lineage` | **0** by default; **≤1** and summarize as “N upstream models” |
28
+ | Compile retries | **≤2** after the first attempt (fix fieldIds / explore, then stop) |
29
+
30
+ Record when a budget stopped you.
22
31
 
23
- 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).
32
+ ## Allowed tools (`lightdash_` prefix)
24
33
 
25
- ## Project scope
34
+ | Tool | Use for |
35
+ | ------------------------------- | --------------------------------------------------------------------------------------------- |
36
+ | `list_projects` / `get_project` | Confirm UUID ↔ name. Credentials never returned (`REDACTED` warning is normal). |
37
+ | `list_explores` | Summaries only. **Always** pass `search` + `limit`. |
38
+ | `list_dimensions` | Compact `{ name, label, table, type, fieldId }`. Default = base table only. |
39
+ | `get_explore` | **Preferred** metric menu: `tables[baseTable].metrics` names/labels only. Ignore join tables. |
40
+ | `list_metrics` / `get_metric` | Optional catalog / definition dig. Filter `tableName === exploreId`. |
41
+ | `compile_query` | Compile only — never “run”. |
42
+ | `get_field_lineage` | Optional provenance; summarize, don’t dump. |
26
43
 
27
- 1. If the user gave a **project UUID**, use it on every tool. Prefer `lightdash_get_project` to confirm the name.
28
- 2. Without an HTTP project pin, `lightdash_list_projects` may return the **entire org** — do **not** switch to another project from that list.
29
- 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`.
44
+ ## Project scope (critical)
45
+
46
+ 1. Every tool call uses the **user-given Lightdash `projectUuid`**. Prefer `get_project` once to confirm the name.
47
+ 2. Without HTTP pin `X-Lightdash-Project`, `list_projects` may list the **entire org**. Do **not** switch projects because a sibling name looks related.
48
+ 3. Lightdash **project UUID** ≠ BigQuery/GCP project. Explores carry `databaseName` / `schemaName` (warehouse). One Lightdash project often embeds explores whose `databaseName` points at another warehouse project — that is normal; stay on the given UUID.
49
+ 4. Optional ceiling `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS` may already filter `list_projects`; still pass the user’s UUID on tools.
30
50
 
31
51
  ## Answer shape
32
52
 
33
- 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.
53
+ - Explore: `name` / `label` / `schemaName` / `databaseName` + why chosen.
54
+ - Fields: short names + **full `fieldId`** (+ role: time / channel / segment / metric).
55
+ - Compile: insight title(s) + fieldIds + compiled SQL (or errors). Verify every requested fieldId appears as a SELECT alias.
56
+ - Gaps: budget hits, empty explore search, compile blockers.
34
57
 
35
58
  ## Stop / deliverables
36
59
 
37
- - **Explore prompt:** shortlist only — do not compile unless asked.
38
- - **Compose / debug:** compiled SQL or errors; stop after a good compile (re-compile only while debugging).
39
- - **Multi-insight:** N titled queries with fieldIds + SQL; one explore resolution shared across them.
60
+ | Prompt | Stop when |
61
+ | --------------- | ----------------------------------------------------------------- |
62
+ | Explore | Shortlist delivered; **do not compile** unless asked |
63
+ | Compose / debug | Good compile (aliases verified) or clear blocker after ≤2 retries |
64
+ | Multi-insight | N titled compiles on **one** explore; shared discovery |
65
+
66
+ ## Tool order (default)
67
+
68
+ 1. `get_project` (confirm) → `list_explores` (`search`+`limit`) → disambiguate
69
+ 2. `list_dimensions` (base table) → shortlist by role
70
+ 3. `get_explore` → extract **only** `tables[baseTable].metrics` (names/labels)
71
+ 4. `compile_query` with copied fieldIds → verify SELECT aliases → stop
@@ -2,75 +2,78 @@
2
2
 
3
3
  URI: `lightdash://playbooks/semantic-layer/explore`
4
4
 
5
- ## From warehouse inventory → explore
5
+ ## Always search explores
6
6
 
7
- When the user pastes warehouse inventory (dataset / table / partition field):
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
8
 
9
- | Inventory hint | MCP use |
10
- | ------------------------------- | ----------------------------------------------------------------------------------------- |
11
- | Dataset (`{dataset}`) | Prefer explores with matching **`schemaName`** |
12
- | TABLE (`{table}`) | `lightdash_list_explores` **`search`** = that table token; prefer **exact `label` match** |
13
- | Partition / time field | Candidate **dimension** `fieldId` for time-grain compiles |
14
- | Full id `project.dataset.table` | `databaseName` ≈ project, `schemaName` ≈ dataset, `label` ≈ table |
9
+ Warehouse table / dataset names are **search hints**, not explore IDs. Explore `name` is usually compound (often `{warehouse}__{dataset}__{table}`-style).
15
10
 
16
- 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.
11
+ ## From warehouse inventory → explore
17
12
 
18
- Some inventory tables have **no** explore. Empty `list_explores` → say so; try a related curated/summary table the user cares about.
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
19
 
20
- ## Always search explores
20
+ Some inventory tables have **no** explore. Empty or irrelevant search → say so; try a related curated/summary table the user cares about.
21
21
 
22
- On large projects, **never** use the default first-N explore list (alphabetical across unrelated domains). Always `search` + `limit`.
22
+ ## Explore disambiguation (do not pick the first hit)
23
23
 
24
- ## Explore disambiguation
25
-
26
- Search for `{table}` often returns siblings (staging / EDA / reporting variants, and the warehouse table). **Do not pick the first hit.**
24
+ Search for `{table}` often returns siblings: staging / EDA / reporting / MRE variants, empty-schema stubs, and the warehouse table.
27
25
 
28
26
  1. Skip explores with non-empty `errors`.
29
- 2. If the user named a dataset, prefer matching **`schemaName`**. Skip rows with **empty** `schemaName` unless nothing else matches.
30
- 3. Match warehouse table via **exact `label`** = `{table}`, **or** explore **`name`** ending with / containing `__{table}` (labels may be humanized).
31
- 4. Prefer tags such as `lightdash` when still tied.
32
- 5. Deprioritize staging / EDA / reporting-style name prefixes unless the user asked for them.
33
- 6. Duplicate labels with version suffixes: prefer the explore **`name`** without an extra `_vN` unless the user asked for that version.
34
- 7. State chosen explore **`name`**, `label`, and `schemaName` in the answer.
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
35
 
36
36
  ## Progressive discovery
37
37
 
38
- 1. `lightdash_list_explores` with search → disambiguate → note explore id (`name`, `label`, `schemaName`).
39
- 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).
40
- 3. Discover metrics (see below). Prefer **explore-local** metrics on the base table over unrelated catalog hits.
41
- 4. Stop at a shortlist unless the user asked to compile (compose/compile topic).
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
42
 
43
43
  ## Metrics: catalog vs explore-local (critical)
44
44
 
45
- `lightdash_list_metrics` searches the **org catalog**, not “metrics on this explore”.
45
+ `list_metrics` searches the **project catalog**, not “metrics on this explore”.
46
46
 
47
- | Search token | Typical result |
48
- | ------------------------------ | --------------------------------------------------- |
49
- | Warehouse table / explore id | **Often zero** hits |
50
- | Broad domain / entity tokens | Hundreds of **other** tables — flood |
51
- | Goal keyword from the question | May hit this explore **and** siblings — must filter |
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 |
52
53
 
53
54
  Rules:
54
55
 
55
- 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`.
56
- 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**.
57
- 3. `lightdash_get_metric` `tableName` must be the full explore id. Short warehouse labels → “Metric not found”. Summarize; do not paste huge `availableTimeDimensions` payloads.
58
- 4. Compile metric ids as `{exploreId}_{metricName}` (same pattern as dimension `fieldId`).
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`).
59
60
  5. Dimension-only (`metrics: []`) is valid for volume-by-time; for “insights” prefer real explore metrics when available.
60
61
 
61
62
  ## Dimension shortlist (large explores)
62
63
 
63
- Base tables can expose **hundreds** of dimensions (nested structs, event arrays). Do **not** dump the full list.
64
+ Base tables can expose **hundreds** of dimensions; many are nested (`a.b.c` paths / event arrays). Do **not** dump the list.
64
65
 
65
- Prefer high-signal fields that appear in `list_dimensions`, by **role**:
66
+ Prefer high-signal fields that **appear in `list_dimensions`**, by **role**:
66
67
 
67
- - Time grains (day / week / month; prefer local timezone grains when both UTC and local exist)
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`)
68
69
  - Channel / platform / traffic source
69
70
  - Segment / demographic / cohort dimensions relevant to the question
70
71
  - Core product or entity attributes named in the question
71
72
 
72
73
  Skip nested event dumps and deep struct paths unless the question targets them.
73
74
 
75
+ **Copy `fieldId` literally.** Do not invent grains like `{explore}_session_day` if that string is not in `list_dimensions`.
76
+
74
77
  ## Field lineage
75
78
 
76
- `lightdash_get_field_lineage` accepts full `fieldId` or short `name`. Summarize; do not paste the full graph.
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.
@@ -4,10 +4,10 @@ URI: `lightdash://playbooks/semantic-layer`
4
4
 
5
5
  Workflow-scoped playbooks (always load **core** plus one topic with a prompt):
6
6
 
7
- | Topic | URI |
8
- | ------------------- | ------------------------------------------------------ |
9
- | Core (gates & bans) | `lightdash://playbooks/semantic-layer/core` |
10
- | Explore / discover | `lightdash://playbooks/semantic-layer/explore` |
11
- | Compose & compile | `lightdash://playbooks/semantic-layer/compose-compile` |
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
12
 
13
- 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.
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.
@@ -10,8 +10,8 @@ const playbooks = (0, playbook_resources_js_1.definePersonaPlaybooks)({
10
10
  personaId: 'semantic-layer',
11
11
  moduleDir: __dirname,
12
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, or call AI/identity tools. Those are not available on this server.',
14
- coreDescription: 'Hard bans, allowed tools, project scope, and stop criteria',
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
15
  topics: [
16
16
  {
17
17
  id: 'explore',
@@ -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 = 'content-developer' | 'content-governance' | 'content-reader' | '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. */
@@ -15,13 +15,13 @@ export type DeveloperOperationSafety = {
15
15
  };
16
16
  /** Discovery / passthrough reads (get_project, search_content, list_spaces, ...). */
17
17
  export declare const DISCOVERY_SAFETY: DeveloperOperationSafety;
18
- /** preview_* — computes a diff and issues a previewId, never persists. */
18
+ /** preview_* — computes a diff and issues a HMAC-signed previewToken (ADR-0019), never persists. */
19
19
  export declare const PREVIEW_SAFETY: DeveloperOperationSafety;
20
- /** validate_* — optional saved-resource health check; never unlocks the preview ledger. */
20
+ /** validate_* — optional saved-resource health check; never unlocks the preview. */
21
21
  export declare const VALIDATE_SAFETY: DeveloperOperationSafety;
22
22
  /** compare_*_versions — reads two historical versions and returns a diff, never persists. */
23
23
  export declare const COMPARE_SAFETY: DeveloperOperationSafety;
24
- /** SAFE_WRITE apply tools gated by a validated previewId. */
24
+ /** SAFE_WRITE apply tools gated by a validated previewToken. */
25
25
  export declare const WRITE_SAFETY: DeveloperOperationSafety;
26
26
  /** Throws when a tool violates content-developer capability policy. */
27
27
  export declare function assertContentDeveloperSafe(safety: DeveloperOperationSafety): void;
@@ -22,14 +22,14 @@ exports.DISCOVERY_SAFETY = {
22
22
  resultCapability: 'metadata',
23
23
  agentExposure: 'agent',
24
24
  };
25
- /** preview_* — computes a diff and issues a previewId, never persists. */
25
+ /** preview_* — computes a diff and issues a HMAC-signed previewToken (ADR-0019), never persists. */
26
26
  exports.PREVIEW_SAFETY = {
27
27
  mutability: 'preview',
28
28
  queryCapability: 'none',
29
29
  resultCapability: 'diff',
30
30
  agentExposure: 'agent',
31
31
  };
32
- /** validate_* — optional saved-resource health check; never unlocks the preview ledger. */
32
+ /** validate_* — optional saved-resource health check; never unlocks the preview. */
33
33
  exports.VALIDATE_SAFETY = {
34
34
  mutability: 'none',
35
35
  queryCapability: 'none',
@@ -43,7 +43,7 @@ exports.COMPARE_SAFETY = {
43
43
  resultCapability: 'diff',
44
44
  agentExposure: 'agent',
45
45
  };
46
- /** SAFE_WRITE apply tools gated by a validated previewId. */
46
+ /** SAFE_WRITE apply tools gated by a validated previewToken. */
47
47
  exports.WRITE_SAFETY = {
48
48
  mutability: MUTABILITY_WRITE_NONDESTRUCTIVE,
49
49
  queryCapability: 'none',
@@ -31,16 +31,22 @@ const preview_ledger_js_1 = require("./preview-ledger.js");
31
31
  });
32
32
  (0, vitest_1.describe)('developerErrorResult', () => {
33
33
  (0, vitest_1.it)('maps ProjectScopeError to a coded blocked result', () => {
34
- var _a;
35
34
  const result = (0, content_developer_js_1.developerErrorResult)(new project_scope_js_1.ProjectScopeError('PROJECT_SCOPE_REQUIRED', 'no project'));
36
35
  (0, vitest_1.expect)(result.isError).toBe(true);
37
- (0, vitest_1.expect)((_a = result.content[0]) === null || _a === void 0 ? void 0 : _a.text).toContain('PROJECT_SCOPE_REQUIRED');
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
+ }
38
41
  });
39
42
  (0, vitest_1.it)('maps PreviewLedgerError to a coded blocked result', () => {
40
- var _a;
41
43
  const result = (0, content_developer_js_1.developerErrorResult)(new preview_ledger_js_1.PreviewLedgerError('PREVIEW_STALE', 'stale preview'));
42
44
  (0, vitest_1.expect)(result.isError).toBe(true);
43
- (0, vitest_1.expect)((_a = result.content[0]) === null || _a === void 0 ? void 0 : _a.text).toContain('PREVIEW_STALE');
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
+ }
44
50
  });
45
51
  (0, vitest_1.it)('rethrows unrelated errors', () => {
46
52
  (0, vitest_1.expect)(() => (0, content_developer_js_1.developerErrorResult)(new Error('boom'))).toThrow('boom');
@@ -7,14 +7,18 @@ import type { McpServer } from '@modelcontextprotocol/server';
7
7
  export type ReaderOperationSafety = {
8
8
  mutability: 'none' | 'transient';
9
9
  queryCapability: 'arbitrary_semantic' | 'none' | 'raw_sql' | 'saved_content' | 'underlying_data';
10
- resultCapability: 'bounded_aggregate_rows' | 'bulk_export' | 'metadata' | 'row_level';
10
+ resultCapability: 'bounded_aggregate_rows' | 'bulk_export' | 'image_snapshot' | 'metadata' | 'row_level';
11
11
  usesWarehouse: boolean;
12
12
  agentExposure: 'agent' | 'client-only';
13
13
  };
14
14
  /** Computational read-only (warehouse run) but not idempotent — run/cancel/poll. */
15
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;
16
18
  export declare const METADATA_SAFETY: ReaderOperationSafety;
17
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;
18
22
  /** Throws when a tool violates content-reader capability policy. */
19
23
  export declare function assertContentReaderSafe(safety: ReaderOperationSafety): void;
20
24
  /** Register a content-reader tool after safety asserts. */