@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
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const client_1 = require("@lightdash-tools/client");
3
4
  const vitest_1 = require("vitest");
4
5
  const test_mcp_http_config_js_1 = require("../../config/test-mcp-http-config.js");
5
6
  const index_js_1 = require("../../profiles/organization-audit/v1/index.js");
6
7
  const index_js_2 = require("../../profiles/semantic-layer/v1/index.js");
8
+ const mcp_access_token_js_1 = require("../oauth-broker/mcp-access-token.js");
7
9
  const lightdash_oauth_middleware_js_1 = require("./lightdash-oauth-middleware.js");
8
10
  const lightdash_token_validation_js_1 = require("./lightdash-token-validation.js");
9
11
  const token_validation_error_js_1 = require("./token-validation-error.js");
@@ -11,19 +13,33 @@ vitest_1.vi.mock('./lightdash-token-validation.js', () => ({
11
13
  validateLightdashAccessToken: vitest_1.vi.fn(),
12
14
  }));
13
15
  const baseConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
16
+ oauthClientId: 'ld-client',
17
+ oauthClientSecret: new client_1.SecretString('test-lightdash-confidential-client-secret'),
14
18
  requiredScopes: [],
15
19
  });
16
- function jwtWithScope(scope) {
17
- const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
18
- const payload = Buffer.from(JSON.stringify({ scope })).toString('base64url');
19
- return `${header}.${payload}.signature`;
20
- }
21
20
  function createRequest(authorization) {
22
21
  return {
23
22
  headers: authorization ? { authorization } : {},
24
23
  };
25
24
  }
