@lightdash-tools/mcp 0.13.2 → 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 (137) hide show
  1. package/README.md +54 -18
  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/request-state-key.d.ts +1 -1
  15. package/dist/auth/request-state-key.js +1 -1
  16. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +2 -0
  17. package/dist/auth/resource-server/lightdash-oauth-middleware.js +58 -37
  18. package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +59 -57
  19. package/dist/auth/resource-server/oauth-protected-resource.d.ts +2 -2
  20. package/dist/auth/resource-server/oauth-protected-resource.js +10 -9
  21. package/dist/bin.js +34 -8
  22. package/dist/config/enabled-profiles.d.ts +23 -0
  23. package/dist/config/enabled-profiles.js +57 -0
  24. package/dist/config/enabled-profiles.test.d.ts +1 -0
  25. package/dist/config/enabled-profiles.test.js +62 -0
  26. package/dist/config/env.d.ts +7 -0
  27. package/dist/config/env.js +8 -1
  28. package/dist/config/load-mcp-config.d.ts +15 -1
  29. package/dist/config/load-mcp-config.js +21 -9
  30. package/dist/config/load-mcp-config.test.js +61 -0
  31. package/dist/config/prompt-context-policy.d.ts +18 -0
  32. package/dist/config/prompt-context-policy.js +40 -0
  33. package/dist/config/prompt-context-policy.test.d.ts +4 -0
  34. package/dist/config/prompt-context-policy.test.js +35 -0
  35. package/dist/config/test-mcp-http-config.js +4 -1
  36. package/dist/governance/mcp-post-factory-context.d.ts +2 -0
  37. package/dist/http.d.ts +7 -1
  38. package/dist/http.integration.test.js +102 -44
  39. package/dist/http.js +10 -1
  40. package/dist/index.d.ts +6 -1
  41. package/dist/index.integration.test.js +3 -12
  42. package/dist/index.js +6 -3
  43. package/dist/policy/content-developer.d.ts +5 -0
  44. package/dist/policy/content-developer.js +25 -1
  45. package/dist/policy/content-developer.test.js +29 -0
  46. package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +27 -0
  47. package/dist/profiles/ai-agent-ops/v1/invariants.js +39 -0
  48. package/dist/profiles/ai-agent-ops/v1/prompts.d.ts +3 -2
  49. package/dist/profiles/ai-agent-ops/v1/prompts.js +67 -41
  50. package/dist/profiles/ai-agent-ops/v1/resources/playbooks.d.ts +2 -1
  51. package/dist/profiles/ai-agent-ops/v1/resources/playbooks.js +10 -3
  52. package/dist/profiles/content-developer/v1/invariants.d.ts +69 -0
  53. package/dist/profiles/content-developer/v1/invariants.js +95 -0
  54. package/dist/profiles/content-developer/v1/prompt-specs.d.ts +32 -0
  55. package/dist/profiles/content-developer/v1/prompt-specs.js +56 -0
  56. package/dist/profiles/content-developer/v1/prompts.d.ts +4 -3
  57. package/dist/profiles/content-developer/v1/prompts.js +65 -71
  58. package/dist/profiles/content-developer/v1/prompts.test.js +61 -7
  59. package/dist/profiles/content-developer/v1/resources/playbooks/chart-types.md +2 -1
  60. package/dist/profiles/content-developer/v1/resources/playbooks/core.md +3 -1
  61. package/dist/profiles/content-developer/v1/resources/playbooks/dashboard-design.md +11 -1
  62. package/dist/profiles/content-developer/v1/resources/playbooks/dashboards.md +1 -1
  63. package/dist/profiles/content-developer/v1/resources/playbooks/index.md +11 -8
  64. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/dashboard-diff.md +15 -0
  65. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-required.md +14 -0
  66. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-stale.md +21 -0
  67. package/dist/profiles/content-developer/v1/resources/playbooks/table-calculations.md +15 -3
  68. package/dist/profiles/content-developer/v1/resources/playbooks.d.ts +3 -2
  69. package/dist/profiles/content-developer/v1/resources/playbooks.js +35 -21
  70. package/dist/profiles/content-governance/v1/invariants.d.ts +27 -0
  71. package/dist/profiles/content-governance/v1/invariants.js +39 -0
  72. package/dist/profiles/content-governance/v1/prompts.d.ts +4 -2
  73. package/dist/profiles/content-governance/v1/prompts.js +31 -19
  74. package/dist/profiles/content-governance/v1/resources/playbooks.d.ts +2 -1
  75. package/dist/profiles/content-governance/v1/resources/playbooks.js +8 -9
  76. package/dist/profiles/content-reader/v1/index.js +1 -0
  77. package/dist/profiles/content-reader/v1/invariants.d.ts +33 -0
  78. package/dist/profiles/content-reader/v1/invariants.js +47 -0
  79. package/dist/profiles/content-reader/v1/prompt-specs.d.ts +18 -0
  80. package/dist/profiles/content-reader/v1/prompt-specs.js +33 -0
  81. package/dist/profiles/content-reader/v1/prompts.d.ts +3 -2
  82. package/dist/profiles/content-reader/v1/prompts.js +69 -75
  83. package/dist/profiles/content-reader/v1/resources/playbooks/compare.md +1 -1
  84. package/dist/profiles/content-reader/v1/resources/playbooks/core.md +1 -0
  85. package/dist/profiles/content-reader/v1/resources/playbooks/discover.md +12 -3
  86. package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +2 -1
  87. package/dist/profiles/content-reader/v1/resources/playbooks.d.ts +2 -1
  88. package/dist/profiles/content-reader/v1/resources/playbooks.js +10 -11
  89. package/dist/profiles/data-analyst/v1/invariants.d.ts +21 -0
  90. package/dist/profiles/data-analyst/v1/invariants.js +31 -0
  91. package/dist/profiles/data-analyst/v1/prompts.d.ts +3 -2
  92. package/dist/profiles/data-analyst/v1/prompts.js +17 -9
  93. package/dist/profiles/data-analyst/v1/resources/playbooks.d.ts +2 -1
  94. package/dist/profiles/data-analyst/v1/resources/playbooks.js +6 -7
  95. package/dist/profiles/index.d.ts +2 -1
  96. package/dist/profiles/index.js +2 -1
  97. package/dist/profiles/index.test.js +2 -1
  98. package/dist/profiles/lib/playbook-resources.d.ts +16 -34
  99. package/dist/profiles/lib/playbook-resources.js +55 -76
  100. package/dist/profiles/lib/prompt-context.d.ts +71 -0
  101. package/dist/profiles/lib/prompt-context.js +205 -0
  102. package/dist/profiles/lib/prompt-context.test.d.ts +4 -0
  103. package/dist/profiles/lib/prompt-context.test.js +154 -0
  104. package/dist/profiles/lib/prompt-invariants.d.ts +20 -0
  105. package/dist/profiles/lib/prompt-invariants.js +54 -0
  106. package/dist/profiles/organization-audit/v1/invariants.d.ts +24 -0
  107. package/dist/profiles/organization-audit/v1/invariants.js +35 -0
  108. package/dist/profiles/organization-audit/v1/prompts.d.ts +3 -2
  109. package/dist/profiles/organization-audit/v1/prompts.js +44 -28
  110. package/dist/profiles/organization-audit/v1/resources/playbooks.d.ts +2 -1
  111. package/dist/profiles/organization-audit/v1/resources/playbooks.js +10 -3
  112. package/dist/profiles/semantic-layer/v1/invariants.d.ts +27 -0
  113. package/dist/profiles/semantic-layer/v1/invariants.js +39 -0
  114. package/dist/profiles/semantic-layer/v1/prompts.d.ts +3 -2
  115. package/dist/profiles/semantic-layer/v1/prompts.js +37 -26
  116. package/dist/profiles/semantic-layer/v1/resources/playbooks.d.ts +2 -4
  117. package/dist/profiles/semantic-layer/v1/resources/playbooks.js +8 -7
  118. package/dist/profiles/test-support/prompt-context-budget.test.d.ts +5 -0
  119. package/dist/profiles/test-support/prompt-context-budget.test.js +72 -0
  120. package/dist/profiles/types.d.ts +6 -1
  121. package/dist/server/capabilities.d.ts +3 -0
  122. package/dist/server/capabilities.js +4 -2
  123. package/dist/stdio.process.test.js +2 -1
  124. package/dist/tools/lib/schema-fields.d.ts +4 -0
  125. package/dist/tools/lib/schema-fields.js +8 -1
  126. package/dist/tools/project/developer-content-preview.js +1 -1
  127. package/dist/tools/project/developer-content.js +2 -2
  128. package/dist/tools/project/reader-content.d.ts +2 -0
  129. package/dist/tools/project/reader-content.js +28 -1
  130. package/dist/tools/query/reader-tool-helpers.d.ts +2 -2
  131. package/dist/tools/query/reader-tool-helpers.js +2 -2
  132. package/dist/tools/query/reader-tool-helpers.test.js +1 -0
  133. package/dist/tools/shared.d.ts +6 -1
  134. package/dist/tools/shared.js +12 -2
  135. package/dist/transports/streamable-http.js +16 -6
  136. package/dist/transports/streamable-http.test.js +16 -0
  137. package/package.json +3 -3
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 */
@@ -3,8 +3,9 @@
3
3
  */
