@lightdash-tools/mcp 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (485) hide show
  1. package/README.md +205 -58
  2. package/dist/audit/audit.d.ts +5 -0
  3. package/dist/{audit.js → audit/audit.js} +1 -2
  4. package/dist/audit/tool-audit-context.d.ts +6 -0
  5. package/dist/audit/tool-audit-context.js +12 -0
  6. package/dist/audit/tool-audit-context.test.d.ts +1 -0
  7. package/dist/audit/tool-audit-context.test.js +19 -0
  8. package/dist/auth/auth-mode.d.ts +4 -0
  9. package/dist/auth/auth-mode.js +6 -0
  10. package/dist/auth/bearer.d.ts +3 -0
  11. package/dist/auth/bearer.js +13 -0
  12. package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
  13. package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
  14. package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
  15. package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
  16. package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
  17. package/dist/auth/oauth-broker/as-metadata.js +20 -0
  18. package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
  19. package/dist/auth/oauth-broker/lightdash-token.js +76 -0
  20. package/dist/auth/oauth-broker/pending-store.d.ts +127 -0
  21. package/dist/auth/oauth-broker/pending-store.js +151 -0
  22. package/dist/auth/oauth-broker/pending-store.test.d.ts +6 -0
  23. package/dist/auth/oauth-broker/pending-store.test.js +146 -0
  24. package/dist/auth/oauth-broker/pkce.d.ts +2 -0
  25. package/dist/auth/oauth-broker/pkce.js +17 -0
  26. package/dist/auth/oauth-broker/routes.d.ts +13 -0
  27. package/dist/auth/oauth-broker/routes.js +452 -0
  28. package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
  29. package/dist/auth/oauth-broker/routes.test.js +242 -0
  30. package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
  31. package/dist/auth/providers/bearer-context-provider.js +52 -0
  32. package/dist/auth/providers/env-context-provider.d.ts +13 -0
  33. package/dist/auth/providers/env-context-provider.js +19 -0
  34. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
  35. package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
  36. package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
  37. package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
  38. package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
  39. package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
  40. package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
  41. package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
  42. package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
  43. package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
  44. package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
  45. package/dist/auth/resource-server/shared-key-middleware.js +24 -0
  46. package/dist/auth/resource-server/token-scopes.d.ts +15 -0
  47. package/dist/auth/resource-server/token-scopes.js +76 -0
  48. package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
  49. package/dist/auth/resource-server/token-scopes.test.js +51 -0
  50. package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
  51. package/dist/auth/resource-server/token-validation-cache.js +44 -0
  52. package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
  53. package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
  54. package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
  55. package/dist/auth/resource-server/token-validation-error.js +13 -0
  56. package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
  57. package/dist/auth/resource-server/www-authenticate.js +24 -0
  58. package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
  59. package/dist/auth/resource-server/www-authenticate.test.js +70 -0
  60. package/dist/auth/token-hash.d.ts +2 -0
  61. package/dist/auth/token-hash.js +8 -0
  62. package/dist/bin.d.ts +0 -4
  63. package/dist/bin.js +62 -33
  64. package/dist/config/env.d.ts +57 -0
  65. package/dist/config/env.js +60 -0
  66. package/dist/config/load-mcp-config.d.ts +30 -0
  67. package/dist/config/load-mcp-config.js +286 -0
  68. package/dist/config/load-mcp-config.test.d.ts +1 -0
  69. package/dist/config/load-mcp-config.test.js +202 -0
  70. package/dist/config/normalize-url.d.ts +13 -0
  71. package/dist/config/normalize-url.js +52 -0
  72. package/dist/config/normalize-url.test.d.ts +1 -0
  73. package/dist/config/normalize-url.test.js +47 -0
  74. package/dist/config/public-url.d.ts +3 -0
  75. package/dist/config/public-url.js +10 -0
  76. package/dist/config/runtime.d.ts +15 -0
  77. package/dist/config/runtime.js +48 -0
  78. package/dist/config/runtime.test.d.ts +1 -0
  79. package/dist/config/runtime.test.js +69 -0
  80. package/dist/config/test-mcp-http-config.d.ts +3 -0
  81. package/dist/config/test-mcp-http-config.js +7 -0
  82. package/dist/destructive/capability.d.ts +13 -0
  83. package/dist/destructive/capability.js +37 -0
  84. package/dist/destructive/capability.test.d.ts +1 -0
  85. package/dist/destructive/capability.test.js +46 -0
  86. package/dist/destructive/confirmation-claim.d.ts +21 -0
  87. package/dist/destructive/confirmation-claim.js +87 -0
  88. package/dist/destructive/confirmation-claim.test.d.ts +1 -0
  89. package/dist/destructive/confirmation-claim.test.js +50 -0
  90. package/dist/destructive/confirmation.d.ts +58 -0
  91. package/dist/destructive/confirmation.js +99 -0
  92. package/dist/destructive/confirmation.test.d.ts +1 -0
  93. package/dist/destructive/confirmation.test.js +75 -0
  94. package/dist/destructive/content-promote.d.ts +8 -0
  95. package/dist/destructive/content-promote.js +144 -0
  96. package/dist/destructive/content-soft-delete.d.ts +7 -0
  97. package/dist/destructive/content-soft-delete.js +106 -0
  98. package/dist/destructive/destructive-contract.test.d.ts +1 -0
  99. package/dist/destructive/destructive-contract.test.js +269 -0
  100. package/dist/destructive/precondition.d.ts +14 -0
  101. package/dist/destructive/precondition.js +31 -0
  102. package/dist/destructive/precondition.test.d.ts +1 -0
  103. package/dist/destructive/precondition.test.js +72 -0
  104. package/dist/destructive/promote-contract.test.d.ts +1 -0
  105. package/dist/destructive/promote-contract.test.js +339 -0
  106. package/dist/destructive/register-destructive-tool.d.ts +54 -0
  107. package/dist/destructive/register-destructive-tool.js +301 -0
  108. package/dist/destructive/request-state.d.ts +16 -0
  109. package/dist/destructive/request-state.js +76 -0
  110. package/dist/destructive/types.d.ts +64 -0
  111. package/dist/destructive/types.js +10 -0
  112. package/dist/governance/mcp-client-session.d.ts +9 -0
  113. package/dist/governance/mcp-client-session.js +30 -0
  114. package/dist/governance/mcp-client-session.test.d.ts +1 -0
  115. package/dist/governance/mcp-client-session.test.js +31 -0
  116. package/dist/governance/project-pin.d.ts +14 -0
  117. package/dist/governance/project-pin.js +44 -0
  118. package/dist/governance/project-pin.test.d.ts +1 -0
  119. package/dist/governance/project-pin.test.js +35 -0
  120. package/dist/governance/project-scope.d.ts +38 -0
  121. package/dist/governance/project-scope.js +79 -0
  122. package/dist/governance/project-scope.test.d.ts +4 -0
  123. package/dist/governance/project-scope.test.js +103 -0
  124. package/dist/http.d.ts +1 -2
  125. package/dist/http.integration.test.d.ts +1 -0
  126. package/dist/http.integration.test.js +722 -0
  127. package/dist/http.js +3 -170
  128. package/dist/http.test.d.ts +4 -0
  129. package/dist/http.test.js +131 -0
  130. package/dist/index.d.ts +2 -0
  131. package/dist/index.integration.test.js +73 -30
  132. package/dist/index.js +28 -27
  133. package/dist/index.test.js +3 -3
  134. package/dist/logging/structured.d.ts +27 -0
  135. package/dist/logging/structured.js +32 -0
  136. package/dist/logging/structured.test.d.ts +1 -0
  137. package/dist/logging/structured.test.js +33 -0
  138. package/dist/personas/content-developer/v1/index.d.ts +10 -0
  139. package/dist/personas/content-developer/v1/index.js +51 -0
  140. package/dist/personas/content-developer/v1/prompts.d.ts +5 -0
  141. package/dist/personas/content-developer/v1/prompts.js +138 -0
  142. package/dist/personas/content-developer/v1/prompts.test.d.ts +4 -0
  143. package/dist/personas/content-developer/v1/prompts.test.js +75 -0
  144. package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +15 -0
  145. package/dist/personas/content-developer/v1/resources/playbooks/core.md +63 -0
  146. package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +55 -0
  147. package/dist/personas/content-developer/v1/resources/playbooks/index.md +13 -0
  148. package/dist/personas/content-developer/v1/resources/playbooks.d.ts +10 -0
  149. package/dist/personas/content-developer/v1/resources/playbooks.js +44 -0
  150. package/dist/personas/content-governance/v1/index.d.ts +9 -0
  151. package/dist/personas/content-governance/v1/index.js +29 -0
  152. package/dist/personas/content-governance/v1/prompts.d.ts +5 -0
  153. package/dist/personas/content-governance/v1/prompts.js +87 -0
  154. package/dist/personas/content-governance/v1/prompts.test.d.ts +4 -0
  155. package/dist/personas/content-governance/v1/prompts.test.js +75 -0
  156. package/dist/personas/content-governance/v1/resources/playbooks/charts.md +29 -0
  157. package/dist/personas/content-governance/v1/resources/playbooks/core.md +52 -0
  158. package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +48 -0
  159. package/dist/personas/content-governance/v1/resources/playbooks/index.md +13 -0
  160. package/dist/personas/content-governance/v1/resources/playbooks.d.ts +10 -0
  161. package/dist/personas/content-governance/v1/resources/playbooks.js +41 -0
  162. package/dist/personas/content-reader/v1/index.d.ts +8 -0
  163. package/dist/personas/content-reader/v1/index.js +37 -0
  164. package/dist/personas/content-reader/v1/prompts.d.ts +5 -0
  165. package/dist/personas/content-reader/v1/prompts.js +128 -0
  166. package/dist/personas/content-reader/v1/prompts.test.d.ts +4 -0
  167. package/dist/personas/content-reader/v1/prompts.test.js +25 -0
  168. package/dist/personas/content-reader/v1/resources/playbooks/compare.md +21 -0
  169. package/dist/personas/content-reader/v1/resources/playbooks/core.md +40 -0
  170. package/dist/personas/content-reader/v1/resources/playbooks/discover.md +13 -0
  171. package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +19 -0
  172. package/dist/personas/content-reader/v1/resources/playbooks/index.md +14 -0
  173. package/dist/personas/content-reader/v1/resources/playbooks.d.ts +10 -0
  174. package/dist/personas/content-reader/v1/resources/playbooks.js +49 -0
  175. package/dist/personas/index.d.ts +22 -0
  176. package/dist/personas/index.js +73 -0
  177. package/dist/personas/index.test.d.ts +1 -0
  178. package/dist/personas/index.test.js +109 -0
  179. package/dist/personas/lib/playbook-resources.d.ts +79 -0
  180. package/dist/personas/lib/playbook-resources.js +165 -0
  181. package/dist/personas/organization-audit/v1/index.d.ts +8 -0
  182. package/dist/personas/organization-audit/v1/index.js +42 -0
  183. package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
  184. package/dist/personas/organization-audit/v1/prompts.js +92 -0
  185. package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
  186. package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
  187. package/dist/personas/organization-audit/v1/resources/playbooks/access.md +13 -0
  188. package/dist/personas/organization-audit/v1/resources/playbooks/content.md +9 -0
  189. package/dist/personas/organization-audit/v1/resources/playbooks/core.md +36 -0
  190. package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +9 -0
  191. package/dist/personas/organization-audit/v1/resources/playbooks/index.md +14 -0
  192. package/dist/personas/organization-audit/v1/resources/playbooks.d.ts +10 -0
  193. package/dist/personas/organization-audit/v1/resources/playbooks.js +41 -0
  194. package/dist/personas/persona.parity.test.d.ts +1 -0
  195. package/dist/personas/persona.parity.test.js +26 -0
  196. package/dist/personas/semantic-layer/v1/index.d.ts +8 -0
  197. package/dist/personas/semantic-layer/v1/index.js +32 -0
  198. package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
  199. package/dist/personas/semantic-layer/v1/prompts.js +85 -0
  200. package/dist/personas/semantic-layer/v1/prompts.test.d.ts +4 -0
  201. package/dist/personas/semantic-layer/v1/prompts.test.js +19 -0
  202. package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +55 -0
  203. package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +39 -0
  204. package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +76 -0
  205. package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +13 -0
  206. package/dist/personas/semantic-layer/v1/resources/playbooks.d.ts +13 -0
  207. package/dist/personas/semantic-layer/v1/resources/playbooks.js +39 -0
  208. package/dist/personas/types.d.ts +19 -0
  209. package/dist/personas/types.js +5 -0
  210. package/dist/policy/content-developer.d.ts +35 -0
  211. package/dist/policy/content-developer.js +91 -0
  212. package/dist/policy/content-developer.test.d.ts +4 -0
  213. package/dist/policy/content-developer.test.js +48 -0
  214. package/dist/policy/content-reader.d.ts +24 -0
  215. package/dist/policy/content-reader.js +52 -0
  216. package/dist/policy/content-reader.test.d.ts +4 -0
  217. package/dist/policy/content-reader.test.js +22 -0
  218. package/dist/policy/envelope.d.ts +31 -0
  219. package/dist/policy/envelope.js +24 -0
  220. package/dist/policy/preview-ledger-fault.test.d.ts +1 -0
  221. package/dist/policy/preview-ledger-fault.test.js +527 -0
  222. package/dist/policy/preview-ledger.d.ts +118 -0
  223. package/dist/policy/preview-ledger.js +243 -0
  224. package/dist/policy/preview-ledger.test.d.ts +1 -0
  225. package/dist/policy/preview-ledger.test.js +267 -0
  226. package/dist/policy/result-limits.d.ts +27 -0
  227. package/dist/policy/result-limits.js +107 -0
  228. package/dist/policy/result-limits.test.d.ts +4 -0
  229. package/dist/policy/result-limits.test.js +28 -0
  230. package/dist/protocol-contract.test.d.ts +1 -0
  231. package/dist/protocol-contract.test.js +42 -0
  232. package/dist/server/capabilities.d.ts +15 -0
  233. package/dist/server/capabilities.js +19 -0
  234. package/dist/server/capabilities.test.d.ts +1 -0
  235. package/dist/server/capabilities.test.js +41 -0
  236. package/dist/server/errors.test.d.ts +1 -0
  237. package/dist/server/errors.test.js +53 -0
  238. package/dist/server/request-context.d.ts +13 -0
  239. package/dist/server/request-context.js +2 -0
  240. package/dist/server/server.d.ts +4 -0
  241. package/dist/server/server.js +28 -0
  242. package/dist/server/server.test.d.ts +1 -0
  243. package/dist/server/server.test.js +15 -0
  244. package/dist/server/version.d.ts +1 -0
  245. package/dist/server/version.js +7 -0
  246. package/dist/server/version.test.d.ts +1 -0
  247. package/dist/server/version.test.js +9 -0
  248. package/dist/stdio.process.test.d.ts +1 -0
  249. package/dist/stdio.process.test.js +274 -0
  250. package/dist/store/config.d.ts +11 -0
  251. package/dist/store/config.js +50 -0
  252. package/dist/store/config.test.d.ts +1 -0
  253. package/dist/store/config.test.js +56 -0
  254. package/dist/store/create-oauth-broker-store.d.ts +6 -0
  255. package/dist/store/create-oauth-broker-store.js +16 -0
  256. package/dist/store/create-preview-store.d.ts +10 -0
  257. package/dist/store/create-preview-store.js +30 -0
  258. package/dist/store/create-session-store.d.ts +19 -0
  259. package/dist/store/create-session-store.js +24 -0
  260. package/dist/store/in-memory-preview-store.d.ts +17 -0
  261. package/dist/store/in-memory-preview-store.js +72 -0
  262. package/dist/store/redis-client.d.ts +11 -0
  263. package/dist/store/redis-client.js +48 -0
  264. package/dist/store/redis-oauth-broker-store.d.ts +42 -0
  265. package/dist/store/redis-oauth-broker-store.js +167 -0
  266. package/dist/store/redis-oauth-broker-store.test.d.ts +1 -0
  267. package/dist/store/redis-oauth-broker-store.test.js +80 -0
  268. package/dist/store/redis-preview-store.d.ts +23 -0
  269. package/dist/store/redis-preview-store.js +94 -0
  270. package/dist/store/redis-preview-store.test.d.ts +1 -0
  271. package/dist/store/redis-preview-store.test.js +39 -0
  272. package/dist/store/redis-session-index.d.ts +33 -0
  273. package/dist/store/redis-session-index.js +49 -0
  274. package/dist/store/types.d.ts +13 -0
  275. package/dist/store/types.js +8 -0
  276. package/dist/tools/composition/explain-content.d.ts +6 -0
  277. package/dist/tools/composition/explain-content.js +108 -0
  278. package/dist/tools/index.d.ts +2 -4
  279. package/dist/tools/index.js +4 -30
  280. package/dist/tools/index.test.d.ts +1 -0
  281. package/dist/tools/index.test.js +72 -0
  282. package/dist/tools/lib/api-errors.d.ts +11 -0
  283. package/dist/tools/lib/api-errors.js +27 -0
  284. package/dist/tools/lib/api-shape.d.ts +16 -0
  285. package/dist/tools/lib/api-shape.js +47 -0
  286. package/dist/tools/lib/assert-safe.d.ts +13 -0
  287. package/dist/tools/lib/assert-safe.js +21 -0
  288. package/dist/tools/lib/assert-safe.test.d.ts +4 -0
  289. package/dist/tools/lib/assert-safe.test.js +32 -0
  290. package/dist/tools/lib/concurrency.d.ts +4 -0
  291. package/dist/tools/lib/concurrency.js +24 -0
  292. package/dist/tools/lib/contracts.d.ts +34 -0
  293. package/dist/tools/lib/contracts.js +30 -0
  294. package/dist/tools/lib/redaction.d.ts +107 -0
  295. package/dist/tools/lib/redaction.js +299 -0
  296. package/dist/tools/lib/redaction.test.d.ts +4 -0
  297. package/dist/tools/lib/redaction.test.js +216 -0
  298. package/dist/tools/lib/register-org-audit.d.ts +9 -0
  299. package/dist/tools/lib/register-org-audit.js +20 -0
  300. package/dist/tools/lib/schema-fields.d.ts +9 -0
  301. package/dist/tools/lib/schema-fields.js +19 -0
  302. package/dist/tools/lib/stable-stringify.d.ts +9 -0
  303. package/dist/tools/lib/stable-stringify.js +35 -0
  304. package/dist/tools/organization/binding.d.ts +14 -0
  305. package/dist/tools/organization/binding.js +31 -0
  306. package/dist/tools/organization/invariants.test.d.ts +4 -0
  307. package/dist/tools/organization/invariants.test.js +28 -0
  308. package/dist/tools/organization/inventory.d.ts +10 -0
  309. package/dist/tools/organization/inventory.js +189 -0
  310. package/dist/tools/organization/roles.d.ts +10 -0
  311. package/dist/tools/organization/roles.js +213 -0
  312. package/dist/tools/project/content.d.ts +9 -0
  313. package/dist/tools/project/content.js +192 -0
  314. package/dist/tools/project/delete-chart.d.ts +4 -0
  315. package/dist/tools/project/delete-chart.js +8 -0
  316. package/dist/tools/project/delete-dashboard.d.ts +4 -0
  317. package/dist/tools/project/delete-dashboard.js +8 -0
  318. package/dist/tools/project/developer-content-preview.d.ts +12 -0
  319. package/dist/tools/project/developer-content-preview.js +286 -0
  320. package/dist/tools/project/developer-content-shared.d.ts +18 -0
  321. package/dist/tools/project/developer-content-shared.js +46 -0
  322. package/dist/tools/project/developer-content-shared.test.d.ts +1 -0
  323. package/dist/tools/project/developer-content-shared.test.js +25 -0
  324. package/dist/tools/project/developer-content.d.ts +39 -0
  325. package/dist/tools/project/developer-content.js +584 -0
  326. package/dist/tools/project/developer-helpers.d.ts +180 -0
  327. package/dist/tools/project/developer-helpers.js +484 -0
  328. package/dist/tools/project/developer-helpers.test.d.ts +1 -0
  329. package/dist/tools/project/developer-helpers.test.js +509 -0
  330. package/dist/tools/project/get-dashboard-promote-diff.d.ts +6 -0
  331. package/dist/tools/project/get-dashboard-promote-diff.js +42 -0
  332. package/dist/tools/project/invariants.test.d.ts +4 -0
  333. package/dist/tools/project/invariants.test.js +42 -0
  334. package/dist/tools/project/parameters.d.ts +7 -0
  335. package/dist/tools/project/parameters.js +74 -0
  336. package/dist/tools/project/projects.d.ts +10 -0
  337. package/dist/tools/project/projects.js +102 -0
  338. package/dist/tools/project/projects.test.d.ts +1 -0
  339. package/dist/tools/project/projects.test.js +154 -0
  340. package/dist/tools/project/promote-dashboard.d.ts +4 -0
  341. package/dist/tools/project/promote-dashboard.js +8 -0
  342. package/dist/tools/project/reader-content.d.ts +9 -0
  343. package/dist/tools/project/reader-content.js +208 -0
  344. package/dist/tools/project/reader-execution.d.ts +7 -0
  345. package/dist/tools/project/reader-execution.js +214 -0
  346. package/dist/tools/project/schedulers.d.ts +7 -0
  347. package/dist/tools/project/schedulers.js +115 -0
  348. package/dist/tools/project/schemas/chart-upsert.d.ts +33 -0
  349. package/dist/tools/project/schemas/chart-upsert.js +66 -0
  350. package/dist/tools/project/schemas/dashboard-tile.d.ts +29 -0
  351. package/dist/tools/project/schemas/dashboard-tile.js +57 -0
  352. package/dist/tools/project/schemas/dashboard.d.ts +70 -0
  353. package/dist/tools/project/schemas/dashboard.js +101 -0
  354. package/dist/tools/project/schemas/duplicate.d.ts +30 -0
  355. package/dist/tools/project/schemas/duplicate.js +86 -0
  356. package/dist/tools/project/schemas/index.d.ts +7 -0
  357. package/dist/tools/project/schemas/index.js +26 -0
  358. package/dist/tools/project/schemas/parse-helpers.d.ts +14 -0
  359. package/dist/tools/project/schemas/parse-helpers.js +34 -0
  360. package/dist/tools/project/schemas/payload-schemas.test.d.ts +1 -0
  361. package/dist/tools/project/schemas/payload-schemas.test.js +204 -0
  362. package/dist/tools/project/spaces.d.ts +7 -0
  363. package/dist/tools/project/spaces.js +101 -0
  364. package/dist/tools/query/bounded-saved-query.d.ts +37 -0
  365. package/dist/tools/query/bounded-saved-query.js +80 -0
  366. package/dist/tools/query/bounded-saved-query.test.d.ts +4 -0
  367. package/dist/tools/query/bounded-saved-query.test.js +82 -0
  368. package/dist/tools/query/chart-source.d.ts +10 -0
  369. package/dist/tools/query/chart-source.js +36 -0
  370. package/dist/tools/query/chart-source.test.d.ts +1 -0
  371. package/dist/tools/query/chart-source.test.js +62 -0
  372. package/dist/tools/query/filter-overrides.d.ts +34 -0
  373. package/dist/tools/query/filter-overrides.js +75 -0
  374. package/dist/tools/query/filter-overrides.test.d.ts +1 -0
  375. package/dist/tools/query/filter-overrides.test.js +21 -0
  376. package/dist/tools/query/lifecycle.d.ts +7 -0
  377. package/dist/tools/query/lifecycle.js +112 -0
  378. package/dist/tools/query/query-ledger.d.ts +34 -0
  379. package/dist/tools/query/query-ledger.js +86 -0
  380. package/dist/tools/query/query-ledger.test.d.ts +1 -0
  381. package/dist/tools/query/query-ledger.test.js +73 -0
  382. package/dist/tools/query/reader-tool-helpers.d.ts +12 -0
  383. package/dist/tools/query/reader-tool-helpers.js +59 -0
  384. package/dist/tools/query/reader-tool-helpers.test.d.ts +1 -0
  385. package/dist/tools/query/reader-tool-helpers.test.js +49 -0
  386. package/dist/tools/query/result-normalizer.d.ts +27 -0
  387. package/dist/tools/query/result-normalizer.js +133 -0
  388. package/dist/tools/query/result-normalizer.test.d.ts +1 -0
  389. package/dist/tools/query/result-normalizer.test.js +41 -0
  390. package/dist/tools/query/wait-for-async.d.ts +10 -0
  391. package/dist/tools/query/wait-for-async.js +46 -0
  392. package/dist/tools/query/wait-for-async.test.d.ts +1 -0
  393. package/dist/tools/query/wait-for-async.test.js +45 -0
  394. package/dist/tools/registry.d.ts +225 -0
  395. package/dist/tools/registry.js +115 -0
  396. package/dist/tools/semantic/explore-helpers.d.ts +56 -0
  397. package/dist/tools/semantic/explore-helpers.js +115 -0
  398. package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
  399. package/dist/tools/semantic/explore-helpers.test.js +170 -0
  400. package/dist/tools/semantic/explores.d.ts +9 -0
  401. package/dist/tools/semantic/explores.js +80 -0
  402. package/dist/tools/semantic/metrics.d.ts +7 -0
  403. package/dist/tools/semantic/metrics.js +53 -0
  404. package/dist/tools/semantic/query.d.ts +6 -0
  405. package/dist/tools/semantic/query.js +42 -0
  406. package/dist/tools/semantic/schema-fields.d.ts +3 -0
  407. package/dist/tools/semantic/schema-fields.js +7 -0
  408. package/dist/tools/shared.d.ts +51 -15
  409. package/dist/tools/shared.js +171 -163
  410. package/dist/tools/shared.test.js +137 -184
  411. package/dist/tools/space/access.d.ts +66 -0
  412. package/dist/tools/space/access.js +322 -0
  413. package/dist/tools/space/access.test.d.ts +4 -0
  414. package/dist/tools/space/access.test.js +90 -0
  415. package/dist/transports/http-body.d.ts +5 -0
  416. package/dist/transports/http-body.js +50 -0
  417. package/dist/transports/http-request-utils.d.ts +2 -0
  418. package/dist/transports/http-request-utils.js +13 -0
  419. package/dist/transports/http-response.d.ts +6 -0
  420. package/dist/transports/http-response.js +56 -0
  421. package/dist/transports/session-store.d.ts +72 -0
  422. package/dist/transports/session-store.js +143 -0
  423. package/dist/transports/session-store.test.d.ts +1 -0
  424. package/dist/transports/session-store.test.js +111 -0
  425. package/dist/transports/streamable-http.d.ts +9 -0
  426. package/dist/transports/streamable-http.js +461 -0
  427. package/dist/transports/streamable-http.test.d.ts +1 -0
  428. package/dist/transports/streamable-http.test.js +100 -0
  429. package/package.json +26 -10
  430. package/dist/audit.d.ts +0 -6
  431. package/dist/config.d.ts +0 -47
  432. package/dist/config.js +0 -82
  433. package/dist/tools/ai-agents.d.ts +0 -6
  434. package/dist/tools/ai-agents.js +0 -388
  435. package/dist/tools/charts.d.ts +0 -6
  436. package/dist/tools/charts.js +0 -55
  437. package/dist/tools/content.d.ts +0 -6
  438. package/dist/tools/content.js +0 -37
  439. package/dist/tools/dashboards.d.ts +0 -6
  440. package/dist/tools/dashboards.js +0 -28
  441. package/dist/tools/explores.d.ts +0 -6
  442. package/dist/tools/explores.js +0 -65
  443. package/dist/tools/groups.d.ts +0 -6
  444. package/dist/tools/groups.js +0 -121
  445. package/dist/tools/metrics.d.ts +0 -6
  446. package/dist/tools/metrics.js +0 -45
  447. package/dist/tools/projects.d.ts +0 -6
  448. package/dist/tools/projects.js +0 -58
  449. package/dist/tools/query.d.ts +0 -6
  450. package/dist/tools/query.js +0 -34
  451. package/dist/tools/schedulers.d.ts +0 -6
  452. package/dist/tools/schedulers.js +0 -45
  453. package/dist/tools/spaces.d.ts +0 -6
  454. package/dist/tools/spaces.js +0 -128
  455. package/dist/tools/tags.d.ts +0 -6
  456. package/dist/tools/tags.js +0 -28
  457. package/dist/tools/users.d.ts +0 -6
  458. package/dist/tools/users.js +0 -50
  459. package/src/audit.ts +0 -6
  460. package/src/bin.ts +0 -58
  461. package/src/config.ts +0 -83
  462. package/src/errors.ts +0 -27
  463. package/src/http.ts +0 -187
  464. package/src/index.integration.test.ts +0 -57
  465. package/src/index.test.ts +0 -8
  466. package/src/index.ts +0 -31
  467. package/src/tools/ai-agents.ts +0 -759
  468. package/src/tools/charts.ts +0 -85
  469. package/src/tools/content.ts +0 -44
  470. package/src/tools/dashboards.ts +0 -25
  471. package/src/tools/explores.ts +0 -98
  472. package/src/tools/groups.ts +0 -180
  473. package/src/tools/index.ts +0 -35
  474. package/src/tools/metrics.ts +0 -42
  475. package/src/tools/projects.ts +0 -74
  476. package/src/tools/query.ts +0 -47
  477. package/src/tools/schedulers.ts +0 -42
  478. package/src/tools/shared.test.ts +0 -365
  479. package/src/tools/shared.ts +0 -274
  480. package/src/tools/spaces.ts +0 -217
  481. package/src/tools/tags.ts +0 -25
  482. package/src/tools/users.ts +0 -64
  483. package/tsconfig.json +0 -13
  484. /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
  485. /package/dist/{errors.js → server/errors.js} +0 -0
