@lightdash-tools/mcp 0.7.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 (268) hide show
  1. package/README.md +98 -26
  2. package/dist/auth/oauth-broker/pending-store.d.ts +70 -19
  3. package/dist/auth/oauth-broker/pending-store.js +53 -26
  4. package/dist/auth/oauth-broker/pending-store.test.d.ts +6 -0
  5. package/dist/auth/oauth-broker/pending-store.test.js +146 -0
  6. package/dist/auth/oauth-broker/routes.d.ts +6 -2
  7. package/dist/auth/oauth-broker/routes.js +26 -21
  8. package/dist/auth/oauth-broker/routes.test.js +32 -27
  9. package/dist/auth/resource-server/www-authenticate.test.js +12 -6
  10. package/dist/bin.js +23 -2
  11. package/dist/config/env.d.ts +7 -0
  12. package/dist/config/env.js +8 -1
  13. package/dist/config/load-mcp-config.js +4 -0
  14. package/dist/config/load-mcp-config.test.js +7 -0
  15. package/dist/config/normalize-url.test.js +13 -7
  16. package/dist/destructive/capability.d.ts +13 -0
  17. package/dist/destructive/capability.js +37 -0
  18. package/dist/destructive/capability.test.d.ts +1 -0
  19. package/dist/destructive/capability.test.js +46 -0
  20. package/dist/destructive/confirmation-claim.d.ts +21 -0
  21. package/dist/destructive/confirmation-claim.js +87 -0
  22. package/dist/destructive/confirmation-claim.test.d.ts +1 -0
  23. package/dist/destructive/confirmation-claim.test.js +50 -0
  24. package/dist/destructive/confirmation.d.ts +58 -0
  25. package/dist/destructive/confirmation.js +99 -0
  26. package/dist/destructive/confirmation.test.d.ts +1 -0
  27. package/dist/destructive/confirmation.test.js +75 -0
  28. package/dist/destructive/content-promote.d.ts +8 -0
  29. package/dist/destructive/content-promote.js +144 -0
  30. package/dist/destructive/content-soft-delete.d.ts +7 -0
  31. package/dist/destructive/content-soft-delete.js +106 -0
  32. package/dist/destructive/destructive-contract.test.d.ts +1 -0
  33. package/dist/destructive/destructive-contract.test.js +269 -0
  34. package/dist/destructive/precondition.d.ts +14 -0
  35. package/dist/destructive/precondition.js +31 -0
  36. package/dist/destructive/precondition.test.d.ts +1 -0
  37. package/dist/destructive/precondition.test.js +72 -0
  38. package/dist/destructive/promote-contract.test.d.ts +1 -0
  39. package/dist/destructive/promote-contract.test.js +339 -0
  40. package/dist/destructive/register-destructive-tool.d.ts +54 -0
  41. package/dist/destructive/register-destructive-tool.js +301 -0
  42. package/dist/destructive/request-state.d.ts +16 -0
  43. package/dist/destructive/request-state.js +76 -0
  44. package/dist/destructive/types.d.ts +64 -0
  45. package/dist/destructive/types.js +10 -0
  46. package/dist/governance/mcp-client-session.d.ts +9 -0
  47. package/dist/governance/mcp-client-session.js +30 -0
  48. package/dist/governance/mcp-client-session.test.d.ts +1 -0
  49. package/dist/governance/mcp-client-session.test.js +31 -0
  50. package/dist/governance/project-scope.d.ts +38 -0
  51. package/dist/governance/project-scope.js +79 -0
  52. package/dist/governance/project-scope.test.d.ts +4 -0
  53. package/dist/governance/project-scope.test.js +103 -0
  54. package/dist/http.integration.test.js +34 -0
  55. package/dist/index.js +1 -1
  56. package/dist/personas/content-developer/v1/index.d.ts +10 -0
  57. package/dist/personas/content-developer/v1/index.js +51 -0
  58. package/dist/personas/content-developer/v1/prompts.d.ts +5 -0
  59. package/dist/personas/content-developer/v1/prompts.js +138 -0
  60. package/dist/personas/content-developer/v1/prompts.test.d.ts +4 -0
  61. package/dist/personas/content-developer/v1/prompts.test.js +75 -0
  62. package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +15 -0
  63. package/dist/personas/content-developer/v1/resources/playbooks/core.md +63 -0
  64. package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +55 -0
  65. package/dist/personas/content-developer/v1/resources/playbooks/index.md +13 -0
  66. package/dist/personas/content-developer/v1/resources/playbooks.d.ts +10 -0
  67. package/dist/personas/content-developer/v1/resources/playbooks.js +44 -0
  68. package/dist/personas/content-governance/v1/index.d.ts +9 -0
  69. package/dist/personas/content-governance/v1/index.js +29 -0
  70. package/dist/personas/content-governance/v1/prompts.d.ts +5 -0
  71. package/dist/personas/content-governance/v1/prompts.js +87 -0
  72. package/dist/personas/content-governance/v1/prompts.test.d.ts +4 -0
  73. package/dist/personas/content-governance/v1/prompts.test.js +75 -0
  74. package/dist/personas/content-governance/v1/resources/playbooks/charts.md +29 -0
  75. package/dist/personas/content-governance/v1/resources/playbooks/core.md +52 -0
  76. package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +48 -0
  77. package/dist/personas/content-governance/v1/resources/playbooks/index.md +13 -0
  78. package/dist/personas/content-governance/v1/resources/playbooks.d.ts +10 -0
  79. package/dist/personas/content-governance/v1/resources/playbooks.js +41 -0
  80. package/dist/personas/content-reader/v1/index.d.ts +8 -0
  81. package/dist/personas/content-reader/v1/index.js +37 -0
  82. package/dist/personas/content-reader/v1/prompts.d.ts +5 -0
  83. package/dist/personas/content-reader/v1/prompts.js +128 -0
  84. package/dist/personas/content-reader/v1/prompts.test.d.ts +4 -0
  85. package/dist/personas/content-reader/v1/prompts.test.js +25 -0
  86. package/dist/personas/content-reader/v1/resources/playbooks/compare.md +21 -0
  87. package/dist/personas/content-reader/v1/resources/playbooks/core.md +40 -0
  88. package/dist/personas/content-reader/v1/resources/playbooks/discover.md +13 -0
  89. package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +19 -0
  90. package/dist/personas/content-reader/v1/resources/playbooks/index.md +14 -0
  91. package/dist/personas/content-reader/v1/resources/playbooks.d.ts +10 -0
  92. package/dist/personas/content-reader/v1/resources/playbooks.js +49 -0
  93. package/dist/personas/index.d.ts +3 -0
  94. package/dist/personas/index.js +26 -10
  95. package/dist/personas/index.test.js +77 -26
  96. package/dist/personas/lib/playbook-resources.d.ts +79 -0
  97. package/dist/personas/lib/playbook-resources.js +165 -0
  98. package/dist/personas/organization-audit/v1/index.js +2 -2
  99. package/dist/personas/organization-audit/v1/prompts.js +14 -33
  100. package/dist/personas/organization-audit/v1/prompts.test.js +4 -4
  101. package/dist/personas/organization-audit/v1/resources/playbooks/access.md +13 -0
  102. package/dist/personas/organization-audit/v1/resources/playbooks/content.md +9 -0
  103. package/dist/personas/organization-audit/v1/resources/{playbook.md → playbooks/core.md} +6 -22
  104. package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +9 -0
  105. package/dist/personas/organization-audit/v1/resources/playbooks/index.md +14 -0
  106. package/dist/personas/organization-audit/v1/resources/playbooks.d.ts +10 -0
  107. package/dist/personas/organization-audit/v1/resources/playbooks.js +41 -0
  108. package/dist/personas/persona.parity.test.d.ts +1 -0
  109. package/dist/personas/persona.parity.test.js +26 -0
  110. package/dist/personas/semantic-layer/v1/index.js +2 -2
  111. package/dist/personas/semantic-layer/v1/prompts.js +15 -37
  112. package/dist/personas/semantic-layer/v1/prompts.test.d.ts +4 -0
  113. package/dist/personas/semantic-layer/v1/prompts.test.js +19 -0
  114. package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +55 -0
  115. package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +39 -0
  116. package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +76 -0
  117. package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +13 -0
  118. package/dist/personas/semantic-layer/v1/resources/playbooks.d.ts +13 -0
  119. package/dist/personas/semantic-layer/v1/resources/playbooks.js +39 -0
  120. package/dist/personas/types.d.ts +1 -1
  121. package/dist/policy/content-developer.d.ts +35 -0
  122. package/dist/policy/content-developer.js +91 -0
  123. package/dist/policy/content-developer.test.d.ts +4 -0
  124. package/dist/policy/content-developer.test.js +48 -0
  125. package/dist/policy/content-reader.d.ts +24 -0
  126. package/dist/policy/content-reader.js +52 -0
  127. package/dist/policy/content-reader.test.d.ts +4 -0
  128. package/dist/policy/content-reader.test.js +22 -0
  129. package/dist/policy/envelope.d.ts +31 -0
  130. package/dist/policy/envelope.js +24 -0
  131. package/dist/policy/preview-ledger-fault.test.d.ts +1 -0
  132. package/dist/policy/preview-ledger-fault.test.js +527 -0
  133. package/dist/policy/preview-ledger.d.ts +118 -0
  134. package/dist/policy/preview-ledger.js +243 -0
  135. package/dist/policy/preview-ledger.test.d.ts +1 -0
  136. package/dist/policy/preview-ledger.test.js +267 -0
  137. package/dist/policy/result-limits.d.ts +27 -0
  138. package/dist/policy/result-limits.js +107 -0
  139. package/dist/policy/result-limits.test.d.ts +4 -0
  140. package/dist/policy/result-limits.test.js +28 -0
  141. package/dist/server/capabilities.js +1 -1
  142. package/dist/server/capabilities.test.js +3 -1
  143. package/dist/server/server.js +12 -1
  144. package/dist/stdio.process.test.js +148 -0
  145. package/dist/store/config.d.ts +11 -0
  146. package/dist/store/config.js +50 -0
  147. package/dist/store/config.test.d.ts +1 -0
  148. package/dist/store/config.test.js +56 -0
  149. package/dist/store/create-oauth-broker-store.d.ts +6 -0
  150. package/dist/store/create-oauth-broker-store.js +16 -0
  151. package/dist/store/create-preview-store.d.ts +10 -0
  152. package/dist/store/create-preview-store.js +30 -0
  153. package/dist/store/create-session-store.d.ts +19 -0
  154. package/dist/store/create-session-store.js +24 -0
  155. package/dist/store/in-memory-preview-store.d.ts +17 -0
  156. package/dist/store/in-memory-preview-store.js +72 -0
  157. package/dist/store/redis-client.d.ts +11 -0
  158. package/dist/store/redis-client.js +48 -0
  159. package/dist/store/redis-oauth-broker-store.d.ts +42 -0
  160. package/dist/store/redis-oauth-broker-store.js +167 -0
  161. package/dist/store/redis-oauth-broker-store.test.d.ts +1 -0
  162. package/dist/store/redis-oauth-broker-store.test.js +80 -0
  163. package/dist/store/redis-preview-store.d.ts +23 -0
  164. package/dist/store/redis-preview-store.js +94 -0
  165. package/dist/store/redis-preview-store.test.d.ts +1 -0
  166. package/dist/store/redis-preview-store.test.js +39 -0
  167. package/dist/store/redis-session-index.d.ts +33 -0
  168. package/dist/store/redis-session-index.js +49 -0
  169. package/dist/store/types.d.ts +13 -0
  170. package/dist/store/types.js +8 -0
  171. package/dist/tools/composition/explain-content.d.ts +6 -0
  172. package/dist/tools/composition/explain-content.js +108 -0
  173. package/dist/tools/lib/api-errors.d.ts +2 -0
  174. package/dist/tools/lib/api-errors.js +5 -0
  175. package/dist/tools/lib/stable-stringify.d.ts +9 -0
  176. package/dist/tools/lib/stable-stringify.js +35 -0
  177. package/dist/tools/project/delete-chart.d.ts +4 -0
  178. package/dist/tools/project/delete-chart.js +8 -0
  179. package/dist/tools/project/delete-dashboard.d.ts +4 -0
  180. package/dist/tools/project/delete-dashboard.js +8 -0
  181. package/dist/tools/project/developer-content-preview.d.ts +12 -0
  182. package/dist/tools/project/developer-content-preview.js +286 -0
  183. package/dist/tools/project/developer-content-shared.d.ts +18 -0
  184. package/dist/tools/project/developer-content-shared.js +46 -0
  185. package/dist/tools/project/developer-content-shared.test.d.ts +1 -0
  186. package/dist/tools/project/developer-content-shared.test.js +25 -0
  187. package/dist/tools/project/developer-content.d.ts +39 -0
  188. package/dist/tools/project/developer-content.js +584 -0
  189. package/dist/tools/project/developer-helpers.d.ts +180 -0
  190. package/dist/tools/project/developer-helpers.js +484 -0
  191. package/dist/tools/project/developer-helpers.test.d.ts +1 -0
  192. package/dist/tools/project/developer-helpers.test.js +509 -0
  193. package/dist/tools/project/get-dashboard-promote-diff.d.ts +6 -0
  194. package/dist/tools/project/get-dashboard-promote-diff.js +42 -0
  195. package/dist/tools/project/invariants.test.d.ts +4 -0
  196. package/dist/tools/project/invariants.test.js +42 -0
  197. package/dist/tools/project/parameters.d.ts +7 -0
  198. package/dist/tools/project/parameters.js +74 -0
  199. package/dist/tools/project/projects.d.ts +4 -1
  200. package/dist/tools/project/projects.js +64 -4
  201. package/dist/tools/project/projects.test.js +38 -1
  202. package/dist/tools/project/promote-dashboard.d.ts +4 -0
  203. package/dist/tools/project/promote-dashboard.js +8 -0
  204. package/dist/tools/project/reader-content.d.ts +9 -0
  205. package/dist/tools/project/reader-content.js +208 -0
  206. package/dist/tools/project/reader-execution.d.ts +7 -0
  207. package/dist/tools/project/reader-execution.js +214 -0
  208. package/dist/tools/project/schemas/chart-upsert.d.ts +33 -0
  209. package/dist/tools/project/schemas/chart-upsert.js +66 -0
  210. package/dist/tools/project/schemas/dashboard-tile.d.ts +29 -0
  211. package/dist/tools/project/schemas/dashboard-tile.js +57 -0
  212. package/dist/tools/project/schemas/dashboard.d.ts +70 -0
  213. package/dist/tools/project/schemas/dashboard.js +101 -0
  214. package/dist/tools/project/schemas/duplicate.d.ts +30 -0
  215. package/dist/tools/project/schemas/duplicate.js +86 -0
  216. package/dist/tools/project/schemas/index.d.ts +7 -0
  217. package/dist/tools/project/schemas/index.js +26 -0
  218. package/dist/tools/project/schemas/parse-helpers.d.ts +14 -0
  219. package/dist/tools/project/schemas/parse-helpers.js +34 -0
  220. package/dist/tools/project/schemas/payload-schemas.test.d.ts +1 -0
  221. package/dist/tools/project/schemas/payload-schemas.test.js +204 -0
  222. package/dist/tools/project/spaces.d.ts +7 -0
  223. package/dist/tools/project/spaces.js +101 -0
  224. package/dist/tools/query/bounded-saved-query.d.ts +37 -0
  225. package/dist/tools/query/bounded-saved-query.js +80 -0
  226. package/dist/tools/query/bounded-saved-query.test.d.ts +4 -0
  227. package/dist/tools/query/bounded-saved-query.test.js +82 -0
  228. package/dist/tools/query/chart-source.d.ts +10 -0
  229. package/dist/tools/query/chart-source.js +36 -0
  230. package/dist/tools/query/chart-source.test.d.ts +1 -0
  231. package/dist/tools/query/chart-source.test.js +62 -0
  232. package/dist/tools/query/filter-overrides.d.ts +34 -0
  233. package/dist/tools/query/filter-overrides.js +75 -0
  234. package/dist/tools/query/filter-overrides.test.d.ts +1 -0
  235. package/dist/tools/query/filter-overrides.test.js +21 -0
  236. package/dist/tools/query/lifecycle.d.ts +7 -0
  237. package/dist/tools/query/lifecycle.js +112 -0
  238. package/dist/tools/query/query-ledger.d.ts +34 -0
  239. package/dist/tools/query/query-ledger.js +86 -0
  240. package/dist/tools/query/query-ledger.test.d.ts +1 -0
  241. package/dist/tools/query/query-ledger.test.js +73 -0
  242. package/dist/tools/query/reader-tool-helpers.d.ts +12 -0
  243. package/dist/tools/query/reader-tool-helpers.js +59 -0
  244. package/dist/tools/query/reader-tool-helpers.test.d.ts +1 -0
  245. package/dist/tools/query/reader-tool-helpers.test.js +49 -0
  246. package/dist/tools/query/result-normalizer.d.ts +27 -0
  247. package/dist/tools/query/result-normalizer.js +133 -0
  248. package/dist/tools/query/result-normalizer.test.d.ts +1 -0
  249. package/dist/tools/query/result-normalizer.test.js +41 -0
  250. package/dist/tools/query/wait-for-async.d.ts +10 -0
  251. package/dist/tools/query/wait-for-async.js +46 -0
  252. package/dist/tools/query/wait-for-async.test.d.ts +1 -0
  253. package/dist/tools/query/wait-for-async.test.js +45 -0
  254. package/dist/tools/registry.d.ts +124 -3
  255. package/dist/tools/registry.js +63 -7
  256. package/dist/tools/shared.d.ts +25 -2
  257. package/dist/tools/shared.js +66 -13
  258. package/dist/tools/shared.test.js +6 -2
  259. package/dist/transports/session-store.d.ts +33 -1
  260. package/dist/transports/session-store.js +56 -1
  261. package/dist/transports/streamable-http.js +10 -3
  262. package/dist/transports/streamable-http.test.js +11 -6
  263. package/package.json +6 -5
  264. package/dist/personas/organization-audit/v1/resources/playbook.d.ts +0 -11
  265. package/dist/personas/organization-audit/v1/resources/playbook.js +0 -40
  266. package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +0 -12
  267. package/dist/personas/semantic-layer/v1/resources/playbook.js +0 -42
  268. package/dist/personas/semantic-layer/v1/resources/playbook.md +0 -153
