@lightdash-tools/mcp 0.14.0 → 0.16.1

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 (113) hide show
  1. package/README.md +30 -11
  2. package/dist/auth/oauth-broker/lightdash-token.d.ts +6 -5
  3. package/dist/auth/oauth-broker/lightdash-token.js +6 -10
  4. package/dist/auth/oauth-broker/mcp-access-token.d.ts +31 -0
  5. package/dist/auth/oauth-broker/mcp-access-token.js +109 -0
  6. package/dist/auth/oauth-broker/mcp-access-token.test.d.ts +1 -0
  7. package/dist/auth/oauth-broker/mcp-access-token.test.js +61 -0
  8. package/dist/auth/oauth-broker/pending-store.d.ts +9 -3
  9. package/dist/auth/oauth-broker/pending-store.js +5 -3
  10. package/dist/auth/oauth-broker/pending-store.test.js +28 -44
  11. package/dist/auth/oauth-broker/routes.d.ts +2 -1
  12. package/dist/auth/oauth-broker/routes.js +97 -45
  13. package/dist/auth/oauth-broker/routes.test.js +81 -13
  14. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +2 -0
  15. package/dist/auth/resource-server/lightdash-oauth-middleware.js +58 -37
  16. package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +59 -57
  17. package/dist/auth/resource-server/oauth-protected-resource.js +2 -2
  18. package/dist/bin.js +33 -7
  19. package/dist/config/env.d.ts +5 -0
  20. package/dist/config/env.js +6 -1
  21. package/dist/config/load-mcp-config.d.ts +12 -1
  22. package/dist/config/load-mcp-config.js +17 -8
  23. package/dist/config/load-mcp-config.test.js +20 -0
  24. package/dist/config/prompt-context-policy.d.ts +18 -0
  25. package/dist/config/prompt-context-policy.js +40 -0
  26. package/dist/config/prompt-context-policy.test.d.ts +4 -0
  27. package/dist/config/prompt-context-policy.test.js +35 -0
  28. package/dist/config/test-mcp-http-config.js +1 -1
  29. package/dist/governance/mcp-post-factory-context.d.ts +2 -0
  30. package/dist/http.d.ts +7 -1
  31. package/dist/http.integration.test.js +57 -22
  32. package/dist/http.js +10 -1
  33. package/dist/index.d.ts +6 -1
  34. package/dist/index.js +6 -3
  35. package/dist/policy/content-developer.d.ts +5 -0
  36. package/dist/policy/content-developer.js +25 -1
  37. package/dist/policy/content-developer.test.js +29 -0
  38. package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +27 -0
  39. package/dist/profiles/ai-agent-ops/v1/invariants.js +39 -0
  40. package/dist/profiles/ai-agent-ops/v1/prompts.d.ts +3 -2
  41. package/dist/profiles/ai-agent-ops/v1/prompts.js +67 -41
  42. package/dist/profiles/ai-agent-ops/v1/resources/playbooks.d.ts +2 -1
  43. package/dist/profiles/ai-agent-ops/v1/resources/playbooks.js +10 -3
  44. package/dist/profiles/content-developer/v1/invariants.d.ts +69 -0
  45. package/dist/profiles/content-developer/v1/invariants.js +95 -0
  46. package/dist/profiles/content-developer/v1/prompt-specs.d.ts +32 -0
  47. package/dist/profiles/content-developer/v1/prompt-specs.js +56 -0
  48. package/dist/profiles/content-developer/v1/prompts.d.ts +4 -3
  49. package/dist/profiles/content-developer/v1/prompts.js +65 -71
  50. package/dist/profiles/content-developer/v1/prompts.test.js +61 -7
  51. package/dist/profiles/content-developer/v1/resources/playbooks/core.md +1 -0
  52. package/dist/profiles/content-developer/v1/resources/playbooks/index.md +11 -8
  53. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/dashboard-diff.md +15 -0
  54. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-required.md +14 -0
  55. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-stale.md +21 -0
  56. package/dist/profiles/content-developer/v1/resources/playbooks.d.ts +3 -2
  57. package/dist/profiles/content-developer/v1/resources/playbooks.js +35 -22
  58. package/dist/profiles/content-governance/v1/invariants.d.ts +27 -0
  59. package/dist/profiles/content-governance/v1/invariants.js +39 -0
  60. package/dist/profiles/content-governance/v1/prompts.d.ts +4 -2
  61. package/dist/profiles/content-governance/v1/prompts.js +31 -19
  62. package/dist/profiles/content-governance/v1/resources/playbooks.d.ts +2 -1
  63. package/dist/profiles/content-governance/v1/resources/playbooks.js +8 -9
  64. package/dist/profiles/content-reader/v1/invariants.d.ts +33 -0
  65. package/dist/profiles/content-reader/v1/invariants.js +47 -0
  66. package/dist/profiles/content-reader/v1/prompt-specs.d.ts +18 -0
  67. package/dist/profiles/content-reader/v1/prompt-specs.js +33 -0
  68. package/dist/profiles/content-reader/v1/prompts.d.ts +3 -2
  69. package/dist/profiles/content-reader/v1/prompts.js +69 -76
  70. package/dist/profiles/content-reader/v1/resources/playbooks.d.ts +2 -1
  71. package/dist/profiles/content-reader/v1/resources/playbooks.js +10 -11
  72. package/dist/profiles/data-analyst/v1/invariants.d.ts +21 -0
  73. package/dist/profiles/data-analyst/v1/invariants.js +31 -0
  74. package/dist/profiles/data-analyst/v1/prompts.d.ts +3 -2
  75. package/dist/profiles/data-analyst/v1/prompts.js +17 -9
  76. package/dist/profiles/data-analyst/v1/resources/playbooks.d.ts +2 -1
  77. package/dist/profiles/data-analyst/v1/resources/playbooks.js +6 -7
  78. package/dist/profiles/lib/playbook-resources.d.ts +16 -34
  79. package/dist/profiles/lib/playbook-resources.js +55 -76
  80. package/dist/profiles/lib/prompt-context.d.ts +71 -0
  81. package/dist/profiles/lib/prompt-context.js +205 -0
  82. package/dist/profiles/lib/prompt-context.test.d.ts +4 -0
  83. package/dist/profiles/lib/prompt-context.test.js +154 -0
  84. package/dist/profiles/lib/prompt-invariants.d.ts +20 -0
  85. package/dist/profiles/lib/prompt-invariants.js +54 -0
  86. package/dist/profiles/organization-audit/v1/invariants.d.ts +24 -0
  87. package/dist/profiles/organization-audit/v1/invariants.js +35 -0
  88. package/dist/profiles/organization-audit/v1/prompts.d.ts +3 -2
  89. package/dist/profiles/organization-audit/v1/prompts.js +44 -28
  90. package/dist/profiles/organization-audit/v1/resources/playbooks.d.ts +2 -1
  91. package/dist/profiles/organization-audit/v1/resources/playbooks.js +10 -3
  92. package/dist/profiles/semantic-layer/v1/invariants.d.ts +27 -0
  93. package/dist/profiles/semantic-layer/v1/invariants.js +39 -0
  94. package/dist/profiles/semantic-layer/v1/prompts.d.ts +3 -2
  95. package/dist/profiles/semantic-layer/v1/prompts.js +37 -26
  96. package/dist/profiles/semantic-layer/v1/resources/playbooks.d.ts +2 -4
  97. package/dist/profiles/semantic-layer/v1/resources/playbooks.js +8 -7
  98. package/dist/profiles/test-support/prompt-context-budget.test.d.ts +5 -0
  99. package/dist/profiles/test-support/prompt-context-budget.test.js +72 -0
  100. package/dist/profiles/types.d.ts +6 -1
  101. package/dist/server/capabilities.d.ts +3 -0
  102. package/dist/server/capabilities.js +4 -2
  103. package/dist/tools/lib/schema-fields.d.ts +4 -0
  104. package/dist/tools/lib/schema-fields.js +8 -1
  105. package/dist/tools/project/developer-content-preview.js +1 -1
  106. package/dist/tools/project/developer-content.js +2 -2
  107. package/dist/tools/query/reader-tool-helpers.d.ts +2 -2
  108. package/dist/tools/query/reader-tool-helpers.js +2 -2
  109. package/dist/tools/query/reader-tool-helpers.test.js +1 -0
  110. package/dist/tools/shared.d.ts +6 -1
  111. package/dist/tools/shared.js +12 -2
  112. package/dist/transports/streamable-http.js +10 -3
  113. package/package.json +3 -3