@@ -0,0 +1,15 @@
1
+ /**
2
+ * MCP runtime config: Lightdash client + audit path.
3
+ * Credentials: LIGHTDASH_URL, LIGHTDASH_API_KEY (stdio / shared-key).
4
+ * Process safety mode / allowlist / dry-run are not used on MCP (persona-first; ADR-0006).
5
+ */
6
+ import { LightdashClient } from '@lightdash-tools/client';
7
+ import type { PartialLightdashClientConfig } from '@lightdash-tools/client';
8
+ /**
9
+ * Warn once when operators set CLI guardrail env vars on MCP.
10
+ * Those vars do not scope MCP; persona toolIds + HTTP pin + RBAC do.
11
+ */
12
+ export declare function warnIgnoredCliGuardrailEnvVars(env?: NodeJS.ProcessEnv, warn?: (message: string) => void): void;
13
+ /** Undefined → audit log goes to stderr. */
14
+ export declare function getAuditLogPath(): string | undefined;
15
+ export declare function getClient(config?: PartialLightdashClientConfig): LightdashClient;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * MCP runtime config: Lightdash client + audit path.
4
+ * Credentials: LIGHTDASH_URL, LIGHTDASH_API_KEY (stdio / shared-key).
5
+ * Process safety mode / allowlist / dry-run are not used on MCP (persona-first; ADR-0006).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.warnIgnoredCliGuardrailEnvVars = warnIgnoredCliGuardrailEnvVars;
9
+ exports.getAuditLogPath = getAuditLogPath;
10
+ exports.getClient = getClient;
11
+ const client_1 = require("@lightdash-tools/client");
12
+ const common_1 = require("@lightdash-tools/common");
13
+ /** CLI-only guardrail env vars that MCP deliberately ignores (ADR-0008). */
14
+ const CLI_ONLY_GUARDRAIL_ENV_VARS = [
15
+ common_1.ENV_LIGHTDASH_TOOLS_SAFETY_MODE,
16
+ common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS,
17
+ common_1.ENV_LIGHTDASH_TOOLS_DRY_RUN,
18
+ ];
19
+ /**
20
+ * Warn once when operators set CLI guardrail env vars on MCP.
21
+ * Those vars do not scope MCP; persona toolIds + HTTP pin + RBAC do.
22
+ */
23
+ function warnIgnoredCliGuardrailEnvVars(env = process.env, warn = console.warn) {
24
+ const set = [];
25
+ for (const name of CLI_ONLY_GUARDRAIL_ENV_VARS) {
26
+ const value = name === common_1.ENV_LIGHTDASH_TOOLS_SAFETY_MODE
27
+ ? env.LIGHTDASH_TOOLS_SAFETY_MODE
28
+ : name === common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECTS
29
+ ? env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS
30
+ : env.LIGHTDASH_TOOLS_DRY_RUN;
31
+ if (value !== undefined && value !== '') {
32
+ set.push(name);
33
+ }
34
+ }
35
+ if (set.length === 0) {
36
+ return;
37
+ }
38
+ warn(`Warning: ${set.join(', ')} ${set.length === 1 ? 'is' : 'are'} set but ignored by MCP. ` +
39
+ 'Those variables apply to the CLI only. MCP authorization is persona toolIds + auth/RBAC + optional X-Lightdash-Project (ADR-0008).');
40
+ }
41
+ /** Undefined → audit log goes to stderr. */
42
+ function getAuditLogPath() {
43
+ return process.env.LIGHTDASH_TOOLS_AUDIT_LOG || undefined;
44
+ }
45
+ function getClient(config) {
46
+ const merged = (0, client_1.mergeConfig)(config);
47
+ return new client_1.LightdashClient(merged);
48
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const runtime_js_1 = require("./runtime.js");
5
+ (0, vitest_1.describe)('config/runtime', () => {
6
+ const originalAuditLog = process.env.LIGHTDASH_TOOLS_AUDIT_LOG;
7
+ const originalSafety = process.env.LIGHTDASH_TOOLS_SAFETY_MODE;
8
+ const originalAllowlist = process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
9
+ const originalDryRun = process.env.LIGHTDASH_TOOLS_DRY_RUN;
10
+ (0, vitest_1.beforeEach)(() => {
11
+ delete process.env.LIGHTDASH_TOOLS_AUDIT_LOG;
12
+ delete process.env.LIGHTDASH_TOOLS_SAFETY_MODE;
13
+ delete process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS;
14
+ delete process.env.LIGHTDASH_TOOLS_DRY_RUN;
15
+ });
16
+ (0, vitest_1.afterEach)(() => {
17
+ const restore = (key, value) => {
18
+ if (value === undefined) {
19
+ delete process.env[key];
20
+ }
21
+ else {
22
+ process.env[key] = value;
23
+ }
24
+ };
25
+ restore('LIGHTDASH_TOOLS_AUDIT_LOG', originalAuditLog);
26
+ restore('LIGHTDASH_TOOLS_SAFETY_MODE', originalSafety);
27
+ restore('LIGHTDASH_TOOLS_ALLOWED_PROJECTS', originalAllowlist);
28
+ restore('LIGHTDASH_TOOLS_DRY_RUN', originalDryRun);
29
+ });
30
+ (0, vitest_1.describe)('getAuditLogPath', () => {
31
+ (0, vitest_1.it)('should return undefined when env is unset', () => {
32
+ (0, vitest_1.expect)((0, runtime_js_1.getAuditLogPath)()).toBeUndefined();
33
+ });
34
+ (0, vitest_1.it)('should return path when env is set', () => {
35
+ process.env.LIGHTDASH_TOOLS_AUDIT_LOG = '/tmp/audit.log';
36
+ (0, vitest_1.expect)((0, runtime_js_1.getAuditLogPath)()).toBe('/tmp/audit.log');
37
+ });
38
+ (0, vitest_1.it)('should return undefined when env is empty string', () => {
39
+ process.env.LIGHTDASH_TOOLS_AUDIT_LOG = '';
40
+ (0, vitest_1.expect)((0, runtime_js_1.getAuditLogPath)()).toBeUndefined();
41
+ });
42
+ });
43
+ (0, vitest_1.describe)('warnIgnoredCliGuardrailEnvVars', () => {
44
+ (0, vitest_1.it)('does not warn when CLI guardrail env vars are unset', () => {
45
+ const warn = vitest_1.vi.fn();
46
+ (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)(process.env, warn);
47
+ (0, vitest_1.expect)(warn).not.toHaveBeenCalled();
48
+ });
49
+ (0, vitest_1.it)('warns when SAFETY_MODE is set', () => {
50
+ const warn = vitest_1.vi.fn();
51
+ process.env.LIGHTDASH_TOOLS_SAFETY_MODE = 'read-only';
52
+ (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)(process.env, warn);
53
+ (0, vitest_1.expect)(warn).toHaveBeenCalledWith(vitest_1.expect.stringContaining('LIGHTDASH_TOOLS_SAFETY_MODE'));
54
+ (0, vitest_1.expect)(warn).toHaveBeenCalledWith(vitest_1.expect.stringContaining('ignored by MCP'));
55
+ });
56
+ (0, vitest_1.it)('lists all set CLI-only vars in one warning', () => {
57
+ const warn = vitest_1.vi.fn();
58
+ process.env.LIGHTDASH_TOOLS_SAFETY_MODE = 'read-only';
59
+ process.env.LIGHTDASH_TOOLS_ALLOWED_PROJECTS = 'uuid';
60
+ process.env.LIGHTDASH_TOOLS_DRY_RUN = '1';
61
+ (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)(process.env, warn);
62
+ (0, vitest_1.expect)(warn).toHaveBeenCalledTimes(1);
63
+ const message = warn.mock.calls[0][0];
64
+ (0, vitest_1.expect)(message).toContain('LIGHTDASH_TOOLS_SAFETY_MODE');
65
+ (0, vitest_1.expect)(message).toContain('LIGHTDASH_TOOLS_ALLOWED_PROJECTS');
66
+ (0, vitest_1.expect)(message).toContain('LIGHTDASH_TOOLS_DRY_RUN');
67
+ });
68
+ });
69
+ });
@@ -0,0 +1,3 @@
1
+ import type { McpHttpConfig } from './load-mcp-config.js';
2
+ /** Shared base `McpHttpConfig` for MCP package unit/integration tests. */
3
+ export declare function makeTestMcpHttpConfig(overrides?: Partial<McpHttpConfig>): McpHttpConfig;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeTestMcpHttpConfig = makeTestMcpHttpConfig;
4
+ /** Shared base `McpHttpConfig` for MCP package unit/integration tests. */
5
+ function makeTestMcpHttpConfig(overrides) {
6
+ return Object.assign({ lightdashUrl: 'https://app.lightdash.cloud', host: '127.0.0.1', port: 3100, publicUrl: 'https://mcp.example.com', mcpPath: '/semantic-layer/v1/mcp', authMode: 'lightdash-oauth', allowedOrigins: [], maxBodyBytes: 1024, sessionTtlMs: 60000, maxSessions: 10, maxSessionsPerSubject: 10, sessionCleanupMs: 60000, requiredScopes: ['mcp:read'], scopesSupported: ['mcp:read', 'mcp:write'], validateToken: true, tokenValidationCacheTtlMs: 30000 }, overrides);
7
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Detect MCP client form-elicitation capability (ADR-0015).
3
+ */
4
+ import type { ClientCapabilities, ServerContext } from '@modelcontextprotocol/server';
5
+ /**
6
+ * True when the client declared form elicitation.
7
+ *
8
+ * - 2026-07-28: prefer per-request envelope under CLIENT_CAPABILITIES_META_KEY.
9
+ * - 2025-era (current @modelcontextprotocol/server@2.0.0 default): fall back to
10
+ * initialize-declared capabilities from `Server.getClientCapabilities()`.
11
+ * Empty `elicitation: {}` is equivalent to form-only support per the spec.
12
+ */
13
+ export declare function supportsFormElicitation(serverContext: ServerContext | undefined, initializeCapabilities?: ClientCapabilities | undefined): boolean;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * Detect MCP client form-elicitation capability (ADR-0015).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.supportsFormElicitation = supportsFormElicitation;
7
+ const server_1 = require("@modelcontextprotocol/server");
8
+ function elicitationSupportsForm(elicitation) {
9
+ // Empty elicitation object ≡ form mode only (spec backwards-compat).
10
+ if (Object.keys(elicitation).length === 0) {
11
+ return true;
12
+ }
13
+ return elicitation.form !== undefined;
14
+ }
15
+ /**
16
+ * True when the client declared form elicitation.
17
+ *
18
+ * - 2026-07-28: prefer per-request envelope under CLIENT_CAPABILITIES_META_KEY.
19
+ * - 2025-era (current @modelcontextprotocol/server@2.0.0 default): fall back to
20
+ * initialize-declared capabilities from `Server.getClientCapabilities()`.
21
+ * Empty `elicitation: {}` is equivalent to form-only support per the spec.
22
+ */
23
+ function supportsFormElicitation(serverContext, initializeCapabilities) {
24
+ if (serverContext === null || serverContext === void 0 ? void 0 : serverContext.mcpReq) {
25
+ const envelope = serverContext.mcpReq.envelope;
26
+ const fromEnvelope = envelope === undefined
27
+ ? undefined
28
+ : Reflect.get(envelope, server_1.CLIENT_CAPABILITIES_META_KEY);
29
+ if ((fromEnvelope === null || fromEnvelope === void 0 ? void 0 : fromEnvelope.elicitation) !== undefined) {
30
+ return elicitationSupportsForm(fromEnvelope.elicitation);
31
+ }
32
+ }
33
+ if ((initializeCapabilities === null || initializeCapabilities === void 0 ? void 0 : initializeCapabilities.elicitation) !== undefined) {
34
+ return elicitationSupportsForm(initializeCapabilities.elicitation);
35
+ }
36
+ return false;
37
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
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 capability_js_1 = require("./capability.js");
6
+ function serverContextWithEnvelopeCaps(elicitation) {
7
+ const envelope = elicitation === undefined ? {} : { [server_1.CLIENT_CAPABILITIES_META_KEY]: { elicitation } };
8
+ return {
9
+ mcpReq: {
10
+ envelope,
11
+ },
12
+ };
13
+ }
14
+ (0, vitest_1.describe)('supportsFormElicitation', () => {
15
+ (0, vitest_1.it)('returns false when ServerContext and initialize caps are missing', () => {
16
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(undefined)).toBe(false);
17
+ });
18
+ (0, vitest_1.it)('returns false when elicitation capability is absent from envelope', () => {
19
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(serverContextWithEnvelopeCaps(undefined))).toBe(false);
20
+ });
21
+ (0, vitest_1.it)('returns true for empty elicitation object on the envelope (form-only backwards-compat)', () => {
22
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(serverContextWithEnvelopeCaps({}))).toBe(true);
23
+ });
24
+ (0, vitest_1.it)('returns true when form mode is declared on the envelope', () => {
25
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(serverContextWithEnvelopeCaps({ form: {} }))).toBe(true);
26
+ });
27
+ (0, vitest_1.it)('returns false when only url mode is declared on the envelope', () => {
28
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(serverContextWithEnvelopeCaps({ url: {} }))).toBe(false);
29
+ });
30
+ (0, vitest_1.it)('falls back to initialize-declared capabilities when envelope has no elicitation', () => {
31
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(serverContextWithEnvelopeCaps(undefined), {
32
+ elicitation: { form: {} },
33
+ })).toBe(true);
34
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(undefined, {
35
+ elicitation: {},
36
+ })).toBe(true);
37
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(undefined, {
38
+ elicitation: { url: {} },
39
+ })).toBe(false);
40
+ });
41
+ (0, vitest_1.it)('prefers envelope over initialize caps when both are present', () => {
42
+ (0, vitest_1.expect)((0, capability_js_1.supportsFormElicitation)(serverContextWithEnvelopeCaps({ url: {} }), {
43
+ elicitation: { form: {} },
44
+ })).toBe(false);
45
+ });
46
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * One-shot claim for non-idempotent elicitation confirmations (e.g. promote).
3
+ * Memory Map by default; Redis SET NX when LIGHTDASH_TOOLS_MCP_STORE=redis (ADR-0016).
4
+ * Releases are compare-and-delete so a late cleanup cannot erase a newer claimant.
5
+ */
6
+ import type { DestructiveRequestState } from './types.js';
7
+ export type ConfirmationClaimHandle = {
8
+ key: string;
9
+ token: string;
10
+ };
11
+ /** Stable key for a verified confirmation binding. */
12
+ export declare function confirmationClaimKey(state: DestructiveRequestState): string;
13
+ /**
14
+ * Claim a confirmation key for one apply. Returns undefined if already claimed
15
+ * within TTL (concurrent/replayed accept).
16
+ */
17
+ export declare function claimConfirmationKey(key: string, ttlMs?: number): Promise<ConfirmationClaimHandle | undefined>;
18
+ /** Release only if this handle still owns the claim (compare-and-delete). */
19
+ export declare function releaseConfirmationKey(handle: ConfirmationClaimHandle): Promise<void>;
20
+ /** Reset memory claims (tests only). */
21
+ export declare function resetConfirmationClaimsForTests(): void;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * One-shot claim for non-idempotent elicitation confirmations (e.g. promote).
4
+ * Memory Map by default; Redis SET NX when LIGHTDASH_TOOLS_MCP_STORE=redis (ADR-0016).
5
+ * Releases are compare-and-delete so a late cleanup cannot erase a newer claimant.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.confirmationClaimKey = confirmationClaimKey;
9
+ exports.claimConfirmationKey = claimConfirmationKey;
10
+ exports.releaseConfirmationKey = releaseConfirmationKey;
11
+ exports.resetConfirmationClaimsForTests = resetConfirmationClaimsForTests;
12
+ const node_crypto_1 = require("node:crypto");
13
+ const config_js_1 = require("../store/config.js");
14
+ const redis_client_js_1 = require("../store/redis-client.js");
15
+ /** Longer than requestState TTL so an in-flight promote cannot be reclaimed mid-call. */
16
+ const DEFAULT_TTL_MS = 30 * 60 * 1000;
17
+ const REDIS_KEY_PREFIX = 'lightdash-mcp:confirm-claim:';
18
+ /** Compare-and-delete: only remove if the value still matches our claim token. */
19
+ const REDIS_RELEASE_LUA = `
20
+ if redis.call('GET', KEYS[1]) == ARGV[1] then
21
+ return redis.call('DEL', KEYS[1])
22
+ end
23
+ return 0
24
+ `;
25
+ const memoryClaims = new Map();
26
+ function purgeExpiredMemory(now) {
27
+ for (const [key, claim] of memoryClaims) {
28
+ if (claim.expiresAt <= now) {
29
+ memoryClaims.delete(key);
30
+ }
31
+ }
32
+ }
33
+ function redisClaimKey(key) {
34
+ return `${REDIS_KEY_PREFIX}${key}`;
35
+ }
36
+ /** Stable key for a verified confirmation binding. */
37
+ function confirmationClaimKey(state) {
38
+ return [
39
+ state.sessionId,
40
+ state.operationId,
41
+ state.resourceType,
42
+ state.resourceId,
43
+ state.projectUuid,
44
+ state.preconditionDigest,
45
+ ].join('\0');
46
+ }
47
+ /**
48
+ * Claim a confirmation key for one apply. Returns undefined if already claimed
49
+ * within TTL (concurrent/replayed accept).
50
+ */
51
+ async function claimConfirmationKey(key, ttlMs = DEFAULT_TTL_MS) {
52
+ const token = (0, node_crypto_1.randomUUID)();
53
+ const config = (0, config_js_1.resolveEphemeralStoreConfig)();
54
+ if (config.backend === 'redis') {
55
+ const redis = await (0, redis_client_js_1.getSharedRedisClient)(config);
56
+ const result = await redis.set(redisClaimKey(key), token, { NX: true, PX: ttlMs });
57
+ return result === 'OK' ? { key, token } : undefined;
58
+ }
59
+ const now = Date.now();
60
+ purgeExpiredMemory(now);
61
+ const existing = memoryClaims.get(key);
62
+ if (existing !== undefined && existing.expiresAt > now) {
63
+ return undefined;
64
+ }
65
+ memoryClaims.set(key, { token, expiresAt: now + ttlMs });
66
+ return { key, token };
67
+ }
68
+ /** Release only if this handle still owns the claim (compare-and-delete). */
69
+ async function releaseConfirmationKey(handle) {
70
+ const config = (0, config_js_1.resolveEphemeralStoreConfig)();
71
+ if (config.backend === 'redis') {
72
+ const redis = await (0, redis_client_js_1.getSharedRedisClient)(config);
73
+ await redis.eval(REDIS_RELEASE_LUA, {
74
+ keys: [redisClaimKey(handle.key)],
75
+ arguments: [handle.token],
76
+ });
77
+ return;
78
+ }
79
+ const current = memoryClaims.get(handle.key);
80
+ if ((current === null || current === void 0 ? void 0 : current.token) === handle.token) {
81
+ memoryClaims.delete(handle.key);
82
+ }
83
+ }
84
+ /** Reset memory claims (tests only). */
85
+ function resetConfirmationClaimsForTests() {
86
+ memoryClaims.clear();
87
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const confirmation_claim_js_1 = require("./confirmation-claim.js");
5
+ const state = {
6
+ operationId: 'content-governance.dashboards.promote',
7
+ resourceType: 'dashboard',
8
+ resourceId: 'd1',
9
+ projectUuid: 'p1',
10
+ preconditionDigest: 'digest-a',
11
+ sessionId: 's1',
12
+ resourceName: 'Board',
13
+ };
14
+ (0, vitest_1.describe)('confirmation-claim', () => {
15
+ (0, vitest_1.afterEach)(() => {
16
+ (0, confirmation_claim_js_1.resetConfirmationClaimsForTests)();
17
+ });
18
+ (0, vitest_1.it)('allows the first claim and rejects a concurrent replay', async () => {
19
+ const key = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
20
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toEqual(vitest_1.expect.objectContaining({ key, token: vitest_1.expect.any(String) }));
21
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toBeUndefined();
22
+ });
23
+ (0, vitest_1.it)('releases a claim so a confirmed no-write failure can retry', async () => {
24
+ const key = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
25
+ const handle = await (0, confirmation_claim_js_1.claimConfirmationKey)(key);
26
+ (0, vitest_1.expect)(handle).toBeDefined();
27
+ await (0, confirmation_claim_js_1.releaseConfirmationKey)(handle);
28
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toEqual(vitest_1.expect.objectContaining({ key, token: vitest_1.expect.any(String) }));
29
+ });
30
+ (0, vitest_1.it)('does not release when the handle token no longer owns the claim', async () => {
31
+ const key = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
32
+ const first = await (0, confirmation_claim_js_1.claimConfirmationKey)(key);
33
+ (0, vitest_1.expect)(first).toBeDefined();
34
+ // Simulate TTL expiry + re-claim by a newer request.
35
+ (0, confirmation_claim_js_1.resetConfirmationClaimsForTests)();
36
+ const second = await (0, confirmation_claim_js_1.claimConfirmationKey)(key);
37
+ (0, vitest_1.expect)(second).toBeDefined();
38
+ await (0, confirmation_claim_js_1.releaseConfirmationKey)(first);
39
+ // Newer claim must still block a third acquire.
40
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toBeUndefined();
41
+ await (0, confirmation_claim_js_1.releaseConfirmationKey)(second);
42
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(key)).toBeDefined();
43
+ });
44
+ (0, vitest_1.it)('treats distinct precondition digests as distinct claims', async () => {
45
+ const keyA = (0, confirmation_claim_js_1.confirmationClaimKey)(state);
46
+ const keyB = (0, confirmation_claim_js_1.confirmationClaimKey)(Object.assign(Object.assign({}, state), { preconditionDigest: 'digest-b' }));
47
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(keyA)).toBeDefined();
48
+ (0, vitest_1.expect)(await (0, confirmation_claim_js_1.claimConfirmationKey)(keyB)).toBeDefined();
49
+ });
50
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Flat form schemas and message builders for elicitation-gated mutations
3
+ * (ADR-0015 soft-delete, ADR-0017 dashboard promote).
4
+ */
5
+ import type { ConfirmationTarget } from './types.js';
6
+ export type DeleteConfirmFormContent = {
7
+ decision: 'confirm_delete' | 'do_not_delete';
8
+ confirmationText: string;
9
+ };
10
+ export type PromoteConfirmFormContent = {
11
+ decision: 'confirm_promote' | 'do_not_promote';
12
+ confirmationText: string;
13
+ };
14
+ /** Flat JSON Schema for form-mode elicitation (primitives only). */
15
+ export declare const DELETE_CONFIRM_FORM_SCHEMA: {
16
+ type: "object";
17
+ properties: {
18
+ decision: {
19
+ type: "string";
20
+ title: string;
21
+ description: string;
22
+ enum: string[];
23
+ enumNames: string[];
24
+ default: string;
25
+ };
26
+ confirmationText: {
27
+ type: "string";
28
+ title: string;
29
+ description: string;
30
+ };
31
+ };
32
+ required: string[];
33
+ };
34
+ export declare const PROMOTE_CONFIRM_FORM_SCHEMA: {
35
+ type: "object";
36
+ properties: {
37
+ decision: {
38
+ type: "string";
39
+ title: string;
40
+ description: string;
41
+ enum: string[];
42
+ enumNames: string[];
43
+ default: string;
44
+ };
45
+ confirmationText: {
46
+ type: "string";
47
+ title: string;
48
+ description: string;
49
+ };
50
+ };
51
+ required: string[];
52
+ };
53
+ export type ConfirmFormSchema = typeof DELETE_CONFIRM_FORM_SCHEMA | typeof PROMOTE_CONFIRM_FORM_SCHEMA;
54
+ export declare function normalizeResourceName(name: string): string;
55
+ export declare function buildDeleteConfirmationMessage(target: ConfirmationTarget): string;
56
+ export declare function buildPromoteConfirmationMessage(target: ConfirmationTarget): string;
57
+ export declare function isAcceptedDeleteForm(content: DeleteConfirmFormContent | undefined, expectedName: string): content is DeleteConfirmFormContent;
58
+ export declare function isAcceptedPromoteForm(content: PromoteConfirmFormContent | undefined, expectedName: string): content is PromoteConfirmFormContent;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Flat form schemas and message builders for elicitation-gated mutations
4
+ * (ADR-0015 soft-delete, ADR-0017 dashboard promote).
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PROMOTE_CONFIRM_FORM_SCHEMA = exports.DELETE_CONFIRM_FORM_SCHEMA = void 0;
8
+ exports.normalizeResourceName = normalizeResourceName;
9
+ exports.buildDeleteConfirmationMessage = buildDeleteConfirmationMessage;
10
+ exports.buildPromoteConfirmationMessage = buildPromoteConfirmationMessage;
11
+ exports.isAcceptedDeleteForm = isAcceptedDeleteForm;
12
+ exports.isAcceptedPromoteForm = isAcceptedPromoteForm;
13
+ /** Flat JSON Schema for form-mode elicitation (primitives only). */
14
+ exports.DELETE_CONFIRM_FORM_SCHEMA = {
15
+ type: 'object',
16
+ properties: {
17
+ decision: {
18
+ type: 'string',
19
+ title: 'Delete resource?',
20
+ description: 'This soft-deletes the specified Lightdash resource (restorable from trash).',
21
+ enum: ['confirm_delete', 'do_not_delete'],
22
+ enumNames: ['Delete (soft-delete)', 'Keep resource'],
23
+ default: 'do_not_delete',
24
+ },
25
+ confirmationText: {
26
+ type: 'string',
27
+ title: 'Type the resource name',
28
+ description: 'Enter the exact resource name shown in the message.',
29
+ },
30
+ },
31
+ // Mutable `string[]` required by MCP form elicitation schema typing.
32
+ required: ['decision', 'confirmationText'],
33
+ };
34
+ exports.PROMOTE_CONFIRM_FORM_SCHEMA = {
35
+ type: 'object',
36
+ properties: {
37
+ decision: {
38
+ type: 'string',
39
+ title: 'Promote dashboard?',
40
+ description: 'This promotes the dashboard (and nested charts/spaces/data apps) to the configured upstream project.',
41
+ enum: ['confirm_promote', 'do_not_promote'],
42
+ enumNames: ['Promote to upstream', 'Do not promote'],
43
+ default: 'do_not_promote',
44
+ },
45
+ confirmationText: {
46
+ type: 'string',
47
+ title: 'Type the dashboard name',
48
+ description: 'Enter the exact dashboard name shown in the message.',
49
+ },
50
+ },
51
+ required: ['decision', 'confirmationText'],
52
+ };
53
+ function normalizeResourceName(name) {
54
+ return name.trim().replace(/\s+/g, ' ');
55
+ }
56
+ function appendTargetLines(lines, target) {
57
+ var _a;
58
+ lines.push(`Name: ${target.resourceName}`);
59
+ lines.push(`${target.resourceType === 'chart' ? 'Chart' : 'Dashboard'} UUID/slug: ${target.resourceId}`);
60
+ lines.push(`Project UUID: ${target.projectUuid}`);
61
+ if (target.location) {
62
+ lines.push(`Space: ${target.location}`);
63
+ }
64
+ if (target.updatedAt) {
65
+ lines.push(`Updated at: ${target.updatedAt}`);
66
+ }
67
+ for (const detail of (_a = target.details) !== null && _a !== void 0 ? _a : []) {
68
+ lines.push(detail);
69
+ }
70
+ for (const consequence of target.consequences) {
71
+ lines.push(consequence);
72
+ }
73
+ }
74
+ function buildDeleteConfirmationMessage(target) {
75
+ const lines = [`Confirm soft-deletion of this Lightdash ${target.resourceType}.`];
76
+ appendTargetLines(lines, target);
77
+ lines.push('Type the exact resource name to confirm. Soft-deleted items can be restored from trash.');
78
+ return lines.join('\n');
79
+ }
80
+ function buildPromoteConfirmationMessage(target) {
81
+ const lines = [
82
+ 'Confirm promotion of this Lightdash dashboard to its configured upstream project.',
83
+ ];
84
+ appendTargetLines(lines, target);
85
+ lines.push('Type the exact dashboard name to confirm. Nested charts, spaces, and data apps may be created or overwritten upstream.');
86
+ return lines.join('\n');
87
+ }
88
+ function isAcceptedConfirmForm(content, acceptDecision, expectedName) {
89
+ if (!content || content.decision !== acceptDecision) {
90
+ return false;
91
+ }
92
+ return normalizeResourceName(content.confirmationText) === normalizeResourceName(expectedName);
93
+ }
94
+ function isAcceptedDeleteForm(content, expectedName) {
95
+ return isAcceptedConfirmForm(content, 'confirm_delete', expectedName);
96
+ }
97
+ function isAcceptedPromoteForm(content, expectedName) {
98
+ return isAcceptedConfirmForm(content, 'confirm_promote', expectedName);
99
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const confirmation_js_1 = require("./confirmation.js");
5
+ const target = {
6
+ operation: 'delete',
7
+ resourceType: 'chart',
8
+ resourceId: 'chart-1',
9
+ resourceName: 'Revenue KPI',
10
+ projectUuid: '11111111-1111-1111-1111-111111111111',
11
+ location: 'Finance',
12
+ updatedAt: '2026-08-01T00:00:00.000Z',
13
+ consequences: ['Hidden from normal lists.', 'Restorable from trash.'],
14
+ };
15
+ const promoteTarget = {
16
+ operation: 'promote',
17
+ resourceType: 'dashboard',
18
+ resourceId: 'dash-1',
19
+ resourceName: 'Exec Overview',
20
+ projectUuid: '11111111-1111-1111-1111-111111111111',
21
+ location: 'Executive',
22
+ updatedAt: '2026-08-01T00:00:00.000Z',
23
+ details: ['Charts: 2 create, 1 update'],
24
+ consequences: ['Nested charts may be overwritten upstream.'],
25
+ };
26
+ (0, vitest_1.describe)('normalizeResourceName', () => {
27
+ (0, vitest_1.it)('trims and collapses internal whitespace', () => {
28
+ (0, vitest_1.expect)((0, confirmation_js_1.normalizeResourceName)(' Revenue KPI ')).toBe('Revenue KPI');
29
+ });
30
+ });
31
+ (0, vitest_1.describe)('buildDeleteConfirmationMessage', () => {
32
+ (0, vitest_1.it)('includes identity fields and consequences', () => {
33
+ const message = (0, confirmation_js_1.buildDeleteConfirmationMessage)(target);
34
+ (0, vitest_1.expect)(message).toContain('Confirm soft-deletion of this Lightdash chart.');
35
+ (0, vitest_1.expect)(message).toContain('Name: Revenue KPI');
36
+ (0, vitest_1.expect)(message).toContain('Chart UUID/slug: chart-1');
37
+ (0, vitest_1.expect)(message).toContain('Project UUID: 11111111-1111-1111-1111-111111111111');
38
+ (0, vitest_1.expect)(message).toContain('Space: Finance');
39
+ (0, vitest_1.expect)(message).toContain('Updated at: 2026-08-01T00:00:00.000Z');
40
+ (0, vitest_1.expect)(message).toContain('Hidden from normal lists.');
41
+ (0, vitest_1.expect)(message).toContain('Type the exact resource name to confirm');
42
+ });
43
+ });
44
+ (0, vitest_1.describe)('isAcceptedDeleteForm', () => {
45
+ (0, vitest_1.it)('rejects missing content', () => {
46
+ (0, vitest_1.expect)((0, confirmation_js_1.isAcceptedDeleteForm)(undefined, 'Revenue KPI')).toBe(false);
47
+ });
48
+ (0, vitest_1.it)('rejects decline decisions', () => {
49
+ (0, vitest_1.expect)((0, confirmation_js_1.isAcceptedDeleteForm)({ decision: 'do_not_delete', confirmationText: 'Revenue KPI' }, 'Revenue KPI')).toBe(false);
50
+ });
51
+ (0, vitest_1.it)('rejects mismatched confirmation text', () => {
52
+ (0, vitest_1.expect)((0, confirmation_js_1.isAcceptedDeleteForm)({ decision: 'confirm_delete', confirmationText: 'Wrong Name' }, 'Revenue KPI')).toBe(false);
53
+ });
54
+ (0, vitest_1.it)('accepts confirm_delete with normalized matching name', () => {
55
+ (0, vitest_1.expect)((0, confirmation_js_1.isAcceptedDeleteForm)({ decision: 'confirm_delete', confirmationText: ' Revenue KPI ' }, 'Revenue KPI')).toBe(true);
56
+ });
57
+ });
58
+ (0, vitest_1.describe)('buildPromoteConfirmationMessage', () => {
59
+ (0, vitest_1.it)('includes promoteDiff details and upstream consequences', () => {
60
+ const message = (0, confirmation_js_1.buildPromoteConfirmationMessage)(promoteTarget);
61
+ (0, vitest_1.expect)(message).toContain('Confirm promotion of this Lightdash dashboard');
62
+ (0, vitest_1.expect)(message).toContain('Name: Exec Overview');
63
+ (0, vitest_1.expect)(message).toContain('Charts: 2 create, 1 update');
64
+ (0, vitest_1.expect)(message).toContain('Nested charts may be overwritten upstream.');
65
+ (0, vitest_1.expect)(message).toContain('Type the exact dashboard name to confirm');
66
+ });
67
+ });
68
+ (0, vitest_1.describe)('isAcceptedPromoteForm', () => {
69
+ (0, vitest_1.it)('rejects decline decisions', () => {
70
+ (0, vitest_1.expect)((0, confirmation_js_1.isAcceptedPromoteForm)({ decision: 'do_not_promote', confirmationText: 'Exec Overview' }, 'Exec Overview')).toBe(false);
71
+ });
72
+ (0, vitest_1.it)('accepts confirm_promote with matching name', () => {
73
+ (0, vitest_1.expect)((0, confirmation_js_1.isAcceptedPromoteForm)({ decision: 'confirm_promote', confirmationText: 'Exec Overview' }, 'Exec Overview')).toBe(true);
74
+ });
75
+ });