@@ -1,3 +1,4 @@
1
+ import type { OAuthBrokerStore } from './pending-store.js';
1
2
  import type { McpHttpConfig } from '../../config/load-mcp-config.js';
2
3
  import type { IncomingMessage, ServerResponse } from 'node:http';
3
4
  export interface OAuthBroker {
@@ -5,5 +6,8 @@ export interface OAuthBroker {
5
6
  }
6
7
  /** True for co-located OAuth AS / broker paths (CORS may reflect any Origin). */
7
8
  export declare function isOAuthBrokerPath(path: string): boolean;
8
- /** Creates the OAuth broker request handler for co-located AS façade routes. */
9
- export declare function createOAuthBroker(config: McpHttpConfig): OAuthBroker;
9
+ /**
10
+ * Creates the OAuth broker request handler for co-located AS façade routes.
11
+ * Uses the shared ephemeral store backend (memory default; Redis when configured).
12
+ */
13
+ export declare function createOAuthBroker(config: McpHttpConfig, store?: OAuthBrokerStore): OAuthBroker;
@@ -4,11 +4,11 @@ exports.isOAuthBrokerPath = isOAuthBrokerPath;
4
4
  exports.createOAuthBroker = createOAuthBroker;
5
5
  const env_js_1 = require("../../config/env.js");
6
6
  const normalize_url_js_1 = require("../../config/normalize-url.js");
7
+ const create_oauth_broker_store_js_1 = require("../../store/create-oauth-broker-store.js");
7
8
  const http_body_js_1 = require("../../transports/http-body.js");
8
9
  const http_response_js_1 = require("../../transports/http-response.js");
9
10
  const as_metadata_js_1 = require("./as-metadata.js");
10
11
  const lightdash_token_js_1 = require("./lightdash-token.js");
11
- const pending_store_js_1 = require("./pending-store.js");
12
12
  const pkce_js_1 = require("./pkce.js");
13
13
  /** Schemes that must never be used as OAuth redirect targets. */
14
14
  const BLOCKED_REDIRECT_SCHEMES = new Set(['javascript:', 'data:', 'vbscript:', 'file:']);
@@ -94,7 +94,7 @@ function isAllowedClientRedirectUri(redirectUri) {
94
94
  return false;
95
95
  }
96
96
  }