4
4
  import type { McpServer } from '@modelcontextprotocol/server';
5
5
  export type AiAgentOpsPlaybookTopic = 'evaluation' | 'loop-engineering' | 'release-gate';
6
- export declare const AI_AGENT_OPS_HARD_BANS: string;
6
+ export { AI_AGENT_OPS_HARD_BANS } from '../invariants.js';
7
7
  export declare const getAllPlaybookMarkdown: () => string;
8
8
  export declare const AI_AGENT_OPS_CORE_PLAYBOOK: import("../../../lib/playbook-resources.js").EmbeddedPlaybook;
9
9
  export declare const AI_AGENT_OPS_TOPIC_PLAYBOOKS: Readonly<Record<AiAgentOpsPlaybookTopic, import("../../../lib/playbook-resources.js").EmbeddedPlaybook>>;
10
+ export declare const AI_AGENT_OPS_TOPIC_META: Readonly<Record<AiAgentOpsPlaybookTopic, import("../../../lib/playbook-resources.js").PromptTopicMeta>>;
10
11
  export declare function registerAiAgentOpsPlaybook(server: McpServer): void;
@@ -3,13 +3,12 @@
3
3
  * AI agent-ops multi-playbook resources (core + topics + index).
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AI_AGENT_OPS_TOPIC_PLAYBOOKS = exports.AI_AGENT_OPS_CORE_PLAYBOOK = exports.getAllPlaybookMarkdown = exports.AI_AGENT_OPS_HARD_BANS = void 0;
6
+ exports.AI_AGENT_OPS_TOPIC_META = exports.AI_AGENT_OPS_TOPIC_PLAYBOOKS = exports.AI_AGENT_OPS_CORE_PLAYBOOK = exports.getAllPlaybookMarkdown = exports.AI_AGENT_OPS_HARD_BANS = void 0;
7
7
  exports.registerAiAgentOpsPlaybook = registerAiAgentOpsPlaybook;
8
8
  const playbook_resources_js_1 = require("../../../lib/playbook-resources.js");
9
9
  const playbooks = (0, playbook_resources_js_1.defineProfilePlaybooks)({
10
10
  profileId: 'ai-agent-ops',
11
11
  moduleDir: __dirname,
12
- hardBans: 'Do not create/update/delete agents on this server, start or continue threads, mutate users/roles/semantic models/charts, run local offline scorers, write Git eval artifact stores via MCP, invent recommend_* or analyze_* mega-tools, or claim a CLI promotion gate passed from MCP run results alone. Those capabilities are not available as MCP mega-tools here — use CLI agentops / other profiles / the host.',
13
12
  coreDescription: 'Hard bans, tool catalog, truth labels, and distributed loop rules',
14
13
  topics: [
15
14
  {
@@ -17,25 +16,33 @@ const playbooks = (0, playbook_resources_js_1.defineProfilePlaybooks)({
17
16
  title: 'AI agent-ops evaluation playbook',
18
17
  description: 'Product evaluation suites and readiness API usage',
19
18
  file: 'evaluation.md',
19
+ useWhen: 'Designing, running, or comparing product evaluation suites',
20
+ priority: 0.8,
20
21
  },
21
22
  {
22
23
  id: 'loop-engineering',
23
24
  title: 'AI agent-ops loop-engineering playbook',
24
25
  description: 'Host-driven improve loop across MCP, CLI, and other profiles',
25
26
  file: 'loop-engineering.md',
27
+ useWhen: 'Investigating failures or running a bounded improve loop',
28
+ priority: 0.75,
26
29
  },
27
30
  {
28
31
  id: 'release-gate',
29
32
  title: 'AI agent-ops release-gate playbook',
30
33
  description: 'Promotion decisions via CLI agentops evaluate-gate',
31
34
  file: 'release-gate.md',
35
+ useWhen: 'Preparing a release recommendation or promotion gate',
36
+ priority: 0.7,
32
37
  },
33
38
  ],
34
39
  });
35
- exports.AI_AGENT_OPS_HARD_BANS = playbooks.HARD_BANS;
40
+ var invariants_js_1 = require("../invariants.js");
41
+ Object.defineProperty(exports, "AI_AGENT_OPS_HARD_BANS", { enumerable: true, get: function () { return invariants_js_1.AI_AGENT_OPS_HARD_BANS; } });
36
42
  exports.getAllPlaybookMarkdown = playbooks.getAllPlaybookMarkdown;
37
43
  exports.AI_AGENT_OPS_CORE_PLAYBOOK = playbooks.CORE_PLAYBOOK;
38
44
  exports.AI_AGENT_OPS_TOPIC_PLAYBOOKS = playbooks.TOPIC_PLAYBOOKS;
45
+ exports.AI_AGENT_OPS_TOPIC_META = playbooks.TOPIC_META;
39
46
  function registerAiAgentOpsPlaybook(server) {
40
47
  playbooks.registerPlaybooks(server);
41
48
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Content-developer structured prompt invariants (SSOT for capsules + HARD_BANS projection).
3
+ */
4
+ export declare const CONTENT_DEVELOPER_INVARIANTS: readonly [{
5
+ readonly id: "no-arbitrary-sql";
6
+ readonly short: "Do not execute arbitrary metric queries, raw SQL, warehouse runs, or saved-chart execution.";
7
+ }, {
8
+ readonly id: "no-sql-charts";
9
+ readonly short: "Do not author or upsert SQL charts.";
10
+ }, {
11
+ readonly id: "no-hard-delete-promote";
12
+ readonly short: "Do not hard-delete, rollback, or promote content (use content-governance for promote).";
13
+ }, {
14
+ readonly id: "no-org-admin";
15
+ readonly short: "Do not perform organization administration or list org-wide projects.";
16
+ }, {
17
+ readonly id: "no-space-crud";
18
+ readonly short: "Do not create or update spaces — spaces are Terraform / out-of-band; use existing spaces only.";
19
+ }, {
20
+ readonly id: "no-space-only-charts";
21
+ readonly short: "Do not create space-only charts for dashboard work — set dashboardSlug to the dashboard shell already created.";
22
+ }, {
23
+ readonly id: "design-approval";
24
+ readonly short: "Do not call preview_* or write tools for a new dashboard or a material dashboard redesign until a Design Spec (with settled Objective) was presented and the user approved or amended it in-thread.";
25
+ }, {
26
+ readonly id: "objective-first";
27
+ readonly short: "Do not start writes from a viz-type or all-chart-types checklist alone — settle Objective and insight questions first (an explicit user all-types ask may be the Objective after a one-line restatement).";
28
+ }, {
29
+ readonly id: "project-scope";
30
+ readonly short: "Do not call confirm_preview without projectUuid when there is no HTTP X-Lightdash-Project pin (PROJECT_SCOPE_REQUIRED).";
31
+ }, {
32
+ readonly id: "tile-targets-filters";
33
+ readonly short: "Do not attach dashboard filters whose target.tableName is absent from a tile explore without excluding that tile (or remapping) via tileTargets.";
34
+ }, {
35
+ readonly id: "dashboard-shell-first";
36
+ readonly short: "Do not treat chart create as done without a dashboard shell and tiles.";
37
+ }, {
38
+ readonly id: "no-invent-field-ids";
39
+ readonly short: "Do not invent fieldIds — clone via get_chart_as_code / get_chart or use semantic-layer.";
40
+ }, {
41
+ readonly id: "no-skinny-chart-config";
42
+ readonly short: "Do not invent skinny chartConfig — clone a working as-code body and keep series/layout/encode.";
43
+ }, {
44
+ readonly id: "no-verify-unless-asked";
45
+ readonly short: "Do not set chart verified or dashboard preserveVerification unless the user explicitly asks (verify permission required).";
46
+ }, {
47
+ readonly id: "preview-confirm-apply";
48
+ readonly short: "Do not apply a write tool without a confirmed, unexpired HMAC previewToken from the matching preview_* tool (confirm_preview unlocks every write; use the new validated token).";
49
+ }, {
50
+ readonly id: "immutable-preview-payload";
51
+ readonly short: "Do not mutate the proposed payload after preview_* (description/name/SQL/metrics/tiles) — apply must reuse the identical proposed body or PREVIEW_STALE (content hash mismatch); any edit requires a new preview_*.";
52
+ }, {
53
+ readonly id: "preview-kind-key-match";
54
+ readonly short: "Do not unlock with a different resource's preview — resourceKind / resourceKey must match the preview exactly.";
55
+ }, {
56
+ readonly id: "validate-not-unlock";
57
+ readonly short: "Do not treat validate_chart / validate_dashboard as a preview unlock — they are saved-UUID health checks only (validate_chart needs chartUuid).";
58
+ }, {
59
+ readonly id: "no-reuse-draft-token";
60
+ readonly short: "Do not reuse a draft previewToken after confirm; re-run preview if the resource drifts (PREVIEW_STALE).";
61
+ }, {
62
+ readonly id: "no-sdd-mcp-click-loops";
63
+ readonly short: "Do not use subagent-driven-development or multi-task writing-plans solely to click MCP preview/confirm/apply for lab boards (e.g. experiments) — after Design Spec approval, run Batch SOP inline in the same session.";
64
+ }, {
65
+ readonly id: "no-secrets";
66
+ readonly short: "Do not reveal secrets, warehouse credentials, or saved SQL chart bodies.";
67
+ }];
68
+ export declare const CONTENT_DEVELOPER_HARD_BANS: string;
69
+ export declare const CONTENT_DEVELOPER_DEFAULT_INVARIANT_IDS: readonly ("no-arbitrary-sql" | "no-sql-charts" | "no-hard-delete-promote" | "no-org-admin" | "no-space-crud" | "no-space-only-charts" | "design-approval" | "objective-first" | "project-scope" | "tile-targets-filters" | "dashboard-shell-first" | "no-invent-field-ids" | "no-skinny-chart-config" | "no-verify-unless-asked" | "preview-confirm-apply" | "immutable-preview-payload" | "preview-kind-key-match" | "validate-not-unlock" | "no-reuse-draft-token" | "no-sdd-mcp-click-loops" | "no-secrets")[];