@@ -4,10 +4,13 @@ const node_http_1 = require("node:http");
4
4
  const client_1 = require("@lightdash-tools/client");
5
5
  const server_1 = require("@modelcontextprotocol/server");
6
6
  const vitest_1 = require("vitest");
7
+ const mcp_access_token_js_1 = require("./auth/oauth-broker/mcp-access-token.js");
7
8
  const oauth_protected_resource_js_1 = require("./auth/resource-server/oauth-protected-resource.js");
8
9
  const enabled_profiles_js_1 = require("./config/enabled-profiles.js");
9
10
  const test_mcp_http_config_js_1 = require("./config/test-mcp-http-config.js");
10
11
  const streamable_http_js_1 = require("./transports/streamable-http.js");
12
+ // These constants model downstream Lightdash credentials only. MCP clients never send
13
+ // them directly after ADR-0026; tests wrap them in broker-issued MCP access tokens.
11
14
  const TOKEN_A = scopedAccessToken('mcp:read mcp:write', 'token-a');
12
15
  const TOKEN_B = scopedAccessToken('mcp:read mcp:write', 'token-b');
13
16
  const TOKEN_READ_ONLY = scopedAccessToken('mcp:read', 'token-read-only');
@@ -120,6 +123,17 @@ async function startMockLightdashServer() {
120
123
  function baseOAuthConfig(lightdashUrl, overrides) {
121
124
  return (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)(Object.assign({ lightdashUrl, port: 0, publicUrl: 'http://127.0.0.1:0', oauthClientId: 'test-client-id', oauthClientSecret: new client_1.SecretString('test-client-secret'), maxBodyBytes: 1024 * 1024, requiredScopes: [], scopesSupported: [] }, overrides));
122
125
  }
126
+ function brokerAccessToken(mcpBaseUrl, lightdashAccessToken, options = {}) {
127
+ var _a;
128
+ const path = (_a = options.path) !== null && _a !== void 0 ? _a : '/semantic-layer/v1/mcp';
129
+ return (0, mcp_access_token_js_1.mintMcpAccessToken)(baseOAuthConfig('https://lightdash.invalid'), {
130
+ lightdashAccessToken,
131
+ clientId: 'integration-test-client',
132
+ resource: `${mcpBaseUrl}${path}`,
133
+ scope: options.scope,
134
+ expiresAtMs: Date.now() + 60000,
135
+ }).accessToken;
136
+ }
123
137
  async function postMcp(baseUrl, body, options) {
124
138
  var _a;
125
139
  const headers = {
@@ -175,12 +189,15 @@ function parseSseOrJsonToolText(raw) {
175
189
  (0, vitest_1.expect)(body).not.toContain(invalidToken);
176
190
  (0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
177
191
  });
178
- (0, vitest_1.it)('handles initialize with valid OAuth bearer and validates upstream Authorization', async () => {
179
- const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
192
+ (0, vitest_1.it)('handles initialize with an MCP bearer and validates the downstream Lightdash bearer', async () => {
193
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
194
+ const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpToken });
180
195
  (0, vitest_1.expect)(response.status).toBe(200);
181
- // Sessionless: no session-id header is set
196
+ // Sessionless: no session-id header is set.
182
197
  (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
198
+ (0, vitest_1.expect)(mcpToken).not.toBe(TOKEN_A);
183
199
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
200
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
184
201
  });
185
202
  (0, vitest_1.it)('returns 401 before parsing malformed JSON when OAuth token is missing', async () => {
186
203
  const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
@@ -202,12 +219,13 @@ function parseSseOrJsonToolText(raw) {
202
219
  (0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
203
220
  });
204
221
  (0, vitest_1.it)('returns 400 for malformed JSON only after successful OAuth authentication', async () => {
222
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
205
223
  const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
206
224
  method: 'POST',
207
225
  headers: {
208
226
  'Content-Type': 'application/json',
209
227
  Accept: 'application/json, text/event-stream',
210
- Authorization: `Bearer ${TOKEN_A}`,
228
+ Authorization: `Bearer ${mcpToken}`,
211
229
  },
212
230
  body: '{not-json',
213
231
  });
@@ -282,16 +300,21 @@ function parseSseOrJsonToolText(raw) {
282
300
  (0, vitest_1.expect)(wwwAuthenticate).toContain(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-governance/v1/mcp`);
283
301
  (0, vitest_1.expect)(wwwAuthenticate).not.toContain('semantic-layer/v1/mcp');
284
302
  });
285
- (0, vitest_1.it)('maps token-a and token-b to distinct authenticated users upstream', async () => {
286
- const responseA = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
287
- const responseB = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_B });
303
+ (0, vitest_1.it)('maps two MCP tokens to distinct authenticated users upstream', async () => {
304
+ const mcpTokenA = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
305
+ const mcpTokenB = brokerAccessToken(mcpServer.baseUrl, TOKEN_B);
306
+ const responseA = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpTokenA });
307
+ const responseB = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpTokenB });
288
308
  (0, vitest_1.expect)(responseA.status).toBe(200);
289
309
  (0, vitest_1.expect)(responseB.status).toBe(200);
290
310
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
291
311
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_B}`);
312
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpTokenA}`);
313
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpTokenB}`);
292
314
  });
293
315
  (0, vitest_1.it)('accepts form-elicitation caps from per-request _meta on content-governance tools/call', async () => {
294
316
  const governancePath = '/content-governance/v1/mcp';
317
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A, { path: governancePath });
295
318
  const call = await postMcp(mcpServer.baseUrl, {
296
319
  jsonrpc: '2.0',
297
320
  method: 'tools/call',
@@ -306,7 +329,7 @@ function parseSseOrJsonToolText(raw) {
306
329
  },
307
330
  },
308
331
  id: 2,
309
- }, { token: TOKEN_A, path: governancePath });
332
+ }, { token: mcpToken, path: governancePath });
310
333
  (0, vitest_1.expect)(call.status).toBe(200);
311
334
  const text = parseSseOrJsonToolText(await call.text());
312
335
  // Per-request envelope caps: past ELICITATION_REQUIRED into chart resolve (mock has no chart).
@@ -325,7 +348,8 @@ function parseSseOrJsonToolText(raw) {
325
348
  const unavailableUrl = `http://127.0.0.1:${unavailableAddress.port}`;
326
349
  const downServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(unavailableUrl)));