97
- function parseRegisteredClientRedirect(query, store) {
97
+ async function parseRegisteredClientRedirect(query, store) {
98
98
  const clientId = query.get('client_id');
99
99
  if (!clientId) {
100
100
  return {
@@ -106,7 +106,7 @@ function parseRegisteredClientRedirect(query, store) {
106
106
  },
107
107
  };
108
108
  }
109
- if (!store.getClient(clientId)) {
109
+ if (!(await store.getClient(clientId))) {
110
110
  return {
111
111
  ok: false,
112
112
  status: 400,
@@ -127,7 +127,7 @@ function parseRegisteredClientRedirect(query, store) {
127
127
  },
128
128
  };
129
129
  }
130
- if (!store.isRedirectAllowedForClient(clientId, redirectUri)) {
130
+ if (!(await store.isRedirectAllowedForClient(clientId, redirectUri))) {
131
131
  return {
132
132
  ok: false,
133
133
  status: 400,
@@ -139,7 +139,7 @@ function parseRegisteredClientRedirect(query, store) {
139
139
  }
140
140
  return { ok: true, clientId, redirectUri };
141
141
  }
142
- function parseAuthorizeRequest(query, store) {
142
+ async function parseAuthorizeRequest(query, store) {
143
143
  var _a, _b, _c, _d, _e;
144
144
  const responseType = query.get('response_type');
145
145
  if (responseType !== 'code') {
@@ -152,7 +152,7 @@ function parseAuthorizeRequest(query, store) {
152
152
  },
153
153
  };
154
154
  }
155
- const registered = parseRegisteredClientRedirect(query, store);
155
+ const registered = await parseRegisteredClientRedirect(query, store);
156
156
  if (!registered.ok) {
157
157
  return registered;
158
158
  }
@@ -180,18 +180,18 @@ function parseAuthorizeRequest(query, store) {
180
180
  },
181
181
  };
182
182
  }
183
- function handleAuthorize(req, res, config, store) {
183
+ async function handleAuthorize(req, res, config, store) {
184
184
  if (req.method !== 'GET') {
185
185
  res.writeHead(405, { Allow: 'GET' }).end();
186
186
  return;
187
187
  }
188
- const parsed = parseAuthorizeRequest(readQuery(req), store);
188
+ const parsed = await parseAuthorizeRequest(readQuery(req), store);
189
189
  if (!parsed.ok) {
190
190
  (0, http_response_js_1.sendJson)(res, parsed.status, parsed.body);
191
191
  return;
192
192
  }
193
193
  const { clientId, redirectUri, clientState, codeChallenge, resource, scope } = parsed.value;
194
- const pending = store.createPending({
194
+ const pending = await store.createPending({
195
195
  clientId,
196
196
  redirectUri,
197
197
  clientState,
@@ -230,7 +230,7 @@ async function handleCallback(req, res, config, store) {
230
230
  (0, http_response_js_1.sendJson)(res, 400, { error: 'invalid_request', error_description: 'Missing state' });
231
231
  return;
232
232
  }
233
- const pending = store.takePending(brokerState);
233
+ const pending = await store.takePending(brokerState);
234
234
  if (!pending) {
235
235
  (0, http_response_js_1.sendJson)(res, 400, { error: 'invalid_request', error_description: 'Unknown or expired state' });
236
236
  return;
@@ -252,7 +252,7 @@ async function handleCallback(req, res, config, store) {
252
252
  try {
253
253
  const tokens = await (0, lightdash_token_js_1.exchangeLightdashAuthorizationCode)(config, code);
254
254
  // Do not persist/return refresh_token: broker only supports authorization_code.
255
- const issued = store.issueCode(pending, {
255
+ const issued = await store.issueCode(pending, {
256
256
  accessToken: tokens.access_token,
257
257
  expiresIn: tokens.expires_in,
258
258
  tokenType: tokens.token_type,
@@ -276,7 +276,7 @@ async function handleCallback(req, res, config, store) {
276
276
  });
277
277
  }
278
278
  }
279
- function validateTokenGrant(params, store) {
279
+ async function validateTokenGrant(params, store) {
280
280
  var _a;
281
281
  const grantType = params.get('grant_type');
282
282
  if (grantType !== 'authorization_code') {
@@ -301,8 +301,9 @@ function validateTokenGrant(params, store) {
301
301
  },
302
302
  };
303
303
  }
304
- // Validate before consume so a bad verifier / redirect does not burn a one-time code.
305
- const candidate = store.getCode(code);
304
+ // Atomic take first (multi-instance safe). Restore on validation failure so a
305
+ // bad verifier / redirect does not permanently burn a one-time code.
306
+ const candidate = await store.takeCode(code);
306
307
  if (!candidate) {
307
308
  return {
308
309
  status: 400,
@@ -310,24 +311,26 @@ function validateTokenGrant(params, store) {
310
311
  };
311
312
  }
312
313
  if (candidate.redirectUri !== redirectUri) {
314
+ await store.restoreCode(candidate);
313
315
  return {
314
316
  status: 400,
315
317
  body: { error: 'invalid_grant', error_description: 'redirect_uri mismatch' },
316
318
  };
317
319
  }
318
320
  if (candidate.clientId !== clientId) {
321
+ await store.restoreCode(candidate);
319
322
  return {
320
323
  status: 400,
321
324
  body: { error: 'invalid_grant', error_description: 'client_id mismatch' },
322
325
  };
323
326
  }
324
327
  if (!(0, pkce_js_1.verifyPkce)(codeVerifier, candidate.codeChallenge, candidate.codeChallengeMethod)) {
328
+ await store.restoreCode(candidate);
325
329
  return {
326
330
  status: 400,
327
331
  body: { error: 'invalid_grant', error_description: 'PKCE verification failed' },
328
332
  };
329
333
  }
330
- store.deleteCode(code);
331
334
  return { issued: candidate };
332
335
  }
333
336
  async function handleToken(req, res, config, store) {
@@ -339,7 +342,7 @@ async function handleToken(req, res, config, store) {
339
342
  const params = await readFormOrJson(req, res, config.maxBodyBytes);
340
343
  if (!params)
341
344
  return;
342
- const grant = validateTokenGrant(params, store);
345
+ const grant = await validateTokenGrant(params, store);
343
346
  if ('status' in grant) {
344
347
  (0, http_response_js_1.sendJson)(res, grant.status, grant.body);
345
348
  return;
@@ -380,7 +383,7 @@ async function handleRegister(req, res, config, store) {
380
383
  return;
381
384
  }
382
385
  }
383
- const registered = store.registerClient(redirectUris);
386
+ const registered = await store.registerClient(redirectUris);
384
387
  if (!registered) {
385
388
  (0, http_response_js_1.sendJson)(res, 503, Object.assign({}, AS_BUSY));
386
389
  return;
@@ -409,9 +412,11 @@ const BROKER_PATHS = new Set([
409
412
  function isOAuthBrokerPath(path) {
410
413
  return BROKER_PATHS.has(path);
411
414
  }
412
- /** Creates the OAuth broker request handler for co-located AS façade routes. */
413
- function createOAuthBroker(config) {
414
- const store = new pending_store_js_1.OAuthBrokerStore();
415
+ /**
416
+ * Creates the OAuth broker request handler for co-located AS façade routes.
417
+ * Uses the shared ephemeral store backend (memory default; Redis when configured).
418
+ */
419
+ function createOAuthBroker(config, store = (0, create_oauth_broker_store_js_1.createOAuthBrokerStore)()) {
415
420
  return {
416
421
  async handle(req, res, path) {
417
422
  if (!isOAuthBrokerPath(path)) {
@@ -426,7 +431,7 @@ function createOAuthBroker(config) {
426
431
  return true;
427
432
  }
428
433
  if (path === env_js_1.OAUTH_AUTHORIZE_PATH) {
429
- handleAuthorize(req, res, config, store);
434
+ await handleAuthorize(req, res, config, store);
430
435
  return true;
431
436
  }
432
437
  if (path === env_js_1.OAUTH_CALLBACK_PATH) {
@@ -93,59 +93,64 @@ function mockReq(method, url, body, contentType = 'application/x-www-form-urlenc
93
93
  (0, vitest_1.expect)((0, pkce_js_1.verifyPkce)(verifier, verifier, 'PLAIN')).toBe(false);
94
94
  (0, vitest_1.expect)((0, pkce_js_1.verifyPkce)(undefined, challenge, 'S256')).toBe(false);
95
95
  });
96
- (0, vitest_1.it)('issues and consumes one-time broker codes without refresh tokens', () => {
97
- var _a, _b;
98
- const store = new pending_store_js_1.OAuthBrokerStore();
99
- const pending = store.createPending({
96
+ (0, vitest_1.it)('issues and consumes one-time broker codes without refresh tokens', async () => {
97
+ var _a;
98
+ const store = new pending_store_js_1.InMemoryOAuthBrokerStore();
99
+ const pending = await store.createPending({
100
100
  clientId: 'client-a',
101
101
  redirectUri: 'http://127.0.0.1:9999/callback',
102
102
  codeChallenge: 'challenge',
103
103
  codeChallengeMethod: 'S256',
104
104
  });
105
105
  (0, vitest_1.expect)(pending).toBeDefined();
106
- (0, vitest_1.expect)((_a = store.takePending(pending.brokerState)) === null || _a === void 0 ? void 0 : _a.clientId).toBe('client-a');
107
- (0, vitest_1.expect)(store.takePending(pending.brokerState)).toBeUndefined();
108
- const pending2 = store.createPending({
106
+ (0, vitest_1.expect)((_a = (await store.takePending(pending.brokerState))) === null || _a === void 0 ? void 0 : _a.clientId).toBe('client-a');
107
+ (0, vitest_1.expect)(await store.takePending(pending.brokerState)).toBeUndefined();
108
+ const pending2 = await store.createPending({
109
109
  clientId: 'client-a',
110
110
  redirectUri: 'http://127.0.0.1:9999/callback',
111
111
  codeChallenge: 'challenge',
112
112
  codeChallengeMethod: 'S256',
113
113
  });
114
114
  (0, vitest_1.expect)(pending2).toBeDefined();
115
- const issued = store.issueCode(pending2, { accessToken: 'atok' });
115
+ const issued = await store.issueCode(pending2, { accessToken: 'atok' });
116
116
  (0, vitest_1.expect)(issued).toBeDefined();
117
- (0, vitest_1.expect)((_b = store.getCode(issued.code)) === null || _b === void 0 ? void 0 : _b.accessToken).toBe('atok');
118
- (0, vitest_1.expect)(store.getCode(issued.code)).not.toHaveProperty('refreshToken');
119
- store.deleteCode(issued.code);
120
- (0, vitest_1.expect)(store.getCode(issued.code)).toBeUndefined();
117
+ (0, vitest_1.expect)(issued).not.toHaveProperty('refreshToken');
118
+ const taken = await store.takeCode(issued.code);
119
+ (0, vitest_1.expect)(taken === null || taken === void 0 ? void 0 : taken.accessToken).toBe('atok');
120
+ (0, vitest_1.expect)(await store.takeCode(issued.code)).toBeUndefined();
121
121
  });
122
- (0, vitest_1.it)('registers clients and binds exact redirect URIs', () => {
123
- const store = new pending_store_js_1.OAuthBrokerStore();
124
- const registered = store.registerClient(['http://127.0.0.1:8787/callback']);
122
+ (0, vitest_1.it)('registers clients and binds exact redirect URIs', async () => {
123
+ const store = new pending_store_js_1.InMemoryOAuthBrokerStore();
124
+ const registered = await store.registerClient(['http://127.0.0.1:8787/callback']);
125
125
  (0, vitest_1.expect)(registered).toBeDefined();
126
- (0, vitest_1.expect)(store.isRedirectAllowedForClient(registered.clientId, 'http://127.0.0.1:8787/callback')).toBe(true);
127
- (0, vitest_1.expect)(store.isRedirectAllowedForClient(registered.clientId, 'https://attacker.example/callback')).toBe(false);
128
- (0, vitest_1.expect)(store.isRedirectAllowedForClient('unknown', 'http://127.0.0.1:8787/callback')).toBe(false);
126
+ (0, vitest_1.expect)(await store.isRedirectAllowedForClient(registered.clientId, 'http://127.0.0.1:8787/callback')).toBe(true);
127
+ (0, vitest_1.expect)(await store.isRedirectAllowedForClient(registered.clientId, 'https://attacker.example/callback')).toBe(false);
128
+ (0, vitest_1.expect)(await store.isRedirectAllowedForClient('unknown', 'http://127.0.0.1:8787/callback')).toBe(false);
129
129
  });
130
- (0, vitest_1.it)('keeps issued code after failed PKCE peek so a later redeem can succeed', () => {
130
+ (0, vitest_1.it)('restores issued code after failed PKCE so a later redeem can succeed', async () => {
131
131
  var _a;
132
- const store = new pending_store_js_1.OAuthBrokerStore();
132
+ const store = new pending_store_js_1.InMemoryOAuthBrokerStore();
133
133
  const verifier = 'test-verifier-value-1234567890';
134
134
  const challenge = (0, node_crypto_1.createHash)('sha256').update(verifier).digest('base64url');
135
- const pending = store.createPending({
135
+ const pending = await store.createPending({
136
136
  clientId: 'client-a',
137
137
  redirectUri: 'http://localhost:8787/callback',
138
138
  codeChallenge: challenge,
139
139
  codeChallengeMethod: 'S256',
140
140
  });
141
141
  (0, vitest_1.expect)(pending).toBeDefined();
142
- const issued = store.issueCode(pending, { accessToken: 'atok' });
142
+ const issued = await store.issueCode(pending, { accessToken: 'atok' });
143
143
  (0, vitest_1.expect)(issued).toBeDefined();
144
- (0, vitest_1.expect)((0, pkce_js_1.verifyPkce)('wrong-verifier', issued.codeChallenge, 'S256')).toBe(false);
145
- (0, vitest_1.expect)((_a = store.getCode(issued.code)) === null || _a === void 0 ? void 0 : _a.accessToken).toBe('atok');
146
- (0, vitest_1.expect)((0, pkce_js_1.verifyPkce)(verifier, issued.codeChallenge, 'S256')).toBe(true);
147
- store.deleteCode(issued.code);
148
- (0, vitest_1.expect)(store.getCode(issued.code)).toBeUndefined();
144
+ // Simulate validateTokenGrant: take → failed PKCE → restore.
145
+ const taken = await store.takeCode(issued.code);
146
+ (0, vitest_1.expect)(taken).toBeDefined();
147
+ (0, vitest_1.expect)((0, pkce_js_1.verifyPkce)('wrong-verifier', taken.codeChallenge, 'S256')).toBe(false);
148
+ await store.restoreCode(taken);
149
+ (0, vitest_1.expect)((_a = (await store.getCode(issued.code))) === null || _a === void 0 ? void 0 : _a.accessToken).toBe('atok');
150
+ const redeemed = await store.takeCode(issued.code);
151
+ (0, vitest_1.expect)(redeemed === null || redeemed === void 0 ? void 0 : redeemed.accessToken).toBe('atok');
152
+ (0, vitest_1.expect)((0, pkce_js_1.verifyPkce)(verifier, redeemed.codeChallenge, 'S256')).toBe(true);
153
+ (0, vitest_1.expect)(await store.takeCode(issued.code)).toBeUndefined();
149
154
  });
150
155
  (0, vitest_1.it)('forwards Proxy-Authorization on Lightdash token exchange when configured', async () => {
151
156
  const fetchMock = vitest_1.vi.fn().mockResolvedValue({
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
4
  const test_mcp_http_config_js_1 = require("../../config/test-mcp-http-config.js");
5
- const index_js_1 = require("../../personas/organization-audit/v1/index.js");
6
- const index_js_2 = require("../../personas/semantic-layer/v1/index.js");
5
+ const index_js_1 = require("../../personas/content-reader/v1/index.js");
6
+ const index_js_2 = require("../../personas/organization-audit/v1/index.js");
7
+ const index_js_3 = require("../../personas/semantic-layer/v1/index.js");
7
8
  const oauth_protected_resource_js_1 = require("./oauth-protected-resource.js");
8
9
  const www_authenticate_js_1 = require("./www-authenticate.js");
9
10
  const baseConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
@@ -19,9 +20,9 @@ const baseConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
19
20
  });
20
21
  (0, vitest_1.describe)('buildOAuthProtectedResourceMetadata', () => {
21
22
  (0, vitest_1.it)('includes resource and MCP host as authorization_servers', () => {
22
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(baseConfig, index_js_2.SEMANTIC_LAYER_PERSONA_PATH);
23
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(baseConfig, index_js_3.SEMANTIC_LAYER_PERSONA_PATH);
23
24
  (0, vitest_1.expect)(metadata).toEqual({
24
- resource: `https://mcp.example.com${index_js_2.SEMANTIC_LAYER_PERSONA_PATH}`,
25
+ resource: `https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PERSONA_PATH}`,
25
26
  authorization_servers: ['https://mcp.example.com'],
26
27
  bearer_methods_supported: ['header'],
27
28
  scopes_supported: ['mcp:read', 'mcp:write'],
@@ -29,8 +30,13 @@ const baseConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
29
30
  (0, vitest_1.expect)((0, oauth_protected_resource_js_1.getAuthorizationServerMetadataUrl)(metadata.authorization_servers[0])).toBe('https://mcp.example.com/.well-known/oauth-authorization-server');
30
31
  });
31
32
  (0, vitest_1.it)('builds persona-specific resource metadata for organization-audit', () => {
32
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(baseConfig, index_js_1.ORGANIZATION_AUDIT_PERSONA_PATH);
33
- (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.ORGANIZATION_AUDIT_PERSONA_PATH}`);
33
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(baseConfig, index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH);
34
+ (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH}`);
35
+ (0, vitest_1.expect)(metadata.authorization_servers).toEqual(['https://mcp.example.com']);
36
+ });
37
+ (0, vitest_1.it)('builds persona-specific resource metadata for content-reader', () => {
38
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(baseConfig, index_js_1.CONTENT_READER_PERSONA_PATH);
39
+ (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.CONTENT_READER_PERSONA_PATH}`);
34
40
  (0, vitest_1.expect)(metadata.authorization_servers).toEqual(['https://mcp.example.com']);
35
41
  });
36
42
  });
package/dist/bin.js CHANGED
@@ -37,6 +37,9 @@ const commander_1 = require("commander");
37
37
  const program = new commander_1.Command();
38
38
  const PERSONA_SEMANTIC_LAYER = 'semantic-layer';
39
39
  const PERSONA_ORGANIZATION_AUDIT = 'organization-audit';
40
+ const PERSONA_CONTENT_READER = 'content-reader';
41
+ const PERSONA_CONTENT_DEVELOPER = 'content-developer';
42
+ const PERSONA_CONTENT_GOVERNANCE = 'content-governance';
40
43
  function runStdio(personaId) {
41
44
  if (personaId) {
42
45
  process.env.LIGHTDASH_TOOLS_MCP_STDIO_PERSONA = personaId;
@@ -48,8 +51,8 @@ function runHttp() {
48
51
  }
49
52
  program
50
53
  .name('lightdash-mcp')
51
- .description('MCP server for Lightdash (semantic-layer discovery and organization-audit). Default stdio persona is semantic-layer.')
52
- .version('0.7.0');
54
+ .description('MCP server for Lightdash (semantic-layer, organization-audit, content-reader, content-developer, content-governance). Default stdio persona is semantic-layer.')
55
+ .version('0.8.0');
53
56
  program
54
57
  .command('stdio')
55
58
  .description('Run MCP server on stdio with the default semantic-layer persona')
@@ -68,6 +71,24 @@ program
68
71
  .action(() => {
69
72
  runStdio(PERSONA_ORGANIZATION_AUDIT);
70
73
  });
74
+ program
75
+ .command(PERSONA_CONTENT_READER)
76
+ .description('Run content-reader persona on stdio (saved-content discovery and bounded execution)')
77
+ .action(() => {
78
+ runStdio(PERSONA_CONTENT_READER);
79
+ });
80
+ program
81
+ .command(PERSONA_CONTENT_DEVELOPER)
82
+ .description('Run content-developer persona on stdio (chart/dashboard/space authoring behind preview -> validate -> apply)')
83
+ .action(() => {
84
+ runStdio(PERSONA_CONTENT_DEVELOPER);
85
+ });
86
+ program
87
+ .command(PERSONA_CONTENT_GOVERNANCE)
88
+ .description('Run content-governance persona on stdio (elicitation-gated soft-delete of charts and dashboards)')
89
+ .action(() => {
90
+ runStdio(PERSONA_CONTENT_GOVERNANCE);
91
+ });
71
92
  program
72
93
  .command('serve-http')
73
94
  .description('Run MCP server with Streamable HTTP transport (auth inferred from OAuth client credentials, shared-key, or NODE_ENV=development)')
@@ -20,6 +20,13 @@ export declare const ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = "LIGHTDASH_TOOLS_
20
20
  export declare const ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = "LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED";
21
21
  export declare const ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = "LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN";
22
22
  export declare const ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = "LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS";
23
+ /**
24
+ * Ephemeral store backend for HTTP preview ledger / sessions / OAuth pending (ADR-0016).
25
+ * `memory` (default) or `redis`.
26
+ */
27
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_STORE = "LIGHTDASH_TOOLS_MCP_STORE";
28
+ /** Required when LIGHTDASH_TOOLS_MCP_STORE=redis. */
29
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = "LIGHTDASH_TOOLS_MCP_REDIS_URL";
23
30
  /** Lightdash OAuth application credentials (server-held confidential client). */
24
31
  export declare const ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = "LIGHTDASH_TOOLS_OAUTH_CLIENT_ID";
25
32
  export declare const ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = "LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET";
@@ -4,7 +4,7 @@
4
4
  * Legacy `MCP_*` aliases are resolved in load-mcp-config.ts.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.OAUTH_AUTHORIZATION_SERVER_METADATA_PATH = exports.OAUTH_REGISTER_PATH = exports.OAUTH_TOKEN_PATH = exports.OAUTH_AUTHORIZE_PATH = exports.OAUTH_CALLBACK_PATH = exports.ENV_MCP_SESSION_CLEANUP_MS = exports.ENV_MCP_MAX_SESSIONS = exports.ENV_MCP_SESSION_TTL_MS = exports.ENV_MCP_MAX_BODY_BYTES = exports.ENV_MCP_ALLOWED_ORIGINS = exports.ENV_MCP_API_KEY = exports.ENV_MCP_AUTH_ENABLED = exports.ENV_MCP_PUBLIC_URL = exports.ENV_MCP_SERVER_PORT = exports.ENV_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_GRANT_ALL_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_SKIP_TOKEN_VALIDATION = exports.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_SESSION_CLEANUP_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSIONS_PER_SUBJECT = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSIONS = exports.ENV_LIGHTDASH_TOOLS_MCP_SESSION_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = void 0;
7
+ exports.OAUTH_AUTHORIZATION_SERVER_METADATA_PATH = exports.OAUTH_REGISTER_PATH = exports.OAUTH_TOKEN_PATH = exports.OAUTH_AUTHORIZE_PATH = exports.OAUTH_CALLBACK_PATH = exports.ENV_MCP_SESSION_CLEANUP_MS = exports.ENV_MCP_MAX_SESSIONS = exports.ENV_MCP_SESSION_TTL_MS = exports.ENV_MCP_MAX_BODY_BYTES = exports.ENV_MCP_ALLOWED_ORIGINS = exports.ENV_MCP_API_KEY = exports.ENV_MCP_AUTH_ENABLED = exports.ENV_MCP_PUBLIC_URL = exports.ENV_MCP_SERVER_PORT = exports.ENV_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_GRANT_ALL_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_SKIP_TOKEN_VALIDATION = exports.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_SESSION_CLEANUP_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSIONS_PER_SUBJECT = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSIONS = exports.ENV_LIGHTDASH_TOOLS_MCP_SESSION_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = void 0;
8
8
  exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = 'LIGHTDASH_TOOLS_MCP_HTTP_HOST';
9
9
  exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = 'LIGHTDASH_TOOLS_MCP_HTTP_PORT';
10
10
  exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = 'LIGHTDASH_TOOLS_MCP_PUBLIC_URL';
@@ -23,6 +23,13 @@ exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = 'LIGHTDASH_TOOLS_MCP_REQUIRED_
23
23
  exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = 'LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED';
24
24
  exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = 'LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN';
25
25
  exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = 'LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS';
26
+ /**
27
+ * Ephemeral store backend for HTTP preview ledger / sessions / OAuth pending (ADR-0016).
28
+ * `memory` (default) or `redis`.
29
+ */
30
+ exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = 'LIGHTDASH_TOOLS_MCP_STORE';
31
+ /** Required when LIGHTDASH_TOOLS_MCP_STORE=redis. */
32
+ exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = 'LIGHTDASH_TOOLS_MCP_REDIS_URL';
26
33
  /** Lightdash OAuth application credentials (server-held confidential client). */
27
34
  exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = 'LIGHTDASH_TOOLS_OAUTH_CLIENT_ID';
28
35
  exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = 'LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET';
@@ -7,6 +7,7 @@ exports.getOAuthCallbackUrl = getOAuthCallbackUrl;
7
7
  const client_1 = require("@lightdash-tools/client");
8
8
  const auth_mode_js_1 = require("../auth/auth-mode.js");
9
9
  const index_js_1 = require("../personas/index.js");
10
+ const config_js_1 = require("../store/config.js");
10
11
  const env_js_1 = require("./env.js");
11
12
  const normalize_url_js_1 = require("./normalize-url.js");
12
13
  const public_url_js_1 = require("./public-url.js");
@@ -201,6 +202,7 @@ function emitMcpHttpSecurityWarnings(config) {
201
202
  }
202
203
  emitLightdashOAuthSecurityWarnings(config);
203
204
  emitCorsSecurityWarnings(config);
205
+ (0, config_js_1.emitEphemeralStoreHttpWarning)((0, config_js_1.resolveEphemeralStoreConfig)());
204
206
  }
205
207
  function readScopeList(env, primary, fallback) {
206
208
  const parsed = parseCsv(readEnv(primary, env));
@@ -249,6 +251,8 @@ function loadMcpHttpConfig(env = process.env) {
249
251
  `The MCP endpoint path is persona-owned (${(0, index_js_1.getDefaultPersona)().path}); leave this variable unset.`);
250
252
  }
251
253
  assertObsoleteEnvRejected(env);
254
+ // Fail closed early when STORE=redis without REDIS_URL (ADR-0016).
255
+ (0, config_js_1.resolveEphemeralStoreConfig)(env);
252
256
  const { oauthClientId, oauthClientSecretRaw, publicUrlRaw, sharedKeyRaw, authMode } = readHttpAuthInputs(env);
253
257
  if (authMode === auth_mode_js_1.MCP_AUTH_MODE_SHARED_KEY && !sharedKeyRaw) {
254
258
  throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY} is required for shared-key HTTP auth ` +
@@ -58,6 +58,13 @@ function setOAuthCreds() {
58
58
  const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
59
59
  (0, vitest_1.expect)(config.publicUrl).toBe('https://mcp.example.com');
60
60
  });
61
+ (0, vitest_1.it)('strips content-reader persona path from public URL', () => {
62
+ setOAuthCreds();
63
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL] =
64
+ 'https://mcp.example.com/content-reader/v1/mcp';
65
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
66
+ (0, vitest_1.expect)(config.publicUrl).toBe('https://mcp.example.com');
67
+ });
61
68
  (0, vitest_1.it)('requires both OAuth client id and secret together', () => {
62
69
  process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
63
70
  process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL] = 'https://mcp.example.com';
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
- const index_js_1 = require("../personas/organization-audit/v1/index.js");
5
- const index_js_2 = require("../personas/semantic-layer/v1/index.js");
4
+ const index_js_1 = require("../personas/content-reader/v1/index.js");
5
+ const index_js_2 = require("../personas/organization-audit/v1/index.js");
6
+ const index_js_3 = require("../personas/semantic-layer/v1/index.js");
6
7
  const normalize_url_js_1 = require("./normalize-url.js");
7
8
  (0, vitest_1.describe)('normalizeMcpPath', () => {
8
9
  (0, vitest_1.it)('adds a leading slash when missing', () => {
@@ -29,13 +30,18 @@ const normalize_url_js_1 = require("./normalize-url.js");
29
30
  (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)('https://mcp.example.com', ['/custom/mcp'])).toBe('https://mcp.example.com');
30
31
  });
31
32
  (0, vitest_1.it)('strips the semantic-layer persona path', () => {
32
- (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_2.SEMANTIC_LAYER_PERSONA_PATH}/`, [
33
- index_js_2.SEMANTIC_LAYER_PERSONA_PATH,
33
+ (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PERSONA_PATH}/`, [
34
+ index_js_3.SEMANTIC_LAYER_PERSONA_PATH,
34
35
  ])).toBe('https://mcp.example.com');
35
36
  });
36
37
  (0, vitest_1.it)('strips any known persona path when given a path list', () => {
37
- const paths = [index_js_2.SEMANTIC_LAYER_PERSONA_PATH, index_js_1.ORGANIZATION_AUDIT_PERSONA_PATH];
38
- (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_1.ORGANIZATION_AUDIT_PERSONA_PATH}`, paths)).toBe('https://mcp.example.com');
39
- (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_2.SEMANTIC_LAYER_PERSONA_PATH}/`, paths)).toBe('https://mcp.example.com');
38
+ const paths = [
39
+ index_js_3.SEMANTIC_LAYER_PERSONA_PATH,
40
+ index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH,
41
+ index_js_1.CONTENT_READER_PERSONA_PATH,
42
+ ];
43
+ (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PERSONA_PATH}`, paths)).toBe('https://mcp.example.com');
44
+ (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PERSONA_PATH}/`, paths)).toBe('https://mcp.example.com');
45
+ (0, vitest_1.expect)((0, normalize_url_js_1.normalizePublicUrl)(`https://mcp.example.com${index_js_1.CONTENT_READER_PERSONA_PATH}`, paths)).toBe('https://mcp.example.com');
40
46
  });
41
47
  });
@@ -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;