@lightdash-tools/mcp 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +108 -237
  2. package/dist/audit/server-persona.d.ts +10 -0
  3. package/dist/audit/server-persona.js +19 -0
  4. package/dist/auth/oauth-broker/pending-store.d.ts +6 -7
  5. package/dist/auth/oauth-broker/pending-store.js +3 -4
  6. package/dist/auth/oauth-broker/pending-store.test.d.ts +2 -3
  7. package/dist/auth/oauth-broker/pending-store.test.js +2 -39
  8. package/dist/auth/oauth-broker/routes.d.ts +1 -1
  9. package/dist/auth/oauth-broker/routes.js +3 -3
  10. package/dist/auth/oauth-broker/routes.test.js +1 -1
  11. package/dist/auth/request-state-key.d.ts +19 -0
  12. package/dist/auth/request-state-key.js +49 -0
  13. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +0 -2
  14. package/dist/auth/resource-server/lightdash-oauth-middleware.js +0 -19
  15. package/dist/auth/resource-server/www-authenticate.test.js +0 -2
  16. package/dist/bin.js +9 -2
  17. package/dist/config/env.d.ts +5 -15
  18. package/dist/config/env.js +6 -16
  19. package/dist/config/load-mcp-config.d.ts +0 -4
  20. package/dist/config/load-mcp-config.js +8 -9
  21. package/dist/config/normalize-url.test.js +14 -11
  22. package/dist/config/runtime.d.ts +3 -3
  23. package/dist/config/runtime.js +19 -23
  24. package/dist/config/runtime.test.js +23 -9
  25. package/dist/config/test-mcp-http-config.js +1 -1
  26. package/dist/destructive/content-promote.js +7 -1
  27. package/dist/destructive/promote-contract.test.js +106 -47
  28. package/dist/destructive/register-destructive-tool.js +6 -24
  29. package/dist/destructive/request-state.d.ts +2 -6
  30. package/dist/destructive/request-state.js +3 -38
  31. package/dist/destructive/types.d.ts +2 -1
  32. package/dist/governance/available-projects.d.ts +37 -0
  33. package/dist/governance/available-projects.js +132 -0
  34. package/dist/governance/available-projects.test.d.ts +4 -0
  35. package/dist/governance/available-projects.test.js +107 -0
  36. package/dist/governance/client-capabilities-cache.d.ts +44 -0
  37. package/dist/governance/client-capabilities-cache.js +142 -0
  38. package/dist/governance/client-capabilities-cache.test.js +148 -0
  39. package/dist/governance/mcp-client-session.d.ts +3 -2
  40. package/dist/governance/mcp-client-session.js +3 -2
  41. package/dist/governance/project-scope.d.ts +8 -22
  42. package/dist/governance/project-scope.js +36 -44
  43. package/dist/governance/project-scope.test.d.ts +1 -1
  44. package/dist/governance/project-scope.test.js +21 -44
  45. package/dist/governance/promote-allowlist.d.ts +18 -0
  46. package/dist/governance/promote-allowlist.js +66 -0
  47. package/dist/governance/promote-allowlist.test.d.ts +4 -0
  48. package/dist/governance/promote-allowlist.test.js +87 -0
  49. package/dist/http.integration.test.js +117 -262
  50. package/dist/http.test.js +0 -12
  51. package/dist/index.integration.test.js +0 -4
  52. package/dist/index.js +3 -1
  53. package/dist/personas/ai-agent-ops/v1/index.d.ts +8 -0
  54. package/dist/personas/ai-agent-ops/v1/index.js +41 -0
  55. package/dist/personas/ai-agent-ops/v1/prompts.d.ts +5 -0
  56. package/dist/personas/ai-agent-ops/v1/prompts.js +141 -0
  57. package/dist/personas/ai-agent-ops/v1/prompts.test.d.ts +4 -0
  58. package/dist/personas/ai-agent-ops/v1/prompts.test.js +26 -0
  59. package/dist/personas/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
  60. package/dist/personas/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
  61. package/dist/personas/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
  62. package/dist/personas/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
  63. package/dist/personas/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
  64. package/dist/personas/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
  65. package/dist/personas/ai-agent-ops/v1/resources/playbooks.js +41 -0
  66. package/dist/personas/content-developer/v1/index.d.ts +1 -1
  67. package/dist/personas/content-developer/v1/index.js +1 -0
  68. package/dist/personas/content-developer/v1/prompts.d.ts +3 -0
  69. package/dist/personas/content-developer/v1/prompts.js +80 -61
  70. package/dist/personas/content-developer/v1/prompts.test.js +159 -3
  71. package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
  72. package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +13 -6
  73. package/dist/personas/content-developer/v1/resources/playbooks/core.md +91 -49
  74. package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
  75. package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +82 -34
  76. package/dist/personas/content-developer/v1/resources/playbooks/index.md +9 -7
  77. package/dist/personas/content-developer/v1/resources/playbooks.d.ts +1 -1
  78. package/dist/personas/content-developer/v1/resources/playbooks.js +29 -10
  79. package/dist/personas/content-governance/v1/resources/playbooks/core.md +1 -1
  80. package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +1 -1
  81. package/dist/personas/content-reader/v1/index.d.ts +1 -1
  82. package/dist/personas/content-reader/v1/index.js +1 -0
  83. package/dist/personas/content-reader/v1/prompts.js +64 -30
  84. package/dist/personas/content-reader/v1/resources/playbooks/compare.md +24 -9
  85. package/dist/personas/content-reader/v1/resources/playbooks/core.md +56 -29
  86. package/dist/personas/content-reader/v1/resources/playbooks/discover.md +27 -5
  87. package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +38 -8
  88. package/dist/personas/content-reader/v1/resources/playbooks/index.md +8 -8
  89. package/dist/personas/content-reader/v1/resources/playbooks.js +2 -2
  90. package/dist/personas/index.d.ts +1 -0
  91. package/dist/personas/index.js +27 -22
  92. package/dist/personas/index.test.js +68 -53
  93. package/dist/personas/lib/playbook-resources.d.ts +4 -3
  94. package/dist/personas/lib/playbook-resources.js +14 -10
  95. package/dist/personas/organization-audit/v1/prompts.js +68 -36
  96. package/dist/personas/organization-audit/v1/resources/playbooks/access.md +12 -4
  97. package/dist/personas/organization-audit/v1/resources/playbooks/content.md +13 -3
  98. package/dist/personas/organization-audit/v1/resources/playbooks/core.md +49 -16
  99. package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +8 -3
  100. package/dist/personas/organization-audit/v1/resources/playbooks/index.md +8 -8
  101. package/dist/personas/organization-audit/v1/resources/playbooks.js +1 -1
  102. package/dist/personas/persona.parity.test.js +14 -10
  103. package/dist/personas/semantic-layer/v1/prompts.js +50 -39
  104. package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +36 -31
  105. package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +53 -21
  106. package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +42 -39
  107. package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +6 -6
  108. package/dist/personas/semantic-layer/v1/resources/playbooks.js +2 -2
  109. package/dist/personas/types.d.ts +1 -1
  110. package/dist/policy/content-developer.d.ts +3 -3
  111. package/dist/policy/content-developer.js +3 -3
  112. package/dist/policy/content-developer.test.js +10 -4
  113. package/dist/policy/content-reader.d.ts +5 -1
  114. package/dist/policy/content-reader.js +18 -3
  115. package/dist/policy/content-reader.test.js +2 -1
  116. package/dist/policy/preview-ledger-fault.test.js +101 -426
  117. package/dist/policy/preview-ledger.d.ts +38 -74
  118. package/dist/policy/preview-ledger.js +108 -186
  119. package/dist/policy/preview-ledger.test.js +237 -111
  120. package/dist/policy/result-limits.d.ts +6 -1
  121. package/dist/policy/result-limits.js +28 -29
  122. package/dist/policy/result-limits.test.js +10 -1
  123. package/dist/server/capabilities.js +2 -0
  124. package/dist/server/capabilities.test.js +2 -0
  125. package/dist/server/server.js +12 -8
  126. package/dist/server/upstream-errors.d.ts +17 -0
  127. package/dist/server/upstream-errors.js +60 -0
  128. package/dist/server/upstream-errors.test.js +50 -0
  129. package/dist/stdio.process.test.js +4 -2
  130. package/dist/tools/ai-agents/agents.d.ts +7 -0
  131. package/dist/tools/ai-agents/agents.js +32 -0
  132. package/dist/tools/ai-agents/agents.test.js +176 -0
  133. package/dist/tools/ai-agents/discovery.d.ts +9 -0
  134. package/dist/tools/ai-agents/discovery.js +73 -0
  135. package/dist/tools/ai-agents/evaluations.d.ts +14 -0
  136. package/dist/tools/ai-agents/evaluations.js +177 -0
  137. package/dist/tools/ai-agents/helpers.d.ts +64 -0
  138. package/dist/tools/ai-agents/helpers.js +323 -0
  139. package/dist/tools/ai-agents/threads.d.ts +7 -0
  140. package/dist/tools/ai-agents/threads.js +40 -0
  141. package/dist/tools/organization/inventory.js +2 -1
  142. package/dist/tools/project/content.js +5 -1
  143. package/dist/tools/project/developer-content-preview.d.ts +2 -1
  144. package/dist/tools/project/developer-content-preview.js +40 -35
  145. package/dist/tools/project/developer-content-shared.d.ts +8 -2
  146. package/dist/tools/project/developer-content-shared.js +7 -3
  147. package/dist/tools/project/developer-content.d.ts +7 -8
  148. package/dist/tools/project/developer-content.js +72 -67
  149. package/dist/tools/project/developer-get-chart-as-code.d.ts +9 -0
  150. package/dist/tools/project/developer-get-chart-as-code.js +39 -0
  151. package/dist/tools/project/developer-get-chart-as-code.test.d.ts +4 -0
  152. package/dist/tools/project/developer-get-chart-as-code.test.js +70 -0
  153. package/dist/tools/project/developer-helpers.d.ts +1 -1
  154. package/dist/tools/project/developer-helpers.js +1 -1
  155. package/dist/tools/project/get-dashboard-promote-diff.js +12 -2
  156. package/dist/tools/project/invariants.test.js +5 -3
  157. package/dist/tools/project/projects.js +6 -4
  158. package/dist/tools/project/projects.test.js +44 -5
  159. package/dist/tools/project/reader-export-chart-image.d.ts +6 -0
  160. package/dist/tools/project/reader-export-chart-image.js +78 -0
  161. package/dist/tools/project/reader-export-chart-image.test.d.ts +4 -0
  162. package/dist/tools/project/reader-export-chart-image.test.js +149 -0
  163. package/dist/tools/query/bounded-saved-query.js +1 -1
  164. package/dist/tools/query/lifecycle.d.ts +1 -1
  165. package/dist/tools/query/lifecycle.js +17 -25
  166. package/dist/tools/query/query-ledger.d.ts +15 -8
  167. package/dist/tools/query/query-ledger.js +21 -15
  168. package/dist/tools/query/query-ledger.test.js +13 -11
  169. package/dist/tools/query/reader-tool-helpers.js +4 -6
  170. package/dist/tools/query/reader-tool-helpers.test.js +8 -4
  171. package/dist/tools/registry.d.ts +63 -0
  172. package/dist/tools/registry.js +26 -0
  173. package/dist/tools/shared.d.ts +27 -8
  174. package/dist/tools/shared.js +61 -28
  175. package/dist/tools/shared.test.js +100 -4
  176. package/dist/transports/streamable-http.js +48 -206
  177. package/dist/transports/streamable-http.test.js +10 -3
  178. package/package.json +5 -6
  179. package/dist/destructive/confirmation-claim.d.ts +0 -21
  180. package/dist/destructive/confirmation-claim.js +0 -87
  181. package/dist/destructive/confirmation-claim.test.js +0 -50
  182. package/dist/store/config.d.ts +0 -11
  183. package/dist/store/config.js +0 -50
  184. package/dist/store/config.test.js +0 -56
  185. package/dist/store/create-oauth-broker-store.d.ts +0 -6
  186. package/dist/store/create-oauth-broker-store.js +0 -16
  187. package/dist/store/create-preview-store.d.ts +0 -10
  188. package/dist/store/create-preview-store.js +0 -30
  189. package/dist/store/create-session-store.d.ts +0 -19
  190. package/dist/store/create-session-store.js +0 -24
  191. package/dist/store/in-memory-preview-store.d.ts +0 -17
  192. package/dist/store/in-memory-preview-store.js +0 -72
  193. package/dist/store/redis-client.d.ts +0 -11
  194. package/dist/store/redis-client.js +0 -48
  195. package/dist/store/redis-oauth-broker-store.d.ts +0 -42
  196. package/dist/store/redis-oauth-broker-store.js +0 -167
  197. package/dist/store/redis-oauth-broker-store.test.js +0 -80
  198. package/dist/store/redis-preview-store.d.ts +0 -23
  199. package/dist/store/redis-preview-store.js +0 -94
  200. package/dist/store/redis-preview-store.test.d.ts +0 -1
  201. package/dist/store/redis-preview-store.test.js +0 -39
  202. package/dist/store/redis-session-index.d.ts +0 -33
  203. package/dist/store/redis-session-index.js +0 -49
  204. package/dist/store/types.d.ts +0 -13
  205. package/dist/store/types.js +0 -8
  206. package/dist/transports/http-request-utils.d.ts +0 -2
  207. package/dist/transports/http-request-utils.js +0 -13
  208. package/dist/transports/session-store.d.ts +0 -72
  209. package/dist/transports/session-store.js +0 -143
  210. package/dist/transports/session-store.test.d.ts +0 -1
  211. package/dist/transports/session-store.test.js +0 -111
  212. /package/dist/{destructive/confirmation-claim.test.d.ts → governance/client-capabilities-cache.test.d.ts} +0 -0
  213. /package/dist/{store/config.test.d.ts → server/upstream-errors.test.d.ts} +0 -0
  214. /package/dist/{store/redis-oauth-broker-store.test.d.ts → tools/ai-agents/agents.test.d.ts} +0 -0