25
+ function resourceFor(path) {
26
+ return `https://mcp.example.com${path}`;
27
+ }
28
+ function mcpToken(options = {}) {
29
+ var _a, _b, _c;
30
+ const path = (_a = options.path) !== null && _a !== void 0 ? _a : index_js_2.SEMANTIC_LAYER_PROFILE_PATH;
31
+ return (0, mcp_access_token_js_1.mintMcpAccessToken)(baseConfig, {
32
+ lightdashAccessToken: (_b = options.lightdashAccessToken) !== null && _b !== void 0 ? _b : 'ld-upstream-token',
33
+ clientId: 'mcp-client-1',
34
+ resource: resourceFor(path),
35
+ scope: options.scope,
36
+ expiresAtMs: (_c = options.expiresAtMs) !== null && _c !== void 0 ? _c : Date.now() + 60000,
37
+ }).accessToken;
38
+ }
26
39
  (0, vitest_1.describe)('authenticateLightdashOAuth', () => {
40
+ (0, vitest_1.beforeEach)(() => {
41
+ vitest_1.vi.clearAllMocks();
42
+ });
27
43
  (0, vitest_1.it)('returns 401 with WWW-Authenticate resource_metadata when token is missing', async () => {
28
44
  const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
29
45
  (0, vitest_1.expect)(result.ok).toBe(false);
@@ -46,22 +62,43 @@ function createRequest(authorization) {
46
62
  (0, vitest_1.expect)(result.wwwAuthenticate).toContain('https://mcp.example.com/.well-known/oauth-protected-resource/organization-audit/v1/mcp');
47
63
  (0, vitest_1.expect)(result.wwwAuthenticate).not.toContain('semantic-layer/v1/mcp');
48
64
  });
49
- (0, vitest_1.it)('returns 401 without echoing the bearer token when validation fails', async () => {
65
+ (0, vitest_1.it)('rejects a raw downstream Lightdash bearer before calling Lightdash', async () => {
66
+ const token = 'ld-upstream-token';
67
+ const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
68
+ (0, vitest_1.expect)(result.ok).toBe(false);
69
+ if (result.ok)
70
+ return;
71
+ (0, vitest_1.expect)(result.status).toBe(401);
72
+ (0, vitest_1.expect)(result.body.error).toBe('invalid_token');
73
+ (0, vitest_1.expect)(JSON.stringify(result.body)).not.toContain(token);
74
+ (0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).not.toHaveBeenCalled();
75
+ });
76
+ (0, vitest_1.it)('rejects a valid broker token at a different profile resource', async () => {
77
+ const token = mcpToken({ path: index_js_1.ORGANIZATION_AUDIT_PROFILE_PATH });
78
+ const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
79
+ (0, vitest_1.expect)(result.ok).toBe(false);
80
+ if (result.ok)
81
+ return;
82
+ (0, vitest_1.expect)(result.status).toBe(401);
83
+ (0, vitest_1.expect)(result.body.error_description).toContain('wrong-audience');
84
+ (0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).not.toHaveBeenCalled();
85
+ });
86
+ (0, vitest_1.it)('returns 401 without echoing the MCP bearer when downstream validation fails', async () => {
50
87
  vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockRejectedValue(new token_validation_error_js_1.TokenValidationError('invalid_token', 'Invalid or expired Lightdash access token'));
51
- const token = 'secret-oauth-token';
88
+ const token = mcpToken();
52
89
  const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
53
90
  (0, vitest_1.expect)(result.ok).toBe(false);
54
91
  if (result.ok)
55
92
  return;
56
93
  (0, vitest_1.expect)(result.status).toBe(401);
57
94
  (0, vitest_1.expect)(result.body.error).toBe('invalid_token');
58
- (0, vitest_1.expect)(result.body.error_description).toBe('Invalid or expired Lightdash access token');
59
95
  (0, vitest_1.expect)(JSON.stringify(result.body)).not.toContain(token);
60
96
  (0, vitest_1.expect)(result.wwwAuthenticate).toContain('error="invalid_token"');
97
+ (0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).toHaveBeenCalledWith(baseConfig, 'ld-upstream-token');
61
98
  });
62
99
  (0, vitest_1.it)('returns 503 when Lightdash upstream is unavailable', async () => {
63
100
  vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockRejectedValue(new token_validation_error_js_1.TokenValidationError('upstream_unavailable', 'Lightdash is temporarily unavailable'));
64
- const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest('Bearer token'), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
101
+ const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
65
102
  (0, vitest_1.expect)(result.ok).toBe(false);
66
103
  if (result.ok)
67
104
  return;
@@ -74,78 +111,42 @@ function createRequest(authorization) {
74
111
  });
75
112
  (0, vitest_1.it)('returns 503 with Retry-After when upstream is rate limited', async () => {
76
113
  vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockRejectedValue(new token_validation_error_js_1.TokenValidationError('upstream_unavailable', 'Lightdash is temporarily unavailable', 60));
77
- const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest('Bearer token'), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
114
+ const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
78
115
  (0, vitest_1.expect)(result.ok).toBe(false);
79
116
  if (result.ok)
80
117
  return;
81
118
  (0, vitest_1.expect)(result.status).toBe(503);
82
119
  (0, vitest_1.expect)(result.headers).toEqual({ 'Retry-After': '60' });
83
120
  });
84
- (0, vitest_1.it)('returns user context when token validation succeeds', async () => {
121
+ (0, vitest_1.it)('returns downstream user context only after broker-token validation succeeds', async () => {
85
122
  vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
86
123
  userUuid: 'user-uuid-1',
87
124
  email: 'user@example.com',
88
125
  });
89
- const token = jwtWithScope('mcp:read mcp:write');
126
+ const token = mcpToken({ scope: 'mcp:read mcp:write' });
90
127
  const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
91
128
  (0, vitest_1.expect)(result).toEqual({
92
129
  ok: true,
93
- accessToken: token,
130
+ accessToken: 'ld-upstream-token',
94
131
  user: { userUuid: 'user-uuid-1', email: 'user@example.com' },
95
132
  scopes: ['mcp:read', 'mcp:write'],
96
133
  });
97
- (0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).toHaveBeenCalledWith(baseConfig, token);
134
+ (0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).toHaveBeenCalledWith(baseConfig, 'ld-upstream-token');
98
135
  });
99
- (0, vitest_1.it)('accepts opaque tokens when endpoint scope requirements are unset', async () => {
136
+ (0, vitest_1.it)('accepts an MCP token without scopes when endpoint scope requirements are unset', async () => {
100
137
  vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
101
138
  userUuid: 'user-uuid-1',
102
139
  email: 'user@example.com',
103
140
  });
104
- const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest('Bearer opaque-token'), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
105
- (0, vitest_1.expect)(result).toEqual({
106
- ok: true,
107
- accessToken: 'opaque-token',
108
- user: { userUuid: 'user-uuid-1', email: 'user@example.com' },
109
- scopes: undefined,
110
- });
111
- });
112
- (0, vitest_1.it)('accepts JWTs without scope claims when endpoint scope requirements are unset', async () => {
113
- vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
114
- userUuid: 'user-uuid-1',
115
- email: 'user@example.com',
116
- });
117
- const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
118
- const payload = Buffer.from(JSON.stringify({ sub: 'user-uuid-1' })).toString('base64url');
119
- const token = `${header}.${payload}.signature`;
120
- const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
141
+ const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
121
142
  (0, vitest_1.expect)(result.ok).toBe(true);
122
143
  if (!result.ok)
123
144
  return;
124
145
  (0, vitest_1.expect)(result.scopes).toBeUndefined();
125
146
  });
126
- (0, vitest_1.it)('returns 403 insufficient_scope when required endpoint scopes are configured and missing', async () => {
127
- vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
128
- userUuid: 'user-uuid-1',
129
- email: 'user@example.com',
130
- });
131
- const scopedConfig = Object.assign(Object.assign({}, baseConfig), { requiredScopes: ['mcp:read'] });
132
- const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest('Bearer opaque-token'), scopedConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
133
- (0, vitest_1.expect)(result.ok).toBe(false);
134
- if (result.ok)
135
- return;
136
- (0, vitest_1.expect)(result.status).toBe(403);
137
- (0, vitest_1.expect)(result.body.error).toBe('insufficient_scope');
138
- (0, vitest_1.expect)(result.wwwAuthenticate).toContain('scope="mcp:read"');
139
- });
140
- (0, vitest_1.it)('returns 403 insufficient_scope when required scopes are missing from token claims', async () => {
141
- vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
142
- userUuid: 'user-uuid-1',
143
- email: 'user@example.com',
144
- });
145
- const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
146
- const payload = Buffer.from(JSON.stringify({ scope: 'mcp:write' })).toString('base64url');
147
- const token = `${header}.${payload}.signature`;
147
+ (0, vitest_1.it)('returns 403 insufficient_scope before calling Lightdash when MCP scopes are missing', async () => {
148
148
  const scopedConfig = Object.assign(Object.assign({}, baseConfig), { requiredScopes: ['mcp:read'] });
149
+ const token = mcpToken({ scope: 'mcp:write' });
149
150
  const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), scopedConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
150
151
  (0, vitest_1.expect)(result.ok).toBe(false);
151
152
  if (result.ok)
@@ -153,18 +154,19 @@ function createRequest(authorization) {
153
154
  (0, vitest_1.expect)(result.status).toBe(403);
154
155
  (0, vitest_1.expect)(result.body.error).toBe('insufficient_scope');
155
156
  (0, vitest_1.expect)(result.wwwAuthenticate).toContain('error="insufficient_scope"');
157
+ (0, vitest_1.expect)(result.wwwAuthenticate).toContain('scope="mcp:read"');
158
+ (0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).not.toHaveBeenCalled();
156
159
  });
157
160
  (0, vitest_1.it)('accepts lowercase bearer scheme prefix', async () => {
158
161
  vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
159
162
  userUuid: 'user-uuid-1',
160
163
  email: 'user@example.com',
161
164
  });
162
- const token = jwtWithScope('mcp:read mcp:write');
163
- const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
165
+ const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
164
166
  (0, vitest_1.expect)(result.ok).toBe(true);
165
167
  if (!result.ok)
166
168
  return;
167
- (0, vitest_1.expect)(result.accessToken).toBe(token);
169
+ (0, vitest_1.expect)(result.accessToken).toBe('ld-upstream-token');
168
170
  });
169
171
  });
170
172
  (0, vitest_1.describe)('writeOAuthAuthFailure', () => {
@@ -17,8 +17,8 @@ export declare function getProtectedResourceMetadataUrl(config: McpHttpConfig):
17
17
  export declare function getProtectedResourceMetadataPathUrl(config: McpHttpConfig, mcpPath: string): string;
18
18
  /**
19
19
  * Resolves the profile MCP path for a PRM well-known request.
20
- * Root PRM maps to the default profile (`config.mcpPath`); path-specific PRM
21
- * is served only for shipped profile paths.
20
+ * Root PRM maps to `config.mcpPath`; path-specific PRM is served only for
21
+ * enabled shipped profile paths (ADR-0024).
22
22
  */
23
23
  export declare function resolveProtectedResourceMcpPath(path: string, config: McpHttpConfig): string | undefined;
24
24
  /** Well-known OAuth Authorization Server Metadata URL for an AS origin. */
@@ -6,6 +6,7 @@ exports.getProtectedResourceMetadataUrl = getProtectedResourceMetadataUrl;
6
6
  exports.getProtectedResourceMetadataPathUrl = getProtectedResourceMetadataPathUrl;
7
7
  exports.resolveProtectedResourceMcpPath = resolveProtectedResourceMcpPath;
8
8
  exports.getAuthorizationServerMetadataUrl = getAuthorizationServerMetadataUrl;
9
+ const enabled_profiles_js_1 = require("../../config/enabled-profiles.js");
9
10
  const env_js_1 = require("../../config/env.js");
10
11
  const normalize_url_js_1 = require("../../config/normalize-url.js");
11
12
  const public_url_js_1 = require("../../config/public-url.js");
@@ -22,8 +23,8 @@ function buildOAuthProtectedResourceMetadata(config, mcpPath) {
22
23
  const path = (0, normalize_url_js_1.normalizeMcpPath)(mcpPath);
23
24
  // Broker mode: authorization_servers is the MCP host (PUBLIC_URL). Clients discover
24
25
  // AS metadata at {PUBLIC_URL}/.well-known/oauth-authorization-server and never need
25
- // the Lightdash client secret. Identity validation remains GET /api/v1/user until
26
- // upstream tokens are resource-bound.
26
+ // the Lightdash client secret. The broker issues its own access token bound to this
27
+ // exact resource; the downstream Lightdash credential remains a separate OAuth leg.
27
28
  return {
28
29
  resource: `${publicUrl}${path}`,
29
30
  authorization_servers: [publicUrl],
@@ -42,14 +43,10 @@ function getProtectedResourceMetadataPathUrl(config, mcpPath) {
42
43
  }
43
44
  /**
44
45
  * Resolves the profile MCP path for a PRM well-known request.
45
- * Root PRM maps to the default profile (`config.mcpPath`); path-specific PRM
46
- * is served only for shipped profile paths.
46
+ * Root PRM maps to `config.mcpPath`; path-specific PRM is served only for
47
+ * enabled shipped profile paths (ADR-0024).
47
48
  */
48
49
  function resolveProtectedResourceMcpPath(path, config) {
49
- var _a;
50
- if (!path.startsWith(exports.OAUTH_PROTECTED_RESOURCE_ROOT)) {
51
- return undefined;
52
- }
53
50
  if (path === exports.OAUTH_PROTECTED_RESOURCE_ROOT) {
54
51
  return config.mcpPath;
55
52
  }
@@ -58,7 +55,11 @@ function resolveProtectedResourceMcpPath(path, config) {
58
55
  return undefined;
59
56
  }
60
57
  const resourcePath = `/${path.slice(prefix.length)}`;
61
- return (_a = (0, index_js_1.getProfileByPath)(resourcePath)) === null || _a === void 0 ? void 0 : _a.path;
58
+ const profile = (0, index_js_1.getProfileByPath)(resourcePath);
59
+ if (!profile || !(0, enabled_profiles_js_1.isProfileEnabled)(config.enabledProfiles, profile.id)) {
60
+ return undefined;
61
+ }
62
+ return profile.path;
62
63
  }
63
64
  /** Well-known OAuth Authorization Server Metadata URL for an AS origin. */
64
65
  function getAuthorizationServerMetadataUrl(authorizationServerOrigin) {
package/dist/bin.js CHANGED
@@ -37,18 +37,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  const common_1 = require("@lightdash-tools/common");
38
38
  const commander_1 = require("commander");
39
39
  const cli_help_js_1 = require("./cli-help.js");
40
+ const env_js_1 = require("./config/env.js");
41
+ const prompt_context_policy_js_1 = require("./config/prompt-context-policy.js");
40
42
  const index_js_1 = require("./profiles/index.js");
41
43
  const version_js_1 = require("./server/version.js");
42
44
  const program = new commander_1.Command();
43
- function runStdio(profileId) {
45
+ function resolvePolicyOrExit(cli) {
46
+ try {
47
+ return (0, prompt_context_policy_js_1.resolvePromptContextPolicy)({
48
+ cli,
49
+ env: process.env,
50
+ });
51
+ }
52
+ catch (err) {
53
+ console.error(err instanceof Error ? err.message : err);
54
+ process.exitCode = 1;
55
+ return undefined;
56
+ }
57
+ }
58
+ function runStdio(profileId, promptContext) {
59
+ const promptContextPolicy = resolvePolicyOrExit(promptContext);
60
+ if (!promptContextPolicy)
61
+ return;
44
62
  void Promise.resolve().then(() => __importStar(require('./index.js'))).then((m) => {
45
- m.startStdio(profileId);
63
+ m.startStdio(profileId, { promptContextPolicy });
46
64
  });
47
65
  }
48
- function runHttp() {
49
- void Promise.resolve().then(() => __importStar(require('./http.js')));
66
+ function runHttp(promptContext) {
67
+ const policy = resolvePolicyOrExit(promptContext);
68
+ if (!policy)
69
+ return;
70
+ void Promise.resolve().then(() => __importStar(require('./http.js'))).then((m) => {
71
+ void m.startHttp({ promptContextPolicy: policy });
72
+ });
50
73
  }
51
74
  const profileList = common_1.PROFILE_IDS.join(', ');
75
+ const promptContextHelp = `Prompt context policy (${prompt_context_policy_js_1.PROMPT_CONTEXT_POLICIES.join('|')}; env: ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT})`;
52
76
  program
53
77
  .name('lightdash-mcp')
54
78
  .description(`MCP server for Lightdash (${profileList}). Use \`stdio --profile <id>\` or \`http\`.`)
@@ -65,6 +89,7 @@ program
65
89
  .command('stdio')
66
90
  .description('Run MCP server on stdio')
67
91
  .requiredOption('--profile <id>', `Profile id (${profileList})`)
92
+ .option('--prompt-context <policy>', promptContextHelp)
68
93
  .addHelpText('after', cli_help_js_1.formatProfilesHelp)
69
94
  .action((opts) => {
70
95
  const id = (0, index_js_1.parseProfileId)(opts.profile);
@@ -73,13 +98,14 @@ program
73
98
  process.exitCode = 1;
74
99
  return;
75
100
  }
76
- runStdio(id);
101
+ runStdio(id, opts.promptContext);
77
102
  });
78
103
  program
79
104
  .command('http')
80
- .description('Run MCP server over Streamable HTTP (all fixed profile paths)')
105
+ .description('Run MCP server over Streamable HTTP (fixed profile paths)')
106
+ .option('--prompt-context <policy>', promptContextHelp)
81
107
  .addHelpText('after', cli_help_js_1.formatProfilesHelp)
82
- .action(() => {
83
- runHttp();
108
+ .action((opts) => {
109
+ runHttp(opts.promptContext);
84
110
  });
85
111
  program.parse(process.argv);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * HTTP mount allowlist for shipped MCP profiles (ADR-0024).
3
+ *
4
+ * Canonical: `LIGHTDASH_TOOLS_MCP_PROFILES`.
5
+ * Unset/empty → unrestricted (all shipped paths). Non-empty → hard ceiling.
6
+ * Unknown ids / empty CSV segments fail closed. Stdio ignores this env.
7
+ */
8
+ import { type ProfileId } from '@lightdash-tools/common';
9
+ export type EnabledProfilesPolicy = {
10
+ restricted: false;
11
+ } | {
12
+ restricted: true;
13
+ ids: ReadonlySet<ProfileId>;
14
+ };
15
+ export declare const UNRESTRICTED_ENABLED_PROFILES: EnabledProfilesPolicy;
16
+ export declare function parseEnabledProfiles(raw: string | undefined): EnabledProfilesPolicy;
17
+ export declare function isProfileEnabled(policy: EnabledProfilesPolicy, id: ProfileId): boolean;
18
+ /** Preview/destructive HMAC key is required when write profiles are mounted. */
19
+ export declare function requiresSignedStateKey(policy: EnabledProfilesPolicy): boolean;
20
+ /** Enabled HTTP mount paths in `PROFILE_IDS` order. */
21
+ export declare function listEnabledProfilePaths(policy: EnabledProfilesPolicy): string[];
22
+ /** Root PRM / `config.mcpPath` anchor: default profile, else first enabled `PROFILE_IDS` id. */
23
+ export declare function resolveRootMcpPath(policy: EnabledProfilesPolicy): string;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * HTTP mount allowlist for shipped MCP profiles (ADR-0024).
4
+ *
5
+ * Canonical: `LIGHTDASH_TOOLS_MCP_PROFILES`.
6
+ * Unset/empty → unrestricted (all shipped paths). Non-empty → hard ceiling.
7
+ * Unknown ids / empty CSV segments fail closed. Stdio ignores this env.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.UNRESTRICTED_ENABLED_PROFILES = void 0;
11
+ exports.parseEnabledProfiles = parseEnabledProfiles;
12
+ exports.isProfileEnabled = isProfileEnabled;
13
+ exports.requiresSignedStateKey = requiresSignedStateKey;
14
+ exports.listEnabledProfilePaths = listEnabledProfilePaths;
15
+ exports.resolveRootMcpPath = resolveRootMcpPath;
16
+ const common_1 = require("@lightdash-tools/common");
17
+ const index_js_1 = require("../profiles/index.js");
18
+ const env_js_1 = require("./env.js");
19
+ exports.UNRESTRICTED_ENABLED_PROFILES = { restricted: false };
20
+ function parseEnabledProfiles(raw) {
21
+ if (raw === undefined || raw.trim() === '') {
22
+ return exports.UNRESTRICTED_ENABLED_PROFILES;
23
+ }
24
+ const parts = raw.split(',').map((s) => s.trim());
25
+ if (parts.some((part) => part === '')) {
26
+ throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES} must be a non-empty comma-separated list of profile ids (empty segments are not allowed)`);
27
+ }
28
+ const ids = new Set();
29
+ for (const part of parts) {
30
+ const id = (0, index_js_1.parseProfileId)(part);
31
+ if (!id) {
32
+ throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES} contains unknown profile '${part}'. Expected one of: ${common_1.PROFILE_IDS.join(', ')}`);
33
+ }
34
+ ids.add(id);
35
+ }
36
+ return { restricted: true, ids };
37
+ }
38
+ function isProfileEnabled(policy, id) {
39
+ return !policy.restricted || policy.ids.has(id);
40
+ }
41
+ /** Preview/destructive HMAC key is required when write profiles are mounted. */
42
+ function requiresSignedStateKey(policy) {
43
+ return (!policy.restricted ||
44
+ policy.ids.has('content-developer') ||
45
+ policy.ids.has('content-governance'));
46
+ }
47
+ /** Enabled HTTP mount paths in `PROFILE_IDS` order. */
48
+ function listEnabledProfilePaths(policy) {
49
+ return common_1.PROFILE_IDS.filter((id) => isProfileEnabled(policy, id)).map((id) => (0, index_js_1.getProfile)(id).path);
50
+ }
51
+ /** Root PRM / `config.mcpPath` anchor: default profile, else first enabled `PROFILE_IDS` id. */
52
+ function resolveRootMcpPath(policy) {
53
+ if (!policy.restricted || policy.ids.has(index_js_1.DEFAULT_PROFILE_ID)) {
54
+ return (0, index_js_1.getDefaultProfile)().path;
55
+ }
56
+ return listEnabledProfilePaths(policy)[0];
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const common_1 = require("@lightdash-tools/common");
4
+ const vitest_1 = require("vitest");
5
+ const index_js_1 = require("../profiles/index.js");
6
+ const enabled_profiles_js_1 = require("./enabled-profiles.js");
7
+ const env_js_1 = require("./env.js");
8
+ (0, vitest_1.describe)('parseEnabledProfiles', () => {
9
+ (0, vitest_1.it)('returns unrestricted when unset or empty', () => {
10
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.parseEnabledProfiles)(undefined)).toEqual(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES);
11
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.parseEnabledProfiles)('')).toEqual(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES);
12
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.parseEnabledProfiles)(' ')).toEqual(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES);
13
+ });
14
+ (0, vitest_1.it)('parses comma-separated ids with trim and dedupe', () => {
15
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.parseEnabledProfiles)(' content-reader , content-developer, content-reader ')).toEqual({
16
+ restricted: true,
17
+ ids: new Set(['content-reader', 'content-developer']),
18
+ });
19
+ });
20
+ (0, vitest_1.it)('rejects empty CSV segments', () => {
21
+ (0, vitest_1.expect)(() => (0, enabled_profiles_js_1.parseEnabledProfiles)(',,,')).toThrow(/empty segments/);
22
+ (0, vitest_1.expect)(() => (0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader,')).toThrow(/empty segments/);
23
+ });
24
+ (0, vitest_1.it)('rejects unknown ids and free-form paths', () => {
25
+ (0, vitest_1.expect)(() => (0, enabled_profiles_js_1.parseEnabledProfiles)('not-a-profile')).toThrow(/unknown profile/);
26
+ (0, vitest_1.expect)(() => (0, enabled_profiles_js_1.parseEnabledProfiles)('/content-reader/v1/mcp')).toThrow(/unknown profile/);
27
+ (0, vitest_1.expect)(() => (0, enabled_profiles_js_1.parseEnabledProfiles)('not-a-profile')).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES);
28
+ });
29
+ });
30
+ (0, vitest_1.describe)('isProfileEnabled / requiresSignedStateKey / resolveRootMcpPath', () => {
31
+ (0, vitest_1.it)('treats unrestricted as all profiles enabled', () => {
32
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.isProfileEnabled)(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES, 'content-governance')).toBe(true);
33
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.isProfileEnabled)(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES, 'data-analyst')).toBe(true);
34
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.requiresSignedStateKey)(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES)).toBe(true);
35
+ });
36
+ (0, vitest_1.it)('restricts to listed ids', () => {
37
+ const policy = (0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader');
38
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.isProfileEnabled)(policy, 'content-reader')).toBe(true);
39
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.isProfileEnabled)(policy, 'semantic-layer')).toBe(false);
40
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.requiresSignedStateKey)(policy)).toBe(false);
41
+ });
42
+ (0, vitest_1.it)('requires signing key when developer or governance is enabled', () => {
43
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.requiresSignedStateKey)((0, enabled_profiles_js_1.parseEnabledProfiles)('content-developer'))).toBe(true);
44
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.requiresSignedStateKey)((0, enabled_profiles_js_1.parseEnabledProfiles)('content-governance'))).toBe(true);
45
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.requiresSignedStateKey)((0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader,content-developer'))).toBe(true);
46
+ });
47
+ (0, vitest_1.it)('uses semantic-layer mcpPath when unrestricted or when that id is listed', () => {
48
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.resolveRootMcpPath)(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES)).toBe(index_js_1.SEMANTIC_LAYER_PROFILE_PATH);
49
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.resolveRootMcpPath)((0, enabled_profiles_js_1.parseEnabledProfiles)('semantic-layer,content-reader'))).toBe(index_js_1.SEMANTIC_LAYER_PROFILE_PATH);
50
+ });
51
+ (0, vitest_1.it)('uses first PROFILE_IDS-enabled path when semantic-layer is omitted', () => {
52
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.resolveRootMcpPath)((0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader'))).toBe(index_js_1.CONTENT_READER_PROFILE_PATH);
53
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.resolveRootMcpPath)((0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader,content-developer'))).toBe(index_js_1.CONTENT_DEVELOPER_PROFILE_PATH);
54
+ (0, vitest_1.expect)(common_1.PROFILE_IDS.indexOf('content-developer')).toBeLessThan(common_1.PROFILE_IDS.indexOf('content-reader'));
55
+ });
56
+ (0, vitest_1.it)('lists shipped paths when unrestricted and only enabled paths when restricted', () => {
57
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.listEnabledProfilePaths)(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES)).toEqual(common_1.PROFILE_IDS.map((id) => (0, index_js_1.getProfile)(id).path));
58
+ (0, vitest_1.expect)((0, enabled_profiles_js_1.listEnabledProfilePaths)((0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader'))).toEqual([
59
+ index_js_1.CONTENT_READER_PROFILE_PATH,
60
+ ]);
61
+ });
62
+ });
@@ -9,6 +9,13 @@ export declare const ENV_PLATFORM_PORT = "PORT";
9
9
  export declare const ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = "LIGHTDASH_TOOLS_MCP_PUBLIC_URL";
10
10
  /** Rejected at config load — MCP path is profile-owned (see profiles/). */
11
11
  export declare const ENV_LIGHTDASH_TOOLS_MCP_PATH = "LIGHTDASH_TOOLS_MCP_PATH";
12
+ /** Optional HTTP mount allowlist (comma-separated ProfileIds). Unset/empty → all. Stdio ignores. */
13
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_PROFILES = "LIGHTDASH_TOOLS_MCP_PROFILES";
14
+ /**
15
+ * Prompt playbook embedding policy: `compact` | `compatible` | `embedded`.
16
+ * Unset → package default (`compact`). Stdio `--prompt-context` overrides.
17
+ */
18
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = "LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT";
12
19
  /** Rejected — auth mode is inferred from credentials (ADR-0007). */
13
20
  export declare const ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = "LIGHTDASH_TOOLS_MCP_AUTH_MODE";
14
21
  export declare const ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = "LIGHTDASH_TOOLS_MCP_SHARED_KEY";
@@ -4,7 +4,7 @@
4
4
  * Legacy `MCP_*` aliases are resolved in load-mcp-config.ts.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.OAUTH_AUTHORIZATION_SERVER_METADATA_PATH = exports.OAUTH_REGISTER_PATH = exports.OAUTH_TOKEN_PATH = exports.OAUTH_AUTHORIZE_PATH = exports.OAUTH_CALLBACK_PATH = exports.ENV_MCP_MAX_BODY_BYTES = exports.ENV_MCP_ALLOWED_ORIGINS = exports.ENV_MCP_API_KEY = exports.ENV_MCP_AUTH_ENABLED = exports.ENV_MCP_PUBLIC_URL = exports.ENV_MCP_SERVER_PORT = exports.ENV_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_GRANT_ALL_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_SKIP_TOKEN_VALIDATION = exports.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV = exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_PLATFORM_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = void 0;
7
+ exports.OAUTH_AUTHORIZATION_SERVER_METADATA_PATH = exports.OAUTH_REGISTER_PATH = exports.OAUTH_TOKEN_PATH = exports.OAUTH_AUTHORIZE_PATH = exports.OAUTH_CALLBACK_PATH = exports.ENV_MCP_MAX_BODY_BYTES = exports.ENV_MCP_ALLOWED_ORIGINS = exports.ENV_MCP_API_KEY = exports.ENV_MCP_AUTH_ENABLED = exports.ENV_MCP_PUBLIC_URL = exports.ENV_MCP_SERVER_PORT = exports.ENV_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_GRANT_ALL_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_SKIP_TOKEN_VALIDATION = exports.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV = exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = exports.ENV_LIGHTDASH_TOOLS_MCP_PROFILES = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_PLATFORM_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = void 0;
8
8
  exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = 'LIGHTDASH_TOOLS_MCP_HTTP_HOST';
9
9
  exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = 'LIGHTDASH_TOOLS_MCP_HTTP_PORT';
10
10
  /** Platform listen port (Cloud Run / many PaaS). Used only when dedicated MCP port env is unset. */
@@ -12,6 +12,13 @@ exports.ENV_PLATFORM_PORT = 'PORT';
12
12
  exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = 'LIGHTDASH_TOOLS_MCP_PUBLIC_URL';
13
13
  /** Rejected at config load — MCP path is profile-owned (see profiles/). */
14
14
  exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = 'LIGHTDASH_TOOLS_MCP_PATH';
15
+ /** Optional HTTP mount allowlist (comma-separated ProfileIds). Unset/empty → all. Stdio ignores. */
16
+ exports.ENV_LIGHTDASH_TOOLS_MCP_PROFILES = 'LIGHTDASH_TOOLS_MCP_PROFILES';
17
+ /**
18
+ * Prompt playbook embedding policy: `compact` | `compatible` | `embedded`.
19
+ * Unset → package default (`compact`). Stdio `--prompt-context` overrides.
20
+ */
21
+ exports.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = 'LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT';
15
22
  /** Rejected — auth mode is inferred from credentials (ADR-0007). */
16
23
  exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = 'LIGHTDASH_TOOLS_MCP_AUTH_MODE';
17
24
  exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = 'LIGHTDASH_TOOLS_MCP_SHARED_KEY';
@@ -1,4 +1,6 @@
1
1
  import { SecretString } from '@lightdash-tools/client';
2
+ import { type EnabledProfilesPolicy } from './enabled-profiles.js';
3
+ import { type PromptContextPolicy } from './prompt-context-policy.js';
2
4
  import type { McpAuthMode } from '../auth/auth-mode.js';
3
5
  export interface McpHttpConfig {
4
6
  lightdashUrl: string;
@@ -7,6 +9,10 @@ export interface McpHttpConfig {
7
9
  port: number;
8
10
  publicUrl?: string;
9
11
  mcpPath: string;
12
+ /** HTTP mount allowlist. Unrestricted when LIGHTDASH_TOOLS_MCP_PROFILES is unset. */
13
+ enabledProfiles: EnabledProfilesPolicy;
14
+ /** Progressive-disclosure prompt embedding policy (default compact). */
15
+ promptContextPolicy: PromptContextPolicy;
10
16
  authMode: McpAuthMode;
11
17
  sharedKey?: SecretString;
12
18
  /** Server-held Lightdash OAuth application client id (broker mode). */
@@ -21,6 +27,14 @@ export interface McpHttpConfig {
21
27
  tokenValidationCacheTtlMs: number;
22
28
  }
23
29
  export declare function emitMcpHttpSecurityWarnings(config: McpHttpConfig): void;
24
- export declare function loadMcpHttpConfig(env?: NodeJS.ProcessEnv): McpHttpConfig;
30
+ /**
31
+ * Load Streamable HTTP MCP config from env.
32
+ * When `options.promptContextPolicy` is set (CLI path), that value wins and
33
+ * `LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT` is not re-resolved — so invalid env
34
+ * cannot fail a start that already resolved a valid CLI policy.
35
+ */
36
+ export declare function loadMcpHttpConfig(env?: NodeJS.ProcessEnv, options?: {
37
+ promptContextPolicy?: PromptContextPolicy;
38
+ }): McpHttpConfig;
25
39
  export declare function requiresLightdashApiKey(authMode: McpAuthMode): boolean;
26
40
  export declare function getOAuthCallbackUrl(config: McpHttpConfig): string;