327
350
  try {
328
- const response = await postMcp(downServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
351
+ const mcpToken = brokerAccessToken(downServer.baseUrl, TOKEN_A);
352
+ const response = await postMcp(downServer.baseUrl, INITIALIZE_BODY, { token: mcpToken });
329
353
  (0, vitest_1.expect)(response.status).toBe(503);
330
354
  (0, vitest_1.expect)(await response.json()).toEqual({
331
355
  error: 'temporarily_unavailable',
@@ -373,33 +397,41 @@ function parseSseOrJsonToolText(raw) {
373
397
  (0, vitest_1.expect)(asMetadata.token_endpoint).toBe(`${mcpServer.baseUrl}/oauth/token`);
374
398
  (0, vitest_1.expect)(asMetadata.registration_endpoint).toBe(`${mcpServer.baseUrl}/oauth/register`);
375
399
  });
376
- (0, vitest_1.it)('handles initialize with opaque OAuth bearer when endpoint scopes are unset', async () => {
377
- const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: OPAQUE_TOKEN_A });
400
+ (0, vitest_1.it)('handles initialize when the downstream Lightdash credential is opaque', async () => {
401
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, OPAQUE_TOKEN_A);
402
+ const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpToken });
378
403
  (0, vitest_1.expect)(response.status).toBe(200);
379
404
  (0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
380
405
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${OPAQUE_TOKEN_A}`);
406
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
381
407
  });
382
- (0, vitest_1.it)('accepts TOKEN_READ_ONLY (mcp:read scope) on initialize', async () => {
408
+ (0, vitest_1.it)('accepts an MCP token carrying mcp:read scope on initialize', async () => {
409
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_READ_ONLY, { scope: 'mcp:read' });
383
410
  const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
384
- token: TOKEN_READ_ONLY,
411
+ token: mcpToken,
385
412
  });
386
413
  (0, vitest_1.expect)(response.status).toBe(200);
387
414
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_READ_ONLY}`);
388
415
  });
389
- (0, vitest_1.it)('accepts TOKEN_A (mcp:read mcp:write scope) on initialize', async () => {
416
+ (0, vitest_1.it)('accepts an MCP token carrying mcp:read mcp:write scope on initialize', async () => {
417
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A, {
418
+ scope: 'mcp:read mcp:write',
419
+ });
390
420
  const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
391
- token: TOKEN_A,
421
+ token: mcpToken,
392
422
  });
393
423
  (0, vitest_1.expect)(response.status).toBe(200);
394
424
  (0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
395
425
  });
396
- (0, vitest_1.it)('forwards bearer token to Lightdash on initialize for opaque credentials', async () => {
426
+ (0, vitest_1.it)('forwards only the decrypted downstream bearer to Lightdash', async () => {
427
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, OPAQUE_TOKEN_A);
397
428
  const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
398
- token: OPAQUE_TOKEN_A,
429
+ token: mcpToken,
399
430
  });
400
431
  (0, vitest_1.expect)(response.status).toBe(200);
401
- const userHeaders = mockLightdash.authorizationHeaders.filter((h) => h === `Bearer ${OPAQUE_TOKEN_A}`);
402
- (0, vitest_1.expect)(userHeaders.length).toBeGreaterThan(0);
432
+ const downstreamHeaders = mockLightdash.authorizationHeaders.filter((header) => header === `Bearer ${OPAQUE_TOKEN_A}`);
433
+ (0, vitest_1.expect)(downstreamHeaders.length).toBeGreaterThan(0);
434
+ (0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
403
435
  });
404
436
  });
405
437
  (0, vitest_1.describe)('MCP HTTP CORS integration', () => {
@@ -461,12 +493,13 @@ function parseSseOrJsonToolText(raw) {
461
493
  });
462
494
  (0, vitest_1.it)('returns 413 for oversized JSON body after OAuth authentication', async () => {
463
495
  const hugeBody = JSON.stringify(Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { padding: 'x'.repeat(1024) }) }));
496
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
464
497
  const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
465
498
  method: 'POST',
466
499
  headers: {
467
500
  'Content-Type': 'application/json',
468
501
  Accept: 'application/json, text/event-stream',
469
- Authorization: `Bearer ${TOKEN_A}`,
502
+ Authorization: `Bearer ${mcpToken}`,
470
503
  },
471
504
  body: hugeBody,
472
505
  });
@@ -516,9 +549,11 @@ function parseSseOrJsonToolText(raw) {
516
549
  (0, vitest_1.expect)(prmResponse.status).toBe(404);
517
550
  });
518
551
  (0, vitest_1.it)('keeps enabled profile MCP and PRM reachable', async () => {
552
+ const contentReaderPath = '/content-reader/v1/mcp';
553
+ const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A, { path: contentReaderPath });
519
554
  const mcpResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
520
- token: TOKEN_A,
521
- path: '/content-reader/v1/mcp',
555
+ token: mcpToken,
556
+ path: contentReaderPath,
522
557
  });
523
558
  (0, vitest_1.expect)(mcpResponse.status).toBe(200);
524
559
  const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-reader/v1/mcp`);
package/dist/http.js CHANGED
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  /**
3
3
  * MCP server entrypoint (Streamable HTTP).
4
+ * Prefer `lightdash-mcp http` (bin) which resolves prompt-context before start.
4
5
  */
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.startHttp = startHttp;
8
+ const load_mcp_config_js_1 = require("./config/load-mcp-config.js");
6
9
  const streamable_http_js_1 = require("./transports/streamable-http.js");
7
- (0, streamable_http_js_1.startStreamableHttpServer)();
10
+ /** Start Streamable HTTP MCP (optional resolved prompt-context policy from CLI). */
11
+ async function startHttp(options) {
12
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)(process.env, (options === null || options === void 0 ? void 0 : options.promptContextPolicy) !== undefined
13
+ ? { promptContextPolicy: options.promptContextPolicy }
14
+ : undefined);
15
+ await (0, streamable_http_js_1.startStreamableHttpServer)(config);
16
+ }
package/dist/index.d.ts CHANGED
@@ -9,6 +9,11 @@
9
9
  * via `legacy: 'serve'`). Hand-wiring `StdioServerTransport` + `connect()` stays
10
10
  * on the 2025-era wire only.
11
11
  */
12
+ import { type PromptContextPolicy } from './config/prompt-context-policy.js';
12
13
  import type { ProfileId } from './profiles/types.js';
14
+ export type StartStdioOptions = {
15
+ /** Explicit policy; when omitted, resolve from env (default compact). */
16
+ promptContextPolicy?: PromptContextPolicy;
17
+ };
13
18
  /** Start stdio MCP for an explicit profile (CLI-selected). */
14
- export declare function startStdio(profileId: ProfileId): void;
19
+ export declare function startStdio(profileId: ProfileId, options?: StartStdioOptions): void;
package/dist/index.js CHANGED
@@ -16,26 +16,29 @@ const stdio_1 = require("@modelcontextprotocol/server/stdio");
16
16
  const audit_js_1 = require("./audit/audit.js");
17
17
  const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
18
18
  const obsolete_env_js_1 = require("./config/obsolete-env.js");
19
+ const prompt_context_policy_js_1 = require("./config/prompt-context-policy.js");
19
20
  const runtime_js_1 = require("./config/runtime.js");
20
21
  const available_projects_js_1 = require("./governance/available-projects.js");
21
22
  const index_js_1 = require("./profiles/index.js");
22
23
  const server_js_1 = require("./server/server.js");
23
24
  /** Start stdio MCP for an explicit profile (CLI-selected). */
24
- function startStdio(profileId) {
25
+ function startStdio(profileId, options) {
26
+ var _a;
25
27
  try {
26
28
  (0, obsolete_env_js_1.assertObsoleteEnvRejected)(process.env);
27
29
  (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
28
30
  (0, available_projects_js_1.validateAvailableProjectsConfig)();
29
31
  (0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
32
+ const promptContextPolicy = (_a = options === null || options === void 0 ? void 0 : options.promptContextPolicy) !== null && _a !== void 0 ? _a : (0, prompt_context_policy_js_1.resolvePromptContextPolicy)({ env: process.env });
30
33
  const profile = (0, index_js_1.getProfile)(profileId);
31
34
  const contextProvider = new env_context_provider_js_1.EnvContextProvider();
32
- (0, stdio_1.serveStdio)(() => (0, server_js_1.createLightdashMcpServer)(contextProvider, { profile }), {
35
+ (0, stdio_1.serveStdio)(() => (0, server_js_1.createLightdashMcpServer)(contextProvider, { profile, promptContextPolicy }), {
33
36
  legacy: 'serve',
34
37
  onerror: (error) => {
35
38
  console.error('MCP stdio error:', error);
36
39
  },
37
40
  });
38
- console.error(`Lightdash MCP server (${profile.id}) running on stdio`);
41
+ console.error(`Lightdash MCP server (${profile.id}) running on stdio (prompt-context=${promptContextPolicy})`);
39
42
  }
40
43
  catch (err) {
41
44
  console.error('Fatal:', err);
@@ -30,6 +30,11 @@ export declare function registerContentDeveloperTool(server: McpServer, shortNam
30
30
  annotations?: ToolOptions['annotations'];
31
31
  safety: DeveloperOperationSafety;
32
32
  }, handler: ToolHandler): void;
33
+ /**
34
+ * Coded tool error for content-developer paths that return preview codes without
35
+ * throwing PreviewLedgerError (adds recovery extras when the code is known).
36
+ */
37
+ export declare function developerCodedErrorResult(code: string, message: string): TextContent;
33
38
  /** Map ProjectScopeError / PreviewLedgerError to a coded tool error result; rethrow anything else. */
34
39
  export declare function developerErrorResult(err: unknown): TextContent;
35
40
  export {};
@@ -9,8 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.WRITE_SAFETY = exports.COMPARE_SAFETY = exports.VALIDATE_SAFETY = exports.PREVIEW_SAFETY = exports.DISCOVERY_SAFETY = void 0;
10
10
  exports.assertContentDeveloperSafe = assertContentDeveloperSafe;
11
11
  exports.registerContentDeveloperTool = registerContentDeveloperTool;
12
+ exports.developerCodedErrorResult = developerCodedErrorResult;
12
13
  exports.developerErrorResult = developerErrorResult;
13
14
  const common_1 = require("@lightdash-tools/common");
15
+ const playbook_resources_js_1 = require("../profiles/lib/playbook-resources.js");
14
16
  const reader_tool_helpers_js_1 = require("../tools/query/reader-tool-helpers.js");
15
17
  const shared_js_1 = require("../tools/shared.js");
16
18
  const preview_ledger_js_1 = require("./preview-ledger.js");
@@ -82,10 +84,32 @@ function registerContentDeveloperTool(server, shortName, options, handler) {
82
84
  }
83
85
  (0, shared_js_1.registerToolSafe)(server, shortName, Object.assign(Object.assign({}, options), { annotations }), handler);
84
86
  }
87
+ /** Additive recovery hints for content-developer preview errors. */
88
+ const PREVIEW_RECOVERY_EXTRAS = {
89
+ PREVIEW_STALE: {
90
+ recovery: 'Re-run preview_* with the intended payload, confirm_preview, then apply the identical proposed body.',
91
+ playbookUri: (0, playbook_resources_js_1.playbookTopicUri)('content-developer', 'recovery/preview-stale'),
92
+ },
93
+ PREVIEW_REQUIRED: {
94
+ recovery: 'Call the matching preview_* tool, then confirm_preview before apply.',
95
+ playbookUri: (0, playbook_resources_js_1.playbookTopicUri)('content-developer', 'recovery/preview-required'),
96
+ },
97
+ };
98
+ function recoveryExtrasForPreviewCode(code) {
99
+ // eslint-disable-next-line security/detect-object-injection -- keys from PreviewLedgerError codes
100
+ return PREVIEW_RECOVERY_EXTRAS[code];
101
+ }
102
+ /**
103
+ * Coded tool error for content-developer paths that return preview codes without
104
+ * throwing PreviewLedgerError (adds recovery extras when the code is known).
105
+ */
106
+ function developerCodedErrorResult(code, message) {
107
+ return (0, reader_tool_helpers_js_1.codedErrorResult)(code, message, recoveryExtrasForPreviewCode(code));
108
+ }
85
109
  /** Map ProjectScopeError / PreviewLedgerError to a coded tool error result; rethrow anything else. */
86
110
  function developerErrorResult(err) {
87
111
  if (err instanceof preview_ledger_js_1.PreviewLedgerError) {
88
- return (0, reader_tool_helpers_js_1.codedErrorResult)(err.code, err.message);
112
+ return developerCodedErrorResult(err.code, err.message);
89
113
  }
90
114
  return (0, reader_tool_helpers_js_1.projectScopeErrorResult)(err);
91
115
  }
@@ -46,9 +46,38 @@ const preview_ledger_js_1 = require("./preview-ledger.js");
46
46
  (0, vitest_1.expect)(first === null || first === void 0 ? void 0 : first.type).toBe('text');
47
47
  if ((first === null || first === void 0 ? void 0 : first.type) === 'text') {
48
48
  (0, vitest_1.expect)(first.text).toContain('PREVIEW_STALE');
49
+ const parsed = JSON.parse(first.text);
50
+ (0, vitest_1.expect)(parsed.error.recovery).toMatch(/preview_\*/);
51
+ (0, vitest_1.expect)(parsed.error.playbookUri).toBe('lightdash://playbooks/content-developer/recovery/preview-stale');
49
52
  }
50
53
  });
51
54
  (0, vitest_1.it)('rethrows unrelated errors', () => {
52
55
  (0, vitest_1.expect)(() => (0, content_developer_js_1.developerErrorResult)(new Error('boom'))).toThrow('boom');
53
56
  });
54
57
  });
58
+ (0, vitest_1.describe)('developerCodedErrorResult', () => {
59
+ (0, vitest_1.it)('attaches recovery extras for direct PREVIEW_STALE returns', () => {
60
+ const result = (0, content_developer_js_1.developerCodedErrorResult)('PREVIEW_STALE', 'source chart drifted');
61
+ (0, vitest_1.expect)(result.isError).toBe(true);
62
+ const first = result.content[0];
63
+ (0, vitest_1.expect)(first === null || first === void 0 ? void 0 : first.type).toBe('text');
64
+ if ((first === null || first === void 0 ? void 0 : first.type) === 'text') {
65
+ const parsed = JSON.parse(first.text);
66
+ (0, vitest_1.expect)(parsed.error.code).toBe('PREVIEW_STALE');
67
+ (0, vitest_1.expect)(parsed.error.message).toBe('source chart drifted');
68
+ (0, vitest_1.expect)(parsed.error.recovery).toMatch(/preview_\*/);
69
+ (0, vitest_1.expect)(parsed.error.playbookUri).toBe('lightdash://playbooks/content-developer/recovery/preview-stale');
70
+ }
71
+ });
72
+ (0, vitest_1.it)('leaves non-preview codes without recovery extras', () => {
73
+ const result = (0, content_developer_js_1.developerCodedErrorResult)('CONTENT_NOT_FOUND', 'missing');
74
+ const first = result.content[0];
75
+ (0, vitest_1.expect)(first === null || first === void 0 ? void 0 : first.type).toBe('text');
76
+ if ((first === null || first === void 0 ? void 0 : first.type) === 'text') {
77
+ const parsed = JSON.parse(first.text);
78
+ (0, vitest_1.expect)(parsed.error.code).toBe('CONTENT_NOT_FOUND');
79
+ (0, vitest_1.expect)(parsed.error.recovery).toBeUndefined();
80
+ (0, vitest_1.expect)(parsed.error.playbookUri).toBeUndefined();
81
+ }
82
+ });
83
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * AI agent-ops structured prompt invariants (SSOT for capsules + HARD_BANS projection).
3
+ */
4
+ export declare const AI_AGENT_OPS_INVARIANTS: readonly [{
5
+ readonly id: "no-agent-crud";
6
+ readonly short: "Do not create/update/delete agents on this server.";
7
+ }, {
8
+ readonly id: "no-thread-mutation";
9
+ readonly short: "Do not start or continue threads.";
10
+ }, {
11
+ readonly id: "no-resource-mutation";
12
+ readonly short: "Do not mutate users/roles/semantic models/charts.";
13
+ }, {
14
+ readonly id: "no-offline-scorers";
15
+ readonly short: "Do not run local offline scorers.";
16
+ }, {
17
+ readonly id: "no-git-eval-stores";
18
+ readonly short: "Do not write Git eval artifact stores via MCP.";
19
+ }, {
20
+ readonly id: "no-invent-mega-tools";
21
+ readonly short: "Do not invent recommend_* or analyze_* mega-tools. Those capabilities are not available as MCP mega-tools here — use CLI agentops / other profiles / the host.";
22
+ }, {
23
+ readonly id: "no-mcp-only-gate-claim";
24
+ readonly short: "Do not claim a CLI promotion gate passed from MCP run results alone.";
25
+ }];
26
+ export declare const AI_AGENT_OPS_HARD_BANS: string;
27
+ export declare const AI_AGENT_OPS_DEFAULT_INVARIANT_IDS: readonly ("no-agent-crud" | "no-thread-mutation" | "no-resource-mutation" | "no-offline-scorers" | "no-git-eval-stores" | "no-invent-mega-tools" | "no-mcp-only-gate-claim")[];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * AI agent-ops structured prompt invariants (SSOT for capsules + HARD_BANS projection).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AI_AGENT_OPS_DEFAULT_INVARIANT_IDS = exports.AI_AGENT_OPS_HARD_BANS = exports.AI_AGENT_OPS_INVARIANTS = void 0;
7
+ const prompt_invariants_js_1 = require("../../lib/prompt-invariants.js");
8
+ exports.AI_AGENT_OPS_INVARIANTS = [
9
+ {
10
+ id: 'no-agent-crud',
11
+ short: 'Do not create/update/delete agents on this server.',
12
+ },
13
+ {
14
+ id: 'no-thread-mutation',
15
+ short: 'Do not start or continue threads.',
16
+ },
17
+ {
18
+ id: 'no-resource-mutation',
19
+ short: 'Do not mutate users/roles/semantic models/charts.',
20
+ },
21
+ {
22
+ id: 'no-offline-scorers',
23
+ short: 'Do not run local offline scorers.',
24
+ },
25
+ {
26
+ id: 'no-git-eval-stores',
27
+ short: 'Do not write Git eval artifact stores via MCP.',
28
+ },
29
+ {
30
+ id: 'no-invent-mega-tools',
31
+ short: 'Do not invent recommend_* or analyze_* mega-tools. Those capabilities are not available as MCP mega-tools here — use CLI agentops / other profiles / the host.',
32
+ },
33
+ {
34
+ id: 'no-mcp-only-gate-claim',
35
+ short: 'Do not claim a CLI promotion gate passed from MCP run results alone.',
36
+ },
37
+ ];
38
+ exports.AI_AGENT_OPS_HARD_BANS = (0, prompt_invariants_js_1.formatHardBansProjection)(exports.AI_AGENT_OPS_INVARIANTS);
39
+ exports.AI_AGENT_OPS_DEFAULT_INVARIANT_IDS = (0, prompt_invariants_js_1.allInvariantIds)(exports.AI_AGENT_OPS_INVARIANTS);
@@ -1,5 +1,6 @@
1
1
  /**
2
- * MCP prompts for ai-agent-ops workflows (ADR-0018).
2
+ * MCP prompts for ai-agent-ops workflows (progressive-disclosure context).
3
3
  */
4
+ import type { RegisterPromptsOptions } from '../../types.js';
4
5
  import type { McpServer } from '@modelcontextprotocol/server';
5
- export declare function registerAiAgentOpsPrompts(server: McpServer): void;
6
+ export declare function registerAiAgentOpsPrompts(server: McpServer, options?: RegisterPromptsOptions): void;
@@ -1,27 +1,34 @@
1
1
  "use strict";
2
2
  /**
3
- * MCP prompts for ai-agent-ops workflows (ADR-0018).
3
+ * MCP prompts for ai-agent-ops workflows (progressive-disclosure context).
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.registerAiAgentOpsPrompts = registerAiAgentOpsPrompts;
7
- /* eslint-disable @typescript-eslint/no-deprecated -- matches other profile prompt registration */
7
+ /* eslint-disable @typescript-eslint/no-deprecated -- matches other profile prompt registration pattern */
8
8
  const zod_1 = require("zod");
9
- const playbook_resources_js_1 = require("../../lib/playbook-resources.js");
9
+ const prompt_context_js_1 = require("../../lib/prompt-context.js");
10
+ const invariants_js_1 = require("./invariants.js");
10
11
  const playbooks_js_1 = require("./resources/playbooks.js");
11
- const userMessages = (0, playbook_resources_js_1.createPromptPlaybookEmbedder)({
12
+ const TOPIC_EVALUATION = 'evaluation';
13
+ const TOPIC_LOOP_ENGINEERING = 'loop-engineering';
14
+ const TOPIC_RELEASE_GATE = 'release-gate';
15
+ const bindPromptContext = (0, prompt_context_js_1.bindProfilePromptContext)({
16
+ invariants: invariants_js_1.AI_AGENT_OPS_INVARIANTS,
12
17
  core: playbooks_js_1.AI_AGENT_OPS_CORE_PLAYBOOK,
13
18
  topics: playbooks_js_1.AI_AGENT_OPS_TOPIC_PLAYBOOKS,
19
+ topicMeta: playbooks_js_1.AI_AGENT_OPS_TOPIC_META,
14
20
  });
15
- function registerAiAgentOpsPrompts(server) {
21
+ function registerAiAgentOpsPrompts(server, options) {
22
+ const promptContext = bindPromptContext(options === null || options === void 0 ? void 0 : options.promptContextPolicy);
23
+ const invariantIds = invariants_js_1.AI_AGENT_OPS_DEFAULT_INVARIANT_IDS;
16
24
  server.registerPrompt('audit_project_ai_agent', {
17
25
  title: 'Audit project AI agent',
18
26
  description: 'Inspect agent config, readiness API, and evaluation coverage via primitives',
19
27
  argsSchema: {
20
28
  agentUuid: zod_1.z.string().optional().describe('Agent UUID (or select after list)'),
21
29
  },
22
- }, ({ agentUuid }) => userMessages(`Audit the selected project-level Lightdash AI agent.
23
-
24
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
30
+ }, ({ agentUuid }) => promptContext({
31
+ task: `Audit the selected project-level Lightdash AI agent.
25
32
 
26
33
  Agent: ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(list_project_agents then select)'}
27
34
 
@@ -31,20 +38,25 @@ Procedure (primitives only):
31
38
  3. Optionally evaluate_agent_readiness — label as readiness API, not e2e.
32
39
  4. List evaluations and recent runs; note coverage gaps.
33
40
  5. Distinguish API facts, readiness signals, evaluation evidence, assumptions, and unknowns.
34
- 6. Do not mutate the agent or claim compliance.`));
41
+ 6. Do not mutate the agent or claim compliance.`,
42
+ invariantIds,
43
+ requiredTopics: [],
44
+ }));
35
45
  server.registerPrompt('build_agent_evaluation_suite', {
36
46
  title: 'Build agent evaluation suite',
37
47
  description: 'Design or update a Lightdash evaluation suite via MCP eval APIs',
38
48
  argsSchema: {
39
49
  agentUuid: zod_1.z.string().optional(),
40
50
  },
41
- }, ({ agentUuid }) => userMessages(`Design or update an offline evaluation suite for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select after list)'}.
42
-
43
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
51
+ }, ({ agentUuid }) => promptContext({
52
+ task: `Design or update an offline evaluation suite for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select after list)'}.
44
53
 
45
54
  Inspect agent configuration first. Prefer create/update/append_agent_evaluation tools.
46
55
  Include common questions, ambiguity, access/refusal, and must-pass cases.
47
- Prefer deterministic expected responses. Do not invent local Git dataset MCP tools.`, 'evaluation'));
56
+ Prefer deterministic expected responses. Do not invent local Git dataset MCP tools.`,
57
+ invariantIds,
58
+ requiredTopics: [TOPIC_EVALUATION],
59
+ }));
48
60
  server.registerPrompt('run_agent_baseline', {
49
61
  title: 'Run agent baseline evaluation',
50
62
  description: 'Run a Lightdash evaluation suite and fetch results',
@@ -52,26 +64,30 @@ Prefer deterministic expected responses. Do not invent local Git dataset MCP too
52
64
  agentUuid: zod_1.z.string().optional(),
53
65
  evalUuid: zod_1.z.string().optional(),
54
66
  },
55
- }, ({ agentUuid, evalUuid }) => userMessages(`Run a baseline evaluation for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'} suite ${evalUuid !== null && evalUuid !== void 0 ? evalUuid : '(select)'}.
56
-
57
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
67
+ }, ({ agentUuid, evalUuid }) => promptContext({
68
+ task: `Run a baseline evaluation for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'} suite ${evalUuid !== null && evalUuid !== void 0 ? evalUuid : '(select)'}.
58
69
 
59
70
  Use run_agent_evaluation then poll list_agent_evaluation_runs and get_agent_eval_run_results.
60
71
  Never silently substitute evaluate_agent_readiness for an evaluation run.
61
- Report run UUID, status, limitations, and hard failures from the product results.`, 'evaluation'));
72
+ Report run UUID, status, limitations, and hard failures from the product results.`,
73
+ invariantIds,
74
+ requiredTopics: [TOPIC_EVALUATION],
75
+ }));
62
76
  server.registerPrompt('investigate_agent_failures', {
63
77
  title: 'Investigate agent evaluation failures',
64
78
  description: 'Cluster failures in the host from run results (no analyze_* tool)',
65
79
  argsSchema: {
66
80
  runUuid: zod_1.z.string().optional(),
67
81
  },
68
- }, ({ runUuid }) => userMessages(`Investigate evaluation failures for run ${runUuid !== null && runUuid !== void 0 ? runUuid : '(from get_agent_eval_run_results)'}.
69
-
70
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
82
+ }, ({ runUuid }) => promptContext({
83
+ task: `Investigate evaluation failures for run ${runUuid !== null && runUuid !== void 0 ? runUuid : '(from get_agent_eval_run_results)'}.
71
84
 
72
85
  There is no lightdash_analyze_* tool. Fetch run results, cluster by root cause in the conversation,
73
86
  cite evidence, separate confirmed causes from hypotheses, and recommend the narrowest intervention.
74
- Prefer metadata fixes before instruction patches.`, 'loop-engineering'));
87
+ Prefer metadata fixes before instruction patches.`,
88
+ invariantIds,
89
+ requiredTopics: [TOPIC_LOOP_ENGINEERING],
90
+ }));
75
91
  server.registerPrompt('improve_agent_with_loop_engineering', {
76
92
  title: 'Improve agent with loop engineering',
77
93
  description: 'Bounded host+CLI+MCP improvement loop',
@@ -79,38 +95,44 @@ Prefer metadata fixes before instruction patches.`, 'loop-engineering'));
79
95
  agentUuid: zod_1.z.string().optional(),
80
96
  maxIterations: zod_1.z.string().optional().describe('Default 3'),
81
97
  },
82
- }, ({ agentUuid, maxIterations }) => userMessages(`Guide a bounded loop-engineering workflow for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'}.
83
-
84
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
98
+ }, ({ agentUuid, maxIterations }) => promptContext({
99
+ task: `Guide a bounded loop-engineering workflow for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'}.
85
100
 
86
101
  Max iterations: ${maxIterations !== null && maxIterations !== void 0 ? maxIterations : '3'}.
87
102
  Use MCP for inspect/eval runs; CLI agentops for bundle apply and gates; other profiles for semantic/content when available.
88
103
  Implementation changes happen outside agent CRUD on this server.
89
- Stop when gates pass, no safe intervention remains, or the budget is exhausted.`, 'loop-engineering'));
104
+ Stop when gates pass, no safe intervention remains, or the budget is exhausted.`,
105
+ invariantIds,
106
+ requiredTopics: [TOPIC_LOOP_ENGINEERING],
107
+ }));
90
108
  server.registerPrompt('review_agent_access_and_scope', {
91
109
  title: 'Review agent access and scope',
92
110
  description: 'Review tags, data access, and explore reachability',
93
111
  argsSchema: {
94
112
  agentUuid: zod_1.z.string().optional(),
95
113
  },
96
- }, ({ agentUuid }) => userMessages(`Review access and scope for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'}.
97
-
98
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
114
+ }, ({ agentUuid }) => promptContext({
115
+ task: `Review access and scope for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'}.
99
116
 
100
117
  Use get_project_agent and get_explore_access_summary. Note unexpectedly broad/narrow tags,
101
- data-access inconsistencies, and self-improvement risk. Do not mutate access.`));
118
+ data-access inconsistencies, and self-improvement risk. Do not mutate access.`,
119
+ invariantIds,
120
+ requiredTopics: [],
121
+ }));
102
122
  server.registerPrompt('review_agent_self_improvement', {
103
123
  title: 'Review agent self-improvement',
104
124
  description: 'Assess whether self-improvement is appropriately configured',
105
125
  argsSchema: {
106
126
  agentUuid: zod_1.z.string().optional(),
107
127
  },
108
- }, ({ agentUuid }) => userMessages(`Assess self-improvement configuration for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'}.
109
-
110
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
128
+ }, ({ agentUuid }) => promptContext({
129
+ task: `Assess self-improvement configuration for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'}.
111
130
 
112
131
  Consider access breadth, data access, evaluation coverage, release gates, and rollback readiness.
113
- Do not approve or apply proposals.`));
132
+ Do not approve or apply proposals.`,
133
+ invariantIds,
134
+ requiredTopics: [],
135
+ }));
114
136
  server.registerPrompt('compare_agent_candidates', {
115
137
  title: 'Compare agent evaluation candidates',
116
138
  description: 'Compare two evaluation runs for comparability then rank',
@@ -118,12 +140,14 @@ Do not approve or apply proposals.`));
118
140
  baselineRunUuid: zod_1.z.string().optional(),
119
141
  candidateRunUuid: zod_1.z.string().optional(),
120
142
  },
121
- }, ({ baselineRunUuid, candidateRunUuid }) => userMessages(`Compare baseline run ${baselineRunUuid !== null && baselineRunUuid !== void 0 ? baselineRunUuid : '(uuid)'} vs candidate ${candidateRunUuid !== null && candidateRunUuid !== void 0 ? candidateRunUuid : '(uuid)'}.
122
-
123
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
143
+ }, ({ baselineRunUuid, candidateRunUuid }) => promptContext({
144
+ task: `Compare baseline run ${baselineRunUuid !== null && baselineRunUuid !== void 0 ? baselineRunUuid : '(uuid)'} vs candidate ${candidateRunUuid !== null && candidateRunUuid !== void 0 ? candidateRunUuid : '(uuid)'}.
124
145
 
125
146
  Fetch both via get_agent_eval_run_results. Check suite/agent/mode comparability before ranking.
126
- Hard failures beat average scores. Never prefer a candidate with a critical regression.`, 'evaluation'));
147
+ Hard failures beat average scores. Never prefer a candidate with a critical regression.`,
148
+ invariantIds,
149
+ requiredTopics: [TOPIC_EVALUATION],
150
+ }));
127
151
  server.registerPrompt('prepare_agent_release', {
128
152
  title: 'Prepare agent release recommendation',
129
153
  description: 'Host release judgment using MCP results + CLI agentops gate',
@@ -131,11 +155,13 @@ Hard failures beat average scores. Never prefer a candidate with a critical regr
131
155
  agentUuid: zod_1.z.string().optional(),
132
156
  runUuid: zod_1.z.string().optional(),
133
157
  },
134
- }, ({ agentUuid, runUuid }) => userMessages(`Prepare a release recommendation for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'} using run ${runUuid !== null && runUuid !== void 0 ? runUuid : '(select)'}.
135
-
136
- ${playbooks_js_1.AI_AGENT_OPS_HARD_BANS}
158
+ }, ({ agentUuid, runUuid }) => promptContext({
159
+ task: `Prepare a release recommendation for agent ${agentUuid !== null && agentUuid !== void 0 ? agentUuid : '(select)'} using run ${runUuid !== null && runUuid !== void 0 ? runUuid : '(select)'}.
137
160
 
138
161
  Require MCP run results plus CLI agentops evaluate-gate evidence when available.
139
- Return PASS, CONDITIONAL, or FAIL with risks and rollback notes. Do not deploy.`, 'release-gate'));
162
+ Return PASS, CONDITIONAL, or FAIL with risks and rollback notes. Do not deploy.`,
163
+ invariantIds,
164
+ requiredTopics: [TOPIC_RELEASE_GATE],
165
+ }));
140
166
  }
141
167
  /* eslint-enable @typescript-eslint/no-deprecated */