@@ -4,22 +4,14 @@ const node_http_1 = require("node:http");
4
4
  const client_1 = require("@lightdash-tools/client");
5
5
  const vitest_1 = require("vitest");
6
6
  const oauth_protected_resource_js_1 = require("./auth/resource-server/oauth-protected-resource.js");
7
+ const client_capabilities_cache_js_1 = require("./governance/client-capabilities-cache.js");
7
8
  const streamable_http_js_1 = require("./transports/streamable-http.js");
8
9
  const TOKEN_A = scopedAccessToken('mcp:read mcp:write', 'token-a');
9
10
  const TOKEN_B = scopedAccessToken('mcp:read mcp:write', 'token-b');
10
- const TOKEN_A_REFRESHED = scopedAccessToken('mcp:read mcp:write', 'token-a-refreshed');
11
11
  const TOKEN_READ_ONLY = scopedAccessToken('mcp:read', 'token-read-only');
12
12
  const OPAQUE_TOKEN_A = 'opaque-token-user-a';
13
- const OPAQUE_TOKEN_ORG_B = 'opaque-token-org-b';
14
- const OPAQUE_TOKEN_A_NO_ORG = 'opaque-token-user-a-no-org';
15
13
  const USER_A = { userUuid: 'user-a-uuid', email: 'a@example.com', organizationUuid: 'org-a-uuid' };
16
14
  const USER_B = { userUuid: 'user-b-uuid', email: 'b@example.com', organizationUuid: 'org-b-uuid' };
17
- const USER_A_ORG_B = {
18
- userUuid: 'user-a-uuid',
19
- email: 'a@example.com',
20
- organizationUuid: 'org-b-uuid',
21
- };
22
- const USER_A_NO_ORG = { userUuid: 'user-a-uuid', email: 'a@example.com' };
23
15
  function scopedAccessToken(scope, subject) {
24
16
  const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
25
17
  const payload = Buffer.from(JSON.stringify({ scope, sub: subject })).toString('base64url');
@@ -48,12 +40,9 @@ async function startMockLightdashServer() {
48
40
  const authorizationHeaders = [];
49
41
  const users = {
50
42
  [TOKEN_A]: USER_A,
51
- [TOKEN_A_REFRESHED]: USER_A,
52
43
  [TOKEN_B]: USER_B,
53
44
  [TOKEN_READ_ONLY]: USER_A,
54
45
  [OPAQUE_TOKEN_A]: USER_A,
55
- [OPAQUE_TOKEN_ORG_B]: USER_A_ORG_B,
56
- [OPAQUE_TOKEN_A_NO_ORG]: USER_A_NO_ORG,
57
46
  };
58
47
  let issuerBaseUrl = '';
59
48
  const server = (0, node_http_1.createServer)((req, res) => {
@@ -138,10 +127,6 @@ function baseOAuthConfig(lightdashUrl) {
138
127
  oauthClientSecret: new client_1.SecretString('test-client-secret'),
139
128
  allowedOrigins: [],
140
129
  maxBodyBytes: 1024 * 1024,
141
- sessionTtlMs: 60000,
142
- maxSessions: 10,
143
- maxSessionsPerSubject: 10,
144
- sessionCleanupMs: 60000,
145
130
  requiredScopes: [],
146
131
  scopesSupported: [],
147
132
  validateToken: true,
@@ -149,6 +134,7 @@ function baseOAuthConfig(lightdashUrl) {
149
134
  };
150
135
  }
151
136
  async function postMcp(baseUrl, body, options) {
137
+ var _a;
152
138
  const headers = {
153
139
  'Content-Type': 'application/json',
154
140
  Accept: 'application/json, text/event-stream',
@@ -156,27 +142,22 @@ async function postMcp(baseUrl, body, options) {
156
142
  if (options === null || options === void 0 ? void 0 : options.token) {
157
143
  headers.Authorization = `Bearer ${options.token}`;
158
144
  }
159
- if (options === null || options === void 0 ? void 0 : options.sessionId) {
160
- headers['Mcp-Session-Id'] = options.sessionId;
161
- }
162
- return fetch(`${baseUrl}/semantic-layer/v1/mcp`, {
145
+ const path = (_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : '/semantic-layer/v1/mcp';
146
+ return fetch(`${baseUrl}${path}`, {
163
147
  method: 'POST',
164
148
  headers,
165
149
  body: JSON.stringify(body),
166
150
  });
167
151
  }
168
- async function parseMcpResponse(response) {
169
- var _a;
170
- const contentType = (_a = response.headers.get('content-type')) !== null && _a !== void 0 ? _a : '';
171
- const text = await response.text();
172
- if (contentType.includes('application/json')) {
173
- return JSON.parse(text);
152
+ function parseSseOrJsonToolText(raw) {
153
+ if (raw.includes('data:')) {
154
+ const lines = raw
155
+ .split('\n')
156
+ .filter((line) => line.startsWith('data:'))
157
+ .map((line) => line.slice('data:'.length).trim());
158
+ return lines.join('\n');
174
159
  }
175
- const dataLines = text.split('\n').filter((line) => line.startsWith('data: '));
176
- const last = dataLines.length > 0 ? dataLines[dataLines.length - 1] : undefined;
177
- if (!last)
178
- return text;
179
- return JSON.parse(last.slice('data: '.length));
160
+ return raw;
180
161
  }
181
162
  (0, vitest_1.describe)('MCP HTTP OAuth integration (RFC §16.3 matrix)', () => {
182
163
  let mockLightdash;
@@ -190,6 +171,7 @@ async function parseMcpResponse(response) {
190
171
  (0, vitest_1.afterEach)(async () => {
191
172
  await mcpServer.close();
192
173
  await mockLightdash.close();
174
+ (0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
193
175
  vitest_1.vi.restoreAllMocks();
194
176
  });
195
177
  (0, vitest_1.it)('returns 401 with WWW-Authenticate resource_metadata when OAuth token is missing', async () => {
@@ -207,78 +189,13 @@ async function parseMcpResponse(response) {
207
189
  (0, vitest_1.expect)(body).not.toContain(invalidToken);
208
190
  (0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
209
191
  });
210
- (0, vitest_1.it)('initializes MCP session with valid OAuth bearer and validates upstream Authorization', async () => {
192
+ (0, vitest_1.it)('handles initialize with valid OAuth bearer and validates upstream Authorization', async () => {
211
193
  const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
212
194
  (0, vitest_1.expect)(response.status).toBe(200);
213
- (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeTruthy();
195
+ // Sessionless: no session-id header is set
196
+ (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
214
197
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
215
198
  });
216
- (0, vitest_1.it)('returns 401 before 404 for unknown session without auth', async () => {
217
- const response = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { sessionId: 'unknown-session-id' });
218
- (0, vitest_1.expect)(response.status).toBe(401);
219
- (0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('resource_metadata=');
220
- });
221
- (0, vitest_1.it)('returns 401 Session subject mismatch when resuming with a different user bearer', async () => {
222
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
223
- const sessionId = initResponse.headers.get('mcp-session-id');
224
- (0, vitest_1.expect)(sessionId).toBeTruthy();
225
- const resumeResponse = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_B, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
226
- (0, vitest_1.expect)(resumeResponse.status).toBe(401);
227
- (0, vitest_1.expect)(await resumeResponse.json()).toEqual({
228
- error: 'invalid_token',
229
- error_description: 'Session subject mismatch',
230
- });
231
- (0, vitest_1.expect)(resumeResponse.headers.get('www-authenticate')).toContain('invalid_token');
232
- });
233
- (0, vitest_1.it)('returns 401 Session organization mismatch when resuming with a different org context', async () => {
234
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
235
- token: OPAQUE_TOKEN_A,
236
- });
237
- const sessionId = initResponse.headers.get('mcp-session-id');
238
- (0, vitest_1.expect)(sessionId).toBeTruthy();
239
- const resumeResponse = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: OPAQUE_TOKEN_ORG_B, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
240
- (0, vitest_1.expect)(resumeResponse.status).toBe(401);
241
- (0, vitest_1.expect)(await resumeResponse.json()).toEqual({
242
- error: 'invalid_token',
243
- error_description: 'Session organization mismatch',
244
- });
245
- (0, vitest_1.expect)(resumeResponse.headers.get('www-authenticate')).toContain('invalid_token');
246
- });
247
- (0, vitest_1.it)('returns 401 Session organization mismatch when org disappears on resume', async () => {
248
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
249
- token: OPAQUE_TOKEN_A,
250
- });
251
- const sessionId = initResponse.headers.get('mcp-session-id');
252
- (0, vitest_1.expect)(sessionId).toBeTruthy();
253
- const resumeResponse = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: OPAQUE_TOKEN_A_NO_ORG, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
254
- (0, vitest_1.expect)(resumeResponse.status).toBe(401);
255
- (0, vitest_1.expect)(await resumeResponse.json()).toEqual({
256
- error: 'invalid_token',
257
- error_description: 'Session organization mismatch',
258
- });
259
- });
260
- (0, vitest_1.it)('protected-resource metadata authorization_servers points at MCP broker AS metadata', async () => {
261
- const response = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource`);
262
- (0, vitest_1.expect)(response.status).toBe(200);
263
- const metadata = (await response.json());
264
- (0, vitest_1.expect)(metadata.authorization_servers).toEqual([mcpServer.baseUrl]);
265
- const asMetadataUrl = (0, oauth_protected_resource_js_1.getAuthorizationServerMetadataUrl)(metadata.authorization_servers[0]);
266
- (0, vitest_1.expect)(asMetadataUrl).toBe(`${mcpServer.baseUrl}/.well-known/oauth-authorization-server`);
267
- const asResponse = await fetch(asMetadataUrl);
268
- (0, vitest_1.expect)(asResponse.status).toBe(200);
269
- const asMetadata = (await asResponse.json());
270
- (0, vitest_1.expect)(asMetadata.authorization_endpoint).toBe(`${mcpServer.baseUrl}/oauth/authorize`);
271
- (0, vitest_1.expect)(asMetadata.token_endpoint).toBe(`${mcpServer.baseUrl}/oauth/token`);
272
- (0, vitest_1.expect)(asMetadata.registration_endpoint).toBe(`${mcpServer.baseUrl}/oauth/register`);
273
- });
274
- (0, vitest_1.it)('allows token refresh for the same OAuth subject within a session', async () => {
275
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
276
- const sessionId = initResponse.headers.get('mcp-session-id');
277
- (0, vitest_1.expect)(sessionId).toBeTruthy();
278
- const resumeResponse = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_A_REFRESHED, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
279
- (0, vitest_1.expect)([200, 202]).toContain(resumeResponse.status);
280
- (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A_REFRESHED}`);
281
- });
282
199
  (0, vitest_1.it)('returns 401 before parsing malformed JSON when OAuth token is missing', async () => {
283
200
  const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
284
201
  method: 'POST',
@@ -387,6 +304,28 @@ async function parseMcpResponse(response) {
387
304
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
388
305
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_B}`);
389
306
  });
307
+ (0, vitest_1.it)('bridges initialize form-elicitation caps to a later content-governance tools/call', async () => {
308
+ const governancePath = '/content-governance/v1/mcp';
309
+ const init = await postMcp(mcpServer.baseUrl, Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { capabilities: { elicitation: { form: {} } } }) }), { token: TOKEN_A, path: governancePath });
310
+ (0, vitest_1.expect)(init.status).toBe(200);
311
+ const call = await postMcp(mcpServer.baseUrl, {
312
+ jsonrpc: '2.0',
313
+ method: 'tools/call',
314
+ params: {
315
+ name: 'lightdash_delete_chart',
316
+ arguments: {
317
+ projectUuid: '11111111-1111-4111-8111-111111111111',
318
+ chartUuidOrSlug: '22222222-2222-4222-8222-222222222222',
319
+ },
320
+ },
321
+ id: 2,
322
+ }, { token: TOKEN_A, path: governancePath });
323
+ (0, vitest_1.expect)(call.status).toBe(200);
324
+ const text = parseSseOrJsonToolText(await call.text());
325
+ // Caps bridge worked: past ELICITATION_REQUIRED into chart resolve (mock has no chart).
326
+ (0, vitest_1.expect)(text).not.toContain('ELICITATION_REQUIRED');
327
+ (0, vitest_1.expect)(text).toContain('CONTENT_NOT_FOUND');
328
+ });
390
329
  (0, vitest_1.it)('returns 503 when Lightdash user validation is unavailable', async () => {
391
330
  const unavailableServer = (0, node_http_1.createServer)((_req, res) => {
392
331
  res.writeHead(503, { 'Content-Type': 'application/json' }).end(JSON.stringify({
@@ -419,6 +358,64 @@ async function parseMcpResponse(response) {
419
358
  }
420
359
  });
421
360
  });
361
+ (0, vitest_1.describe)('MCP HTTP OAuth integration (continued)', () => {
362
+ let mockLightdash;
363
+ let mcpServer;
364
+ (0, vitest_1.beforeEach)(async () => {
365
+ vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
366
+ vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
367
+ mockLightdash = await startMockLightdashServer();
368
+ mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(mockLightdash.baseUrl)));
369
+ });
370
+ (0, vitest_1.afterEach)(async () => {
371
+ await mcpServer.close();
372
+ await mockLightdash.close();
373
+ (0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
374
+ vitest_1.vi.restoreAllMocks();
375
+ });
376
+ (0, vitest_1.it)('protected-resource metadata authorization_servers points at MCP broker AS metadata', async () => {
377
+ const response = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource`);
378
+ (0, vitest_1.expect)(response.status).toBe(200);
379
+ const metadata = (await response.json());
380
+ (0, vitest_1.expect)(metadata.authorization_servers).toEqual([mcpServer.baseUrl]);
381
+ const asMetadataUrl = (0, oauth_protected_resource_js_1.getAuthorizationServerMetadataUrl)(metadata.authorization_servers[0]);
382
+ (0, vitest_1.expect)(asMetadataUrl).toBe(`${mcpServer.baseUrl}/.well-known/oauth-authorization-server`);
383
+ const asResponse = await fetch(asMetadataUrl);
384
+ (0, vitest_1.expect)(asResponse.status).toBe(200);
385
+ const asMetadata = (await asResponse.json());
386
+ (0, vitest_1.expect)(asMetadata.authorization_endpoint).toBe(`${mcpServer.baseUrl}/oauth/authorize`);
387
+ (0, vitest_1.expect)(asMetadata.token_endpoint).toBe(`${mcpServer.baseUrl}/oauth/token`);
388
+ (0, vitest_1.expect)(asMetadata.registration_endpoint).toBe(`${mcpServer.baseUrl}/oauth/register`);
389
+ });
390
+ (0, vitest_1.it)('handles initialize with opaque OAuth bearer when endpoint scopes are unset', async () => {
391
+ const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: OPAQUE_TOKEN_A });
392
+ (0, vitest_1.expect)(response.status).toBe(200);
393
+ (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
394
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${OPAQUE_TOKEN_A}`);
395
+ });
396
+ (0, vitest_1.it)('accepts TOKEN_READ_ONLY (mcp:read scope) on initialize', async () => {
397
+ const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
398
+ token: TOKEN_READ_ONLY,
399
+ });
400
+ (0, vitest_1.expect)(response.status).toBe(200);
401
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_READ_ONLY}`);
402
+ });
403
+ (0, vitest_1.it)('accepts TOKEN_A (mcp:read mcp:write scope) on initialize', async () => {
404
+ const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
405
+ token: TOKEN_A,
406
+ });
407
+ (0, vitest_1.expect)(response.status).toBe(200);
408
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
409
+ });
410
+ (0, vitest_1.it)('forwards bearer token to Lightdash on initialize for opaque credentials', async () => {
411
+ const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
412
+ token: OPAQUE_TOKEN_A,
413
+ });
414
+ (0, vitest_1.expect)(response.status).toBe(200);
415
+ const userHeaders = mockLightdash.authorizationHeaders.filter((h) => h === `Bearer ${OPAQUE_TOKEN_A}`);
416
+ (0, vitest_1.expect)(userHeaders.length).toBeGreaterThan(0);
417
+ });
418
+ });
422
419
  (0, vitest_1.describe)('MCP HTTP CORS integration', () => {
423
420
  let mockLightdash;
424
421
  let mcpServer;
@@ -431,6 +428,7 @@ async function parseMcpResponse(response) {
431
428
  (0, vitest_1.afterEach)(async () => {
432
429
  await mcpServer.close();
433
430
  await mockLightdash.close();
431
+ (0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
434
432
  vitest_1.vi.restoreAllMocks();
435
433
  });
436
434
  (0, vitest_1.it)('sets CORS headers for allowed origins on metadata', async () => {
@@ -462,126 +460,7 @@ async function parseMcpResponse(response) {
462
460
  (0, vitest_1.expect)(body.error).toContain('origin not allowed');
463
461
  });
464
462
  });
465
- (0, vitest_1.describe)('MCP HTTP OAuth integration (continued)', () => {
466
- let mockLightdash;
467
- let mcpServer;
468
- (0, vitest_1.beforeEach)(async () => {
469
- vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
470
- vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
471
- mockLightdash = await startMockLightdashServer();
472
- mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(mockLightdash.baseUrl)));
473
- });
474
- (0, vitest_1.afterEach)(async () => {
475
- await mcpServer.close();
476
- await mockLightdash.close();
477
- vitest_1.vi.restoreAllMocks();
478
- });
479
- (0, vitest_1.it)('calls lightdash_list_projects over an OAuth HTTP session', async () => {
480
- var _a, _b, _c, _d;
481
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
482
- const sessionId = initResponse.headers.get('mcp-session-id');
483
- (0, vitest_1.expect)(sessionId).toBeTruthy();
484
- const userCallsBefore = mockLightdash.authorizationHeaders.length;
485
- await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_A, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
486
- const callResponse = await postMcp(mcpServer.baseUrl, {
487
- jsonrpc: '2.0',
488
- method: 'tools/call',
489
- params: { name: 'lightdash_list_projects', arguments: {} },
490
- id: 2,
491
- }, { token: TOKEN_A, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
492
- (0, vitest_1.expect)(callResponse.status).toBe(200);
493
- const payload = (await parseMcpResponse(callResponse));
494
- const text = (_d = (_c = (_b = (_a = payload.result) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : '';
495
- (0, vitest_1.expect)(text).toContain('project-a-uuid');
496
- (0, vitest_1.expect)(text).not.toContain(TOKEN_A);
497
- (0, vitest_1.expect)(mockLightdash.authorizationHeaders.length).toBeGreaterThan(userCallsBefore);
498
- (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
499
- });
500
- (0, vitest_1.it)('forwards refreshed bearer token to Lightdash on tool calls after session resume', async () => {
501
- var _a, _b, _c, _d;
502
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
503
- const sessionId = initResponse.headers.get('mcp-session-id');
504
- (0, vitest_1.expect)(sessionId).toBeTruthy();
505
- await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_A_REFRESHED, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
506
- const headersBeforeTool = mockLightdash.authorizationHeaders.length;
507
- const callResponse = await postMcp(mcpServer.baseUrl, {
508
- jsonrpc: '2.0',
509
- method: 'tools/call',
510
- params: { name: 'lightdash_list_projects', arguments: {} },
511
- id: 6,
512
- }, { token: TOKEN_A_REFRESHED, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
513
- (0, vitest_1.expect)(callResponse.status).toBe(200);
514
- const payload = (await parseMcpResponse(callResponse));
515
- (0, vitest_1.expect)((_d = (_c = (_b = (_a = payload.result) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : '').toContain('project-a-uuid');
516
- const toolHeaders = mockLightdash.authorizationHeaders.slice(headersBeforeTool);
517
- (0, vitest_1.expect)(toolHeaders).toContain(`Bearer ${TOKEN_A_REFRESHED}`);
518
- (0, vitest_1.expect)(toolHeaders).not.toContain(`Bearer ${TOKEN_A}`);
519
- });
520
- (0, vitest_1.it)('initializes MCP session with opaque OAuth bearer when endpoint scopes are unset', async () => {
521
- const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: OPAQUE_TOKEN_A });
522
- (0, vitest_1.expect)(response.status).toBe(200);
523
- (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeTruthy();
524
- (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${OPAQUE_TOKEN_A}`);
525
- });
526
- (0, vitest_1.it)('lists nine semantic-layer tools under mcp:read-only JWT scopes', async () => {
527
- var _a, _b, _c;
528
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
529
- token: TOKEN_READ_ONLY,
530
- });
531
- const sessionId = initResponse.headers.get('mcp-session-id');
532
- (0, vitest_1.expect)(sessionId).toBeTruthy();
533
- await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_READ_ONLY, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
534
- const listResponse = await postMcp(mcpServer.baseUrl, {
535
- jsonrpc: '2.0',
536
- method: 'tools/list',
537
- id: 3,
538
- }, { token: TOKEN_READ_ONLY, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
539
- (0, vitest_1.expect)(listResponse.status).toBe(200);
540
- const payload = (await parseMcpResponse(listResponse));
541
- (0, vitest_1.expect)((_a = payload.result) === null || _a === void 0 ? void 0 : _a.tools).toHaveLength(9);
542
- (0, vitest_1.expect)((_c = (_b = payload.result) === null || _b === void 0 ? void 0 : _b.tools) === null || _c === void 0 ? void 0 : _c.every((t) => t.name.startsWith('lightdash_'))).toBe(true);
543
- });
544
- (0, vitest_1.it)('allows read tools when JWT scopes include mcp:read only', async () => {
545
- var _a, _b, _c, _d, _e;
546
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
547
- token: TOKEN_READ_ONLY,
548
- });
549
- const sessionId = initResponse.headers.get('mcp-session-id');
550
- (0, vitest_1.expect)(sessionId).toBeTruthy();
551
- await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_READ_ONLY, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
552
- const callResponse = await postMcp(mcpServer.baseUrl, {
553
- jsonrpc: '2.0',
554
- method: 'tools/call',
555
- params: { name: 'lightdash_list_projects', arguments: {} },
556
- id: 4,
557
- }, { token: TOKEN_READ_ONLY, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
558
- (0, vitest_1.expect)(callResponse.status).toBe(200);
559
- const payload = (await parseMcpResponse(callResponse));
560
- (0, vitest_1.expect)((_a = payload.result) === null || _a === void 0 ? void 0 : _a.isError).not.toBe(true);
561
- (0, vitest_1.expect)((_e = (_d = (_c = (_b = payload.result) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : '').toContain('project-a-uuid');
562
- });
563
- (0, vitest_1.it)('does not block read tools for opaque OAuth credentials without local scope claims', async () => {
564
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
565
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
566
- token: OPAQUE_TOKEN_A,
567
- });
568
- const sessionId = initResponse.headers.get('mcp-session-id');
569
- (0, vitest_1.expect)(sessionId).toBeTruthy();
570
- await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: OPAQUE_TOKEN_A, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
571
- const callResponse = await postMcp(mcpServer.baseUrl, {
572
- jsonrpc: '2.0',
573
- method: 'tools/call',
574
- params: { name: 'lightdash_list_projects', arguments: {} },
575
- id: 5,
576
- }, { token: OPAQUE_TOKEN_A, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
577
- (0, vitest_1.expect)(callResponse.status).toBe(200);
578
- const payload = (await parseMcpResponse(callResponse));
579
- (0, vitest_1.expect)((_a = payload.result) === null || _a === void 0 ? void 0 : _a.isError).not.toBe(true);
580
- (0, vitest_1.expect)((_e = (_d = (_c = (_b = payload.result) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : '').not.toContain('insufficient_scope');
581
- (0, vitest_1.expect)((_j = (_h = (_g = (_f = payload.result) === null || _f === void 0 ? void 0 : _f.content) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.text) !== null && _j !== void 0 ? _j : '').toContain('project-a-uuid');
582
- });
583
- });
584
- (0, vitest_1.describe)('MCP HTTP OAuth transport lifecycle', () => {
463
+ (0, vitest_1.describe)('MCP HTTP transport (sessionless)', () => {
585
464
  let mockLightdash;
586
465
  let mcpServer;
587
466
  (0, vitest_1.beforeEach)(async () => {
@@ -593,63 +472,41 @@ async function parseMcpResponse(response) {
593
472
  (0, vitest_1.afterEach)(async () => {
594
473
  await mcpServer.close();
595
474
  await mockLightdash.close();
475
+ (0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
596
476
  vitest_1.vi.restoreAllMocks();
597
477
  });
598
- (0, vitest_1.it)('supports initialize → notification → GET on the same OAuth session', async () => {
599
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
600
- const sessionId = initResponse.headers.get('mcp-session-id');
601
- (0, vitest_1.expect)(sessionId).toBeTruthy();
602
- const notifyResponse = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_A, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
603
- (0, vitest_1.expect)([200, 202]).toContain(notifyResponse.status);
604
- const getResponse = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
605
- method: 'GET',
606
- headers: {
607
- Accept: 'application/json, text/event-stream',
608
- Authorization: `Bearer ${TOKEN_A}`,
609
- 'Mcp-Session-Id': sessionId !== null && sessionId !== void 0 ? sessionId : '',
610
- },
611
- });
612
- (0, vitest_1.expect)(getResponse.status).not.toBe(401);
613
- (0, vitest_1.expect)(getResponse.status).not.toBe(404);
614
- });
615
478
  (0, vitest_1.it)('returns 413 for oversized JSON body after OAuth authentication', async () => {
616
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
617
- const sessionId = initResponse.headers.get('mcp-session-id');
618
- (0, vitest_1.expect)(sessionId).toBeTruthy();
619
- const hugeBody = JSON.stringify({
620
- jsonrpc: '2.0',
621
- method: 'notifications/initialized',
622
- params: { padding: 'x'.repeat(1024) },
623
- });
479
+ const hugeBody = JSON.stringify(Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { padding: 'x'.repeat(1024) }) }));
624
480
  const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
625
481
  method: 'POST',
626
482
  headers: {
627
483
  'Content-Type': 'application/json',
628
484
  Accept: 'application/json, text/event-stream',
629
485
  Authorization: `Bearer ${TOKEN_A}`,
630
- 'Mcp-Session-Id': sessionId !== null && sessionId !== void 0 ? sessionId : '',
631
486
  },
632
487
  body: hugeBody,
633
488
  });
634
489
  (0, vitest_1.expect)(response.status).toBe(413);
635
490
  (0, vitest_1.expect)(await response.json()).toEqual({ error: 'Payload Too Large' });
636
491
  });
637
- (0, vitest_1.it)('closes session on DELETE and rejects subsequent resume with 404', async () => {
638
- const initResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
639
- const sessionId = initResponse.headers.get('mcp-session-id');
640
- (0, vitest_1.expect)(sessionId).toBeTruthy();
641
- const deleteResponse = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
642
- method: 'DELETE',
492
+ (0, vitest_1.it)('returns 405 for GET on persona endpoint (sessionless, no persistent streams)', async () => {
493
+ const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
494
+ method: 'GET',
643
495
  headers: {
644
496
  Accept: 'application/json, text/event-stream',
645
497
  Authorization: `Bearer ${TOKEN_A}`,
646
- 'Mcp-Session-Id': sessionId !== null && sessionId !== void 0 ? sessionId : '',
647
498
  },
648
499
  });
649
- (0, vitest_1.expect)([200, 202, 204]).toContain(deleteResponse.status);
650
- const resumeResponse = await postMcp(mcpServer.baseUrl, { jsonrpc: '2.0', method: 'notifications/initialized' }, { token: TOKEN_A, sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : undefined });
651
- (0, vitest_1.expect)(resumeResponse.status).toBe(404);
652
- (0, vitest_1.expect)(await resumeResponse.json()).toEqual({ error: 'Session not found' });
500
+ (0, vitest_1.expect)(response.status).toBe(405);
501
+ });
502
+ (0, vitest_1.it)('returns 405 for DELETE on persona endpoint (sessionless, no sessions to close)', async () => {
503
+ const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
504
+ method: 'DELETE',
505
+ headers: {
506
+ Authorization: `Bearer ${TOKEN_A}`,
507
+ },
508
+ });
509
+ (0, vitest_1.expect)(response.status).toBe(405);
653
510
  });
654
511
  });
655
512
  (0, vitest_1.describe)('MCP HTTP shared-key integration', () => {
@@ -669,10 +526,6 @@ async function parseMcpResponse(response) {
669
526
  sharedKey: new client_1.SecretString('shared-secret'),
670
527
  allowedOrigins: [],
671
528
  maxBodyBytes: 1024 * 1024,
672
- sessionTtlMs: 60000,
673
- maxSessions: 10,
674
- maxSessionsPerSubject: 10,
675
- sessionCleanupMs: 60000,
676
529
  requiredScopes: [],
677
530
  scopesSupported: ['mcp:read'],
678
531
  validateToken: false,
@@ -682,6 +535,7 @@ async function parseMcpResponse(response) {
682
535
  (0, vitest_1.afterEach)(async () => {
683
536
  await mcpServer.close();
684
537
  process.env = Object.assign({}, originalEnv);
538
+ (0, client_capabilities_cache_js_1.resetClientCapabilitiesCacheForTests)();
685
539
  vitest_1.vi.restoreAllMocks();
686
540
  });
687
541
  (0, vitest_1.it)('requires shared key on MCP endpoint', async () => {
@@ -691,7 +545,8 @@ async function parseMcpResponse(response) {
691
545
  token: 'shared-secret',
692
546
  });
693
547
  (0, vitest_1.expect)(authorized.status).toBe(200);
694
- (0, vitest_1.expect)(authorized.headers.get('mcp-session-id')).toBeTruthy();
548
+ // Sessionless: no session-id
549
+ (0, vitest_1.expect)(authorized.headers.get('mcp-session-id')).toBeFalsy();
695
550
  });
696
551
  (0, vitest_1.it)('returns 401 before reading oversized bodies when shared key is missing', async () => {
697
552
  const hugeBody = JSON.stringify(Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { padding: 'x'.repeat(2048) }) }));
@@ -717,6 +572,6 @@ async function parseMcpResponse(response) {
717
572
  body: JSON.stringify(INITIALIZE_BODY),
718
573
  });
719
574
  (0, vitest_1.expect)(response.status).toBe(200);
720
- (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeTruthy();
575
+ (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
721
576
  });
722
577
  });
package/dist/http.test.js CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const node_events_1 = require("node:events");
7
7
  const vitest_1 = require("vitest");
8
8
  const http_body_js_1 = require("./transports/http-body.js");
9
- const http_request_utils_js_1 = require("./transports/http-request-utils.js");
10
9
  const http_response_js_1 = require("./transports/http-response.js");
11
10
  function createMockResponse() {
12
11
  const res = {
@@ -117,15 +116,4 @@ function createMockResponse() {
117
116
  (0, vitest_1.expect)((0, http_body_js_1.parseJsonBody)(Buffer.from(' '))).toBeUndefined();
118
117
  });
119
118
  });
120
- (0, vitest_1.describe)('initialize detection', () => {
121
- (0, vitest_1.it)('detects initialize POST body', () => {
122
- (0, vitest_1.expect)((0, http_request_utils_js_1.isInitializeMessage)({ jsonrpc: '2.0', method: 'initialize', id: 1 })).toBe(true);
123
- });
124
- (0, vitest_1.it)('detects initialize in batch array', () => {
125
- (0, vitest_1.expect)((0, http_request_utils_js_1.isInitializeMessage)([{ jsonrpc: '2.0', method: 'initialize', id: 1 }])).toBe(true);
126
- });
127
- (0, vitest_1.it)('returns false for non-initialize methods', () => {
128
- (0, vitest_1.expect)((0, http_request_utils_js_1.isInitializeMessage)({ jsonrpc: '2.0', method: 'tools/list', id: 1 })).toBe(false);
129
- });
130
- });
131
119
  });
@@ -64,10 +64,6 @@ vitest_1.describe.runIf(hasOAuthToken)('MCP Integration (OAuth access token)', (
64
64
  authMode: 'lightdash-oauth',
65
65
  allowedOrigins: [],
66
66
  maxBodyBytes: 1024 * 1024,
67
- sessionTtlMs: 60000,
68
- maxSessions: 10,
69
- maxSessionsPerSubject: 10,
70
- sessionCleanupMs: 60000,
71
67
  requiredScopes: ['mcp:read'],
72
68
  scopesSupported: ['mcp:read', 'mcp:write'],
73
69
  validateToken: true,
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ const stdio_1 = require("@modelcontextprotocol/server/stdio");
10
10
  const audit_js_1 = require("./audit/audit.js");
11
11
  const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
12
12
  const runtime_js_1 = require("./config/runtime.js");
13
+ const available_projects_js_1 = require("./governance/available-projects.js");
13
14
  const index_js_1 = require("./personas/index.js");
14
15
  const server_js_1 = require("./server/server.js");
15
16
  function resolveStdioPersona() {
@@ -19,12 +20,13 @@ function resolveStdioPersona() {
19
20
  }
20
21
  const id = (0, index_js_1.parsePersonaId)(raw);
21
22
  if (!id) {
22
- throw new Error(`Invalid LIGHTDASH_TOOLS_MCP_STDIO_PERSONA='${raw}'. Expected semantic-layer, organization-audit, content-reader, content-developer, or content-governance.`);
23
+ throw new Error(`Invalid LIGHTDASH_TOOLS_MCP_STDIO_PERSONA='${raw}'. Expected semantic-layer, organization-audit, content-reader, content-developer, content-governance, or ai-agent-ops.`);
23
24
  }
24
25
  return (0, index_js_1.getPersona)(id);
25
26
  }
26
27
  async function main() {
27
28
  (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
29
+ (0, available_projects_js_1.validateAvailableProjectsConfig)();
28
30
  (0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
29
31
  const persona = resolveStdioPersona();
30
32
  const contextProvider = new env_context_provider_js_1.EnvContextProvider();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * AI agent-ops persona: thin Lightdash AI-agent API surface (ADR-0018).
3
+ */
4
+ import type { PersonaDefinition } from '../../types.js';
5
+ export declare const AI_AGENT_OPS_PERSONA_PATH: "/ai-agent-ops/v1/mcp";
6
+ /** Explicit allowlist — Lightdash API primitives only; no offline eval mega-tools. */
7
+ export declare const AI_AGENT_OPS_TOOL_IDS: readonly ["list_project_agents", "get_project_agent", "evaluate_agent_readiness", "get_agent_suggestions", "get_agent_models", "get_explore_access_summary", "list_agent_threads", "get_agent_thread", "list_agent_evaluations", "get_agent_evaluation", "create_agent_evaluation", "update_agent_evaluation", "append_agent_evaluation_prompts", "delete_agent_evaluation", "run_agent_evaluation", "list_agent_evaluation_runs", "get_agent_eval_run_results"];
8
+ export declare const aiAgentOpsPersona: PersonaDefinition;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * AI agent-ops persona: thin Lightdash AI-agent API surface (ADR-0018).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.aiAgentOpsPersona = exports.AI_AGENT_OPS_TOOL_IDS = exports.AI_AGENT_OPS_PERSONA_PATH = void 0;
7
+ const prompts_js_1 = require("./prompts.js");
8
+ const playbooks_js_1 = require("./resources/playbooks.js");
9
+ exports.AI_AGENT_OPS_PERSONA_PATH = '/ai-agent-ops/v1/mcp';
10
+ /** Explicit allowlist — Lightdash API primitives only; no offline eval mega-tools. */
11
+ exports.AI_AGENT_OPS_TOOL_IDS = [
12
+ 'list_project_agents',
13
+ 'get_project_agent',
14
+ 'evaluate_agent_readiness',
15
+ 'get_agent_suggestions',
16
+ 'get_agent_models',
17
+ 'get_explore_access_summary',
18
+ 'list_agent_threads',
19
+ 'get_agent_thread',
20
+ 'list_agent_evaluations',
21
+ 'get_agent_evaluation',
22
+ 'create_agent_evaluation',
23
+ 'update_agent_evaluation',
24
+ 'append_agent_evaluation_prompts',
25
+ 'delete_agent_evaluation',
26
+ 'run_agent_evaluation',
27
+ 'list_agent_evaluation_runs',
28
+ 'get_agent_eval_run_results',
29
+ ];
30
+ exports.aiAgentOpsPersona = {
31
+ id: 'ai-agent-ops',
32
+ path: exports.AI_AGENT_OPS_PERSONA_PATH,
33
+ serverName: 'lightdash-mcp-aops',
34
+ toolIds: exports.AI_AGENT_OPS_TOOL_IDS,
35
+ registerPrompts: (server) => {
36
+ (0, prompts_js_1.registerAiAgentOpsPrompts)(server);
37
+ },
38
+ registerResources: (server) => {
39
+ (0, playbooks_js_1.registerAiAgentOpsPlaybook)(server);
40
+ },
41
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * MCP prompts for ai-agent-ops workflows (ADR-0018).
3
+ */
4
+ import type { McpServer } from '@modelcontextprotocol/server';
5
+ export declare function registerAiAgentOpsPrompts(server: McpServer): void;