@lightdash-tools/mcp 0.14.0 → 0.17.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 (126) hide show
  1. package/README.md +43 -14
  2. package/dist/auth/oauth-broker/as-metadata.d.ts +6 -2
  3. package/dist/auth/oauth-broker/as-metadata.js +8 -4
  4. package/dist/auth/oauth-broker/invoke-origins.d.ts +16 -0
  5. package/dist/auth/oauth-broker/invoke-origins.js +112 -0
  6. package/dist/auth/oauth-broker/invoke-origins.test.d.ts +1 -0
  7. package/dist/auth/oauth-broker/invoke-origins.test.js +82 -0
  8. package/dist/auth/oauth-broker/lightdash-token.d.ts +6 -5
  9. package/dist/auth/oauth-broker/lightdash-token.js +6 -10
  10. package/dist/auth/oauth-broker/mcp-access-token.d.ts +31 -0
  11. package/dist/auth/oauth-broker/mcp-access-token.js +109 -0
  12. package/dist/auth/oauth-broker/mcp-access-token.test.d.ts +1 -0
  13. package/dist/auth/oauth-broker/mcp-access-token.test.js +61 -0
  14. package/dist/auth/oauth-broker/pending-store.d.ts +9 -3
  15. package/dist/auth/oauth-broker/pending-store.js +5 -3
  16. package/dist/auth/oauth-broker/pending-store.test.js +28 -44
  17. package/dist/auth/oauth-broker/routes.d.ts +2 -1
  18. package/dist/auth/oauth-broker/routes.js +124 -48
  19. package/dist/auth/oauth-broker/routes.test.js +191 -16
  20. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +3 -1
  21. package/dist/auth/resource-server/lightdash-oauth-middleware.js +65 -41
  22. package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +95 -59
  23. package/dist/auth/resource-server/oauth-protected-resource.d.ts +2 -2
  24. package/dist/auth/resource-server/oauth-protected-resource.js +8 -11
  25. package/dist/auth/resource-server/www-authenticate.test.js +3 -3
  26. package/dist/bin.js +33 -7
  27. package/dist/config/env.d.ts +10 -0
  28. package/dist/config/env.js +11 -1
  29. package/dist/config/load-mcp-config.d.ts +14 -1
  30. package/dist/config/load-mcp-config.js +35 -8
  31. package/dist/config/load-mcp-config.test.js +49 -0
  32. package/dist/config/prompt-context-policy.d.ts +18 -0
  33. package/dist/config/prompt-context-policy.js +40 -0
  34. package/dist/config/prompt-context-policy.test.d.ts +4 -0
  35. package/dist/config/prompt-context-policy.test.js +35 -0
  36. package/dist/config/test-mcp-http-config.js +1 -1
  37. package/dist/governance/mcp-post-factory-context.d.ts +2 -0
  38. package/dist/http.d.ts +7 -1
  39. package/dist/http.integration.helpers.d.ts +50 -0
  40. package/dist/http.integration.helpers.js +190 -0
  41. package/dist/http.integration.test.js +81 -187
  42. package/dist/http.invoke-origin.integration.test.d.ts +1 -0
  43. package/dist/http.invoke-origin.integration.test.js +108 -0
  44. package/dist/http.js +10 -1
  45. package/dist/index.d.ts +6 -1
  46. package/dist/index.js +6 -3
  47. package/dist/policy/content-developer.d.ts +5 -0
  48. package/dist/policy/content-developer.js +25 -1
  49. package/dist/policy/content-developer.test.js +29 -0
  50. package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +27 -0
  51. package/dist/profiles/ai-agent-ops/v1/invariants.js +39 -0
  52. package/dist/profiles/ai-agent-ops/v1/prompts.d.ts +3 -2
  53. package/dist/profiles/ai-agent-ops/v1/prompts.js +67 -41
  54. package/dist/profiles/ai-agent-ops/v1/resources/playbooks.d.ts +2 -1
  55. package/dist/profiles/ai-agent-ops/v1/resources/playbooks.js +10 -3
  56. package/dist/profiles/content-developer/v1/invariants.d.ts +69 -0
  57. package/dist/profiles/content-developer/v1/invariants.js +95 -0
  58. package/dist/profiles/content-developer/v1/prompt-specs.d.ts +32 -0
  59. package/dist/profiles/content-developer/v1/prompt-specs.js +56 -0
  60. package/dist/profiles/content-developer/v1/prompts.d.ts +4 -3
  61. package/dist/profiles/content-developer/v1/prompts.js +65 -71
  62. package/dist/profiles/content-developer/v1/prompts.test.js +61 -7
  63. package/dist/profiles/content-developer/v1/resources/playbooks/core.md +1 -0
  64. package/dist/profiles/content-developer/v1/resources/playbooks/index.md +11 -8
  65. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/dashboard-diff.md +15 -0
  66. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-required.md +14 -0
  67. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-stale.md +21 -0
  68. package/dist/profiles/content-developer/v1/resources/playbooks.d.ts +3 -2
  69. package/dist/profiles/content-developer/v1/resources/playbooks.js +35 -22
  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/invariants.d.ts +33 -0
  77. package/dist/profiles/content-reader/v1/invariants.js +47 -0
  78. package/dist/profiles/content-reader/v1/prompt-specs.d.ts +18 -0
  79. package/dist/profiles/content-reader/v1/prompt-specs.js +33 -0
  80. package/dist/profiles/content-reader/v1/prompts.d.ts +3 -2
  81. package/dist/profiles/content-reader/v1/prompts.js +69 -76
  82. package/dist/profiles/content-reader/v1/resources/playbooks.d.ts +2 -1
  83. package/dist/profiles/content-reader/v1/resources/playbooks.js +10 -11
  84. package/dist/profiles/data-analyst/v1/invariants.d.ts +21 -0
  85. package/dist/profiles/data-analyst/v1/invariants.js +31 -0
  86. package/dist/profiles/data-analyst/v1/prompts.d.ts +3 -2
  87. package/dist/profiles/data-analyst/v1/prompts.js +17 -9
  88. package/dist/profiles/data-analyst/v1/resources/playbooks.d.ts +2 -1
  89. package/dist/profiles/data-analyst/v1/resources/playbooks.js +6 -7
  90. package/dist/profiles/lib/playbook-resources.d.ts +16 -34
  91. package/dist/profiles/lib/playbook-resources.js +55 -76
  92. package/dist/profiles/lib/prompt-context.d.ts +71 -0
  93. package/dist/profiles/lib/prompt-context.js +205 -0
  94. package/dist/profiles/lib/prompt-context.test.d.ts +4 -0
  95. package/dist/profiles/lib/prompt-context.test.js +154 -0
  96. package/dist/profiles/lib/prompt-invariants.d.ts +20 -0
  97. package/dist/profiles/lib/prompt-invariants.js +54 -0
  98. package/dist/profiles/organization-audit/v1/invariants.d.ts +24 -0
  99. package/dist/profiles/organization-audit/v1/invariants.js +35 -0
  100. package/dist/profiles/organization-audit/v1/prompts.d.ts +3 -2
  101. package/dist/profiles/organization-audit/v1/prompts.js +44 -28
  102. package/dist/profiles/organization-audit/v1/resources/playbooks.d.ts +2 -1
  103. package/dist/profiles/organization-audit/v1/resources/playbooks.js +10 -3
  104. package/dist/profiles/semantic-layer/v1/invariants.d.ts +27 -0
  105. package/dist/profiles/semantic-layer/v1/invariants.js +39 -0
  106. package/dist/profiles/semantic-layer/v1/prompts.d.ts +3 -2
  107. package/dist/profiles/semantic-layer/v1/prompts.js +37 -26
  108. package/dist/profiles/semantic-layer/v1/resources/playbooks.d.ts +2 -4
  109. package/dist/profiles/semantic-layer/v1/resources/playbooks.js +8 -7
  110. package/dist/profiles/test-support/prompt-context-budget.test.d.ts +5 -0
  111. package/dist/profiles/test-support/prompt-context-budget.test.js +72 -0
  112. package/dist/profiles/types.d.ts +6 -1
  113. package/dist/server/capabilities.d.ts +3 -0
  114. package/dist/server/capabilities.js +4 -2
  115. package/dist/tools/lib/schema-fields.d.ts +4 -0
  116. package/dist/tools/lib/schema-fields.js +8 -1
  117. package/dist/tools/project/developer-content-preview.js +1 -1
  118. package/dist/tools/project/developer-content.js +2 -2
  119. package/dist/tools/query/reader-tool-helpers.d.ts +2 -2
  120. package/dist/tools/query/reader-tool-helpers.js +2 -2
  121. package/dist/tools/query/reader-tool-helpers.test.js +1 -0
  122. package/dist/tools/shared.d.ts +6 -1
  123. package/dist/tools/shared.js +12 -2
  124. package/dist/transports/streamable-http.js +13 -4
  125. package/dist/transports/streamable-http.test.js +8 -3
  126. package/package.json +3 -3
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Cross-profile prompt-context budget gates (deterministic; RFC).
4
+ * Specs come from production builders — not abbreviated stubs.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const vitest_1 = require("vitest");
8
+ const invariants_js_1 = require("../content-developer/v1/invariants.js");
9
+ const prompt_specs_js_1 = require("../content-developer/v1/prompt-specs.js");
10
+ const playbooks_js_1 = require("../content-developer/v1/resources/playbooks.js");
11
+ const invariants_js_2 = require("../content-reader/v1/invariants.js");
12
+ const prompt_specs_js_2 = require("../content-reader/v1/prompt-specs.js");
13
+ const playbooks_js_2 = require("../content-reader/v1/resources/playbooks.js");
14
+ const prompt_context_js_1 = require("../lib/prompt-context.js");
15
+ const SCENARIOS = [
16
+ {
17
+ profile: 'content-reader',
18
+ prompt: 'find_content',
19
+ invariants: invariants_js_2.CONTENT_READER_INVARIANTS,
20
+ core: playbooks_js_2.CONTENT_READER_CORE_PLAYBOOK,
21
+ topics: playbooks_js_2.CONTENT_READER_TOPIC_PLAYBOOKS,
22
+ topicMeta: playbooks_js_2.CONTENT_READER_TOPIC_META,
23
+ spec: (0, prompt_specs_js_2.buildFindContentPromptSpec)({
24
+ question: 'revenue by region',
25
+ projectUuid: 'pin',
26
+ verifiedOnly: false,
27
+ }),
28
+ },
29
+ {
30
+ profile: 'content-developer',
31
+ prompt: 'create_dashboard',
32
+ invariants: invariants_js_1.CONTENT_DEVELOPER_INVARIANTS,
33
+ core: playbooks_js_1.CONTENT_DEVELOPER_CORE_PLAYBOOK,
34
+ topics: playbooks_js_1.CONTENT_DEVELOPER_TOPIC_PLAYBOOKS,
35
+ topicMeta: playbooks_js_1.CONTENT_DEVELOPER_TOPIC_META,
36
+ spec: (0, prompt_specs_js_1.buildCreateDashboardPromptSpec)({
37
+ goal: 'executive revenue overview',
38
+ projectUuid: 'pin',
39
+ }),
40
+ },
41
+ ];
42
+ function metricsForScenario(scenario) {
43
+ const bind = (0, prompt_context_js_1.bindProfilePromptContext)({
44
+ invariants: scenario.invariants,
45
+ core: scenario.core,
46
+ topics: scenario.topics,
47
+ topicMeta: scenario.topicMeta,
48
+ });
49
+ const byPolicy = {};
50
+ for (const policy of ['compact', 'compatible', 'embedded']) {
51
+ byPolicy[policy] = (0, prompt_context_js_1.measurePromptMessages)(bind(policy)(scenario.spec).messages);
52
+ }
53
+ return byPolicy;
54
+ }
55
+ (0, vitest_1.describe)('prompt context budgets', () => {
56
+ for (const scenario of SCENARIOS) {
57
+ (0, vitest_1.it)(`${scenario.profile}/${scenario.prompt}: compact has no embeds and beats embedded by ≥40%`, () => {
58
+ const { compact, embedded } = metricsForScenario(scenario);
59
+ (0, vitest_1.expect)(compact.embeddedResourceCount).toBe(0);
60
+ (0, vitest_1.expect)(embedded.embeddedResourceCount).toBeGreaterThan(0);
61
+ const reduction = 1 - compact.totalChars / embedded.totalChars;
62
+ (0, vitest_1.expect)(reduction).toBeGreaterThanOrEqual(0.4);
63
+ (0, vitest_1.expect)((0, prompt_context_js_1.approxTokensFromChars)(compact.totalChars)).toBeLessThanOrEqual(1500);
64
+ });
65
+ (0, vitest_1.it)(`${scenario.profile}/${scenario.prompt}: compatible embeds only required topics`, () => {
66
+ var _a, _b;
67
+ const { compatible, embedded } = metricsForScenario(scenario);
68
+ (0, vitest_1.expect)(compatible.embeddedResourceCount).toBe((_b = (_a = scenario.spec.requiredTopics) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);
69
+ (0, vitest_1.expect)(compatible.totalChars).toBeLessThan(embedded.totalChars);
70
+ });
71
+ }
72
+ });
@@ -1,10 +1,15 @@
1
1
  /**
2
2
  * Profile packaging types — tools are ToolModules imported by each profile.
3
3
  */
4
+ import type { PromptContextPolicy } from '../config/prompt-context-policy.js';
4
5
  import type { ToolModule } from '../tools/types.js';
5
6
  import type { ProfileId } from '@lightdash-tools/common';
6
7
  import type { McpServer } from '@modelcontextprotocol/server';
7
8
  export type { ProfileId };
9
+ export type RegisterPromptsOptions = {
10
+ /** Progressive-disclosure playbook embedding policy. */
11
+ promptContextPolicy?: PromptContextPolicy;
12
+ };
8
13
  export type ProfileDefinition = {
9
14
  id: ProfileId;
10
15
  /** Fixed Streamable HTTP MCP endpoint path for this profile. */
@@ -18,6 +23,6 @@ export type ProfileDefinition = {
18
23
  * Mounted tools for this profile (import ToolModules; array order is tools/list order).
19
24
  */
20
25
  tools: readonly ToolModule[];
21
- registerPrompts: (server: McpServer) => void;
26
+ registerPrompts: (server: McpServer, options?: RegisterPromptsOptions) => void;
22
27
  registerResources: (server: McpServer) => void;
23
28
  };
@@ -1,12 +1,15 @@
1
1
  /**
2
2
  * Registers MCP capabilities for a profile.
3
3
  */
4
+ import { type PromptContextPolicy } from '../config/prompt-context-policy.js';
4
5
  import type { McpContextProvider } from './request-context.js';
5
6
  import type { ProfileDefinition } from '../profiles/types.js';
6
7
  import type { McpServer } from '@modelcontextprotocol/server';
7
8
  export type RegisterCapabilitiesOptions = {
8
9
  /** Profile to register (defaults to {@link getDefaultProfile}). */
9
10
  profile?: ProfileDefinition;
11
+ /** Progressive-disclosure prompt context policy (defaults to package default). */
12
+ promptContextPolicy?: PromptContextPolicy;
10
13
  };
11
14
  /**
12
15
  * Registers MCP capabilities for the given profile.
@@ -5,6 +5,7 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.registerCapabilities = registerCapabilities;
7
7
  const server_profile_js_1 = require("../audit/server-profile.js");
8
+ const prompt_context_policy_js_1 = require("../config/prompt-context-policy.js");
8
9
  const index_js_1 = require("../profiles/index.js");
9
10
  const registry_js_1 = require("../tools/registry.js");
10
11
  /**
@@ -12,10 +13,11 @@ const registry_js_1 = require("../tools/registry.js");
12
13
  * Tools come from profile.tools (ToolModule imports).
13
14
  */
14
15
  function registerCapabilities(server, contextProvider, options) {
15
- var _a;
16
+ var _a, _b;
16
17
  const profile = (_a = options === null || options === void 0 ? void 0 : options.profile) !== null && _a !== void 0 ? _a : (0, index_js_1.getDefaultProfile)();
18
+ const promptContextPolicy = (_b = options === null || options === void 0 ? void 0 : options.promptContextPolicy) !== null && _b !== void 0 ? _b : prompt_context_policy_js_1.DEFAULT_PROMPT_CONTEXT_POLICY;
17
19
  (0, server_profile_js_1.bindServerProfile)(server, profile.id);
18
20
  (0, registry_js_1.registerTools)(server, contextProvider, profile.tools);
19
- profile.registerPrompts(server);
21
+ profile.registerPrompts(server, { promptContextPolicy });
20
22
  profile.registerResources(server);
21
23
  }
@@ -1,5 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  export declare const PROJECT_UUID_DESC = "Project UUID";
3
+ /** Prompt-body hint when projectUuid arg is omitted (HTTP pin or PROJECT_SCOPE_REQUIRED). */
4
+ export declare const PROMPT_PROJECT_UUID_HINT: "(pass on every tool, or use HTTP pin \u2014 else PROJECT_SCOPE_REQUIRED)";
5
+ /** Eager prompt line for optional projectUuid (HTTP pin or ask). */
6
+ export declare function formatPromptProjectUuidLine(projectUuid?: string): string;
3
7
  export declare const projectUuidField: () => z.ZodString;
4
8
  /** Optional projectUuid when HTTP pin (`X-Lightdash-Project`) can resolve scope. */
5
9
  export declare const optionalProjectUuidField: () => z.ZodOptional<z.ZodString>;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allowedEmailDomainsField = exports.includeEmailField = exports.uuidOrSlugField = exports.optionalProjectUuidField = exports.projectUuidField = exports.PROJECT_UUID_DESC = void 0;
3
+ exports.allowedEmailDomainsField = exports.includeEmailField = exports.uuidOrSlugField = exports.optionalProjectUuidField = exports.projectUuidField = exports.PROMPT_PROJECT_UUID_HINT = exports.PROJECT_UUID_DESC = void 0;
4
+ exports.formatPromptProjectUuidLine = formatPromptProjectUuidLine;
4
5
  const zod_1 = require("zod");
5
6
  exports.PROJECT_UUID_DESC = 'Project UUID';
7
+ /** Prompt-body hint when projectUuid arg is omitted (HTTP pin or PROJECT_SCOPE_REQUIRED). */
8
+ exports.PROMPT_PROJECT_UUID_HINT = '(pass on every tool, or use HTTP pin — else PROJECT_SCOPE_REQUIRED)';
9
+ /** Eager prompt line for optional projectUuid (HTTP pin or ask). */
10
+ function formatPromptProjectUuidLine(projectUuid) {
11
+ return `Project UUID: ${projectUuid !== null && projectUuid !== void 0 ? projectUuid : exports.PROMPT_PROJECT_UUID_HINT}.`;
12
+ }
6
13
  const projectUuidField = () => zod_1.z.string().describe(exports.PROJECT_UUID_DESC);
7
14
  exports.projectUuidField = projectUuidField;
8
15
  /** Optional projectUuid when HTTP pin (`X-Lightdash-Project`) can resolve scope. */
@@ -257,7 +257,7 @@ function registerPreviewContentMove(server, contextProvider) {
257
257
  isNotFound: api_errors_js_1.isNotFoundError,
258
258
  });
259
259
  if (resolved.kind === 'error') {
260
- return (0, reader_tool_helpers_js_1.codedErrorResult)(resolved.error.code, resolved.error.message);
260
+ return (0, content_developer_js_1.developerCodedErrorResult)(resolved.error.code, resolved.error.message);
261
261
  }
262
262
  const resourceKey = (0, developer_helpers_js_1.buildMoveContentResourceKey)(args.itemUuids);
263
263
  const proposed = (0, developer_helpers_js_1.buildMoveContentProposal)({
@@ -283,7 +283,7 @@ function registerDuplicateChart(server, contextProvider) {
283
283
  }
284
284
  const sourceBaseline = (0, developer_helpers_js_1.baselineFromResource)(sourceRecordAfter);
285
285
  if ((sourceBaselineBefore === null || sourceBaselineBefore === void 0 ? void 0 : sourceBaselineBefore.updatedAt) !== (sourceBaseline === null || sourceBaseline === void 0 ? void 0 : sourceBaseline.updatedAt)) {
286
- return (0, reader_tool_helpers_js_1.codedErrorResult)('PREVIEW_STALE', `Source chart '${args.sourceChartUuidOrSlug}' changed while reading as-code; re-run preview -> confirm`);
286
+ return (0, content_developer_js_1.developerCodedErrorResult)('PREVIEW_STALE', `Source chart '${args.sourceChartUuidOrSlug}' changed while reading as-code; re-run preview -> confirm`);
287
287
  }
288
288
  const targetBaseline = await (0, developer_helpers_js_1.fetchChartBaselineOptional)({
289
289
  chartUuidOrSlug: args.newSlug,
@@ -550,7 +550,7 @@ function registerMoveContent(server, contextProvider) {
550
550
  isNotFound: api_errors_js_1.isNotFoundError,
551
551
  });
552
552
  if (resolved.kind === 'error') {
553
- return (0, reader_tool_helpers_js_1.codedErrorResult)(resolved.error.code, resolved.error.message);
553
+ return (0, content_developer_js_1.developerCodedErrorResult)(resolved.error.code, resolved.error.message);
554
554
  }
555
555
  const resourceKey = (0, developer_helpers_js_1.buildMoveContentResourceKey)(args.itemUuids);
556
556
  const proposed = (0, developer_helpers_js_1.buildMoveContentProposal)({
@@ -4,8 +4,8 @@
4
4
  */
5
5
  import type { NormalizedQueryResult } from './result-normalizer.js';
6
6
  import type { ContentReaderWarning } from '../../policy/envelope.js';
7
- import type { TextContent } from '../shared.js';
8
- export declare function codedErrorResult(code: string, message: string): TextContent;
7
+ import type { TextContent, ToolErrorExtras } from '../shared.js';
8
+ export declare function codedErrorResult(code: string, message: string, extras?: ToolErrorExtras): TextContent;
9
9
  /** Map ProjectScopeError to a tool error result; rethrow anything else. */
10
10
  export declare function projectScopeErrorResult(err: unknown): TextContent;
11
11
  export declare function warningFromNormalizedMessage(message: string): ContentReaderWarning;
@@ -32,8 +32,8 @@ const BLOCKED_POLICY_CODES = new Set([
32
32
  'PREVIEW_NOT_OWNED',
33
33
  'CHART_SLUG_EXISTS',
34
34
  ]);
35
- function codedErrorResult(code, message) {
36
- const result = (0, shared_js_1.toolErrorResult)(code, message);
35
+ function codedErrorResult(code, message, extras) {
36
+ const result = (0, shared_js_1.toolErrorResult)(code, message, extras);
37
37
  if (BLOCKED_POLICY_CODES.has(code)) {
38
38
  return (0, shared_js_1.withLightdashBlockedMarker)(result);
39
39
  }
@@ -28,6 +28,7 @@ const reader_tool_helpers_js_1 = require("./reader-tool-helpers.js");
28
28
  'QUERY_BUDGET_EXCEEDED',
29
29
  'ROW_LIMIT_EXCEEDED',
30
30
  'CHART_SLUG_EXISTS',
31
+ 'PREVIEW_STALE',
31
32
  ]) {
32
33
  const result = (0, reader_tool_helpers_js_1.codedErrorResult)(code, 'denied');
33
34
  (0, vitest_1.expect)(result.isError).toBe(true);
@@ -35,8 +35,13 @@ export type TextContent = {
35
35
  export type ToolResult = InputRequiredResult | TextContent;
36
36
  /** Builds a tool result with JSON text and matching structuredContent. */
37
37
  export declare function jsonToolResult(data: unknown): TextContent;
38
+ /** Optional additive fields on structured tool errors (RFC progressive-disclosure recovery). */
39
+ export type ToolErrorExtras = {
40
+ recovery?: string;
41
+ playbookUri?: string;
42
+ };
38
43
  /** Tool execution error with structured `{ error: { code, message } }` (not policy-blocked). */
39
- export declare function toolErrorResult(code: string, message: string): TextContent;
44
+ export declare function toolErrorResult(code: string, message: string, extras?: ToolErrorExtras): TextContent;
40
45
  /**
41
46
  * MCP ImageContent + metadata text. structuredContent holds meta only (no base64).
42
47
  * Spec: https://modelcontextprotocol.io/specification/2025-11-25/server/tools
@@ -47,8 +47,18 @@ function jsonToolResult(data) {
47
47
  };
48
48
  }
49
49
  /** Tool execution error with structured `{ error: { code, message } }` (not policy-blocked). */
50
- function toolErrorResult(code, message) {
51
- return Object.assign(Object.assign({}, jsonToolResult({ error: { code, message } })), { isError: true });
50
+ function toolErrorResult(code, message, extras) {
51
+ const error = {
52
+ code,
53
+ message,
54
+ };
55
+ if ((extras === null || extras === void 0 ? void 0 : extras.recovery) !== undefined) {
56
+ error.recovery = extras.recovery;
57
+ }
58
+ if ((extras === null || extras === void 0 ? void 0 : extras.playbookUri) !== undefined) {
59
+ error.playbookUri = extras.playbookUri;
60
+ }
61
+ return Object.assign(Object.assign({}, jsonToolResult({ error })), { isError: true });
52
62
  }
53
63
  /**
54
64
  * MCP ImageContent + metadata text. structuredContent holds meta only (no base64).
@@ -8,6 +8,7 @@ const server_1 = require("@modelcontextprotocol/server");
8
8
  const audit_js_1 = require("../audit/audit.js");
9
9
  const tool_audit_context_js_1 = require("../audit/tool-audit-context.js");
10
10
  const auth_mode_js_1 = require("../auth/auth-mode.js");
11
+ const invoke_origins_js_1 = require("../auth/oauth-broker/invoke-origins.js");
11
12
  const routes_js_1 = require("../auth/oauth-broker/routes.js");
12
13
  const bearer_context_provider_js_1 = require("../auth/providers/bearer-context-provider.js");
13
14
  const env_context_provider_js_1 = require("../auth/providers/env-context-provider.js");
@@ -18,6 +19,7 @@ const shared_key_middleware_js_1 = require("../auth/resource-server/shared-key-m
18
19
  const token_hash_js_1 = require("../auth/token-hash.js");
19
20
  const enabled_profiles_js_1 = require("../config/enabled-profiles.js");
20
21
  const load_mcp_config_js_1 = require("../config/load-mcp-config.js");
22
+ const public_url_js_1 = require("../config/public-url.js");
21
23
  const runtime_js_1 = require("../config/runtime.js");
22
24
  const available_projects_js_1 = require("../governance/available-projects.js");
23
25
  const mcp_post_factory_context_js_1 = require("../governance/mcp-post-factory-context.js");
@@ -35,7 +37,10 @@ function createProcessMcpHttpHandler() {
35
37
  if (!store) {
36
38
  throw new Error('MCP request factory context is missing');
37
39
  }
38
- return (0, server_js_1.createLightdashMcpServer)(store.contextProvider, { profile: store.profile });
40
+ return (0, server_js_1.createLightdashMcpServer)(store.contextProvider, {
41
+ profile: store.profile,
42
+ promptContextPolicy: store.promptContextPolicy,
43
+ });
39
44
  }, { legacy: 'stateless', onerror: reportMcpHttpError });
40
45
  }
41
46
  function listen(server, port, host) {
@@ -168,7 +173,11 @@ async function handleMcpPost(ctx) {
168
173
  }
169
174
  const contextProvider = createContextProviderForRequest(config, req);
170
175
  const auditAuth = getOAuthAuditContext(req);
171
- await (0, mcp_post_factory_context_js_1.runWithMcpPostFactoryAsync)({ contextProvider, profile }, () => (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)(auditAuth, () => nodeHandler(req, res, body)));
176
+ await (0, mcp_post_factory_context_js_1.runWithMcpPostFactoryAsync)({
177
+ contextProvider,
178
+ profile,
179
+ promptContextPolicy: config.promptContextPolicy,
180
+ }, () => (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)(auditAuth, () => nodeHandler(req, res, body)));
172
181
  }
173
182
  async function createStreamableHttpServer(config) {
174
183
  var _a;
@@ -225,7 +234,7 @@ function startStreamableHttpServer(config) {
225
234
  const paths = (0, enabled_profiles_js_1.listEnabledProfilePaths)(httpConfig.enabledProfiles)
226
235
  .map((p) => `${baseUrl}${p}`)
227
236
  .join(', ');
228
- console.error(`Lightdash MCP server listening on ${paths} (auth: ${httpConfig.authMode})`);
237
+ console.error(`Lightdash MCP server listening on ${paths} (auth: ${httpConfig.authMode}; prompt-context=${httpConfig.promptContextPolicy})`);
229
238
  if (httpConfig.authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
230
239
  console.error(`OAuth PRM: ${(0, oauth_protected_resource_js_1.getProtectedResourceMetadataUrl)(httpConfig)}`);
231
240
  console.error(`OAuth callback (register in Lightdash): ${(0, load_mcp_config_js_1.getOAuthCallbackUrl)(httpConfig)}`);
@@ -286,7 +295,7 @@ async function handlePublicHttpPaths(req, res, config, path, oauthBroker) {
286
295
  : undefined;
287
296
  if (prmMcpPath !== undefined) {
288
297
  applyOptionalCorsHeaders(req, res, config, true);
289
- (0, http_response_js_1.sendJson)(res, 200, (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(config, prmMcpPath));
298
+ (0, http_response_js_1.sendJson)(res, 200, (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(config, prmMcpPath, (0, invoke_origins_js_1.resourceOriginForRequest)(req, config.invokeOrigins, (0, public_url_js_1.requirePublicUrl)(config, 'OAuth resource origin'))));
290
299
  return true;
291
300
  }
292
301
  return false;
@@ -66,17 +66,22 @@ function clearMcpEnv() {
66
66
  });
67
67
  (0, vitest_1.describe)('streamable HTTP OAuth metadata', () => {
68
68
  (0, vitest_1.it)('builds protected resource metadata with MCP host as authorization_servers', () => {
69
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PROFILE_PATH);
69
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PROFILE_PATH, 'https://mcp.example.com');
70
70
  (0, vitest_1.expect)(metadata.authorization_servers).toEqual(['https://mcp.example.com']);
71
71
  (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_3.SEMANTIC_LAYER_PROFILE_PATH}`);
72
72
  (0, vitest_1.expect)((0, oauth_protected_resource_js_1.getAuthorizationServerMetadataUrl)(metadata.authorization_servers[0])).toBe('https://mcp.example.com/.well-known/oauth-authorization-server');
73
73
  });
74
+ (0, vitest_1.it)('builds protected resource metadata for an extra invoke origin', () => {
75
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_3.SEMANTIC_LAYER_PROFILE_PATH, 'http://mcp.ilb.internal');
76
+ (0, vitest_1.expect)(metadata.resource).toBe('http://mcp.ilb.internal/semantic-layer/v1/mcp');
77
+ (0, vitest_1.expect)(metadata.authorization_servers).toEqual(['http://mcp.ilb.internal']);
78
+ });
74
79
  (0, vitest_1.it)('builds organization-audit protected resource metadata', () => {
75
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH);
80
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH, 'https://mcp.example.com');
76
81
  (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_2.ORGANIZATION_AUDIT_PROFILE_PATH}`);
77
82
  });
78
83
  (0, vitest_1.it)('builds content-reader protected resource metadata', () => {
79
- const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.CONTENT_READER_PROFILE_PATH);
84
+ const metadata = (0, oauth_protected_resource_js_1.buildOAuthProtectedResourceMetadata)(oauthConfig, index_js_1.CONTENT_READER_PROFILE_PATH, 'https://mcp.example.com');
80
85
  (0, vitest_1.expect)(metadata.resource).toBe(`https://mcp.example.com${index_js_1.CONTENT_READER_PROFILE_PATH}`);
81
86
  });
82
87
  (0, vitest_1.it)('builds WWW-Authenticate challenges with resource_metadata for OAuth clients', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/mcp",
3
- "version": "0.14.0",
3
+ "version": "0.17.0",
4
4
  "description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, and ai-agent-ops profiles.",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -24,8 +24,8 @@
24
24
  "commander": "^15.0.0",
25
25
  "hono": "^4.13.0",
26
26
  "zod": "^4.4.3",
27
- "@lightdash-tools/client": "0.14.0",
28
- "@lightdash-tools/common": "0.14.0"
27
+ "@lightdash-tools/client": "0.17.0",
28
+ "@lightdash-tools/common": "0.17.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@modelcontextprotocol/client": "2.0.0",