@lightdash-tools/mcp 0.13.1 → 0.14.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 (48) hide show
  1. package/README.md +56 -11
  2. package/dist/auth/request-state-key.d.ts +1 -1
  3. package/dist/auth/request-state-key.js +1 -1
  4. package/dist/auth/resource-server/oauth-protected-resource.d.ts +2 -2
  5. package/dist/auth/resource-server/oauth-protected-resource.js +8 -7
  6. package/dist/bin.js +1 -1
  7. package/dist/config/enabled-profiles.d.ts +23 -0
  8. package/dist/config/enabled-profiles.js +57 -0
  9. package/dist/config/enabled-profiles.test.d.ts +1 -0
  10. package/dist/config/enabled-profiles.test.js +62 -0
  11. package/dist/config/env.d.ts +2 -0
  12. package/dist/config/env.js +3 -1
  13. package/dist/config/load-mcp-config.d.ts +3 -0
  14. package/dist/config/load-mcp-config.js +20 -23
  15. package/dist/config/load-mcp-config.test.js +41 -0
  16. package/dist/config/obsolete-env.js +2 -8
  17. package/dist/config/read-env.d.ts +4 -0
  18. package/dist/config/read-env.js +13 -0
  19. package/dist/config/test-mcp-http-config.js +4 -1
  20. package/dist/http.integration.test.js +47 -24
  21. package/dist/index.integration.test.js +3 -12
  22. package/dist/profiles/content-developer/v1/prompts.js +3 -2
  23. package/dist/profiles/content-developer/v1/prompts.test.js +8 -0
  24. package/dist/profiles/content-developer/v1/resources/playbooks/chart-types.md +3 -0
  25. package/dist/profiles/content-developer/v1/resources/playbooks/core.md +18 -16
  26. package/dist/profiles/content-developer/v1/resources/playbooks/dashboard-design.md +11 -1
  27. package/dist/profiles/content-developer/v1/resources/playbooks/dashboards.md +2 -2
  28. package/dist/profiles/content-developer/v1/resources/playbooks/index.md +8 -7
  29. package/dist/profiles/content-developer/v1/resources/playbooks/table-calculations.md +131 -0
  30. package/dist/profiles/content-developer/v1/resources/playbooks.d.ts +1 -1
  31. package/dist/profiles/content-developer/v1/resources/playbooks.js +8 -1
  32. package/dist/profiles/content-reader/v1/index.js +1 -0
  33. package/dist/profiles/content-reader/v1/prompts.js +10 -9
  34. package/dist/profiles/content-reader/v1/resources/playbooks/compare.md +1 -1
  35. package/dist/profiles/content-reader/v1/resources/playbooks/core.md +12 -11
  36. package/dist/profiles/content-reader/v1/resources/playbooks/discover.md +12 -3
  37. package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +3 -2
  38. package/dist/profiles/index.d.ts +2 -1
  39. package/dist/profiles/index.js +2 -1
  40. package/dist/profiles/index.test.js +2 -1
  41. package/dist/stdio.process.test.js +2 -1
  42. package/dist/tools/project/reader-content.d.ts +4 -0
  43. package/dist/tools/project/reader-content.js +61 -6
  44. package/dist/tools/project/reader-content.test.d.ts +4 -0
  45. package/dist/tools/project/reader-content.test.js +64 -0
  46. package/dist/transports/streamable-http.js +6 -3
  47. package/dist/transports/streamable-http.test.js +16 -0
  48. package/package.json +3 -3
package/README.md CHANGED
@@ -55,7 +55,7 @@ Or install globally: `npm install -g @lightdash-tools/mcp`, then `lightdash-mcp
55
55
 
56
56
  ### Streamable HTTP (remote)
57
57
 
58
- `http` mounts **every** fixed path from the profile table (no `--profile`); clients pick the path in the URL.
58
+ `http` mounts every fixed path from the profile table by default (no `--profile`); clients pick the path in the URL. Optionally restrict mounts with `LIGHTDASH_TOOLS_MCP_PROFILES` (comma-separated profile ids; unset or empty → all).
59
59
 
60
60
  ```bash
61
61
  export LIGHTDASH_URL="https://app.lightdash.cloud"
@@ -79,17 +79,17 @@ Prefer `LIGHTDASH_TOOLS_*` env from the parent process. Avoid plaintext `.env` w
79
79
 
80
80
  ### Stdio
81
81
 
82
- | Required | Optional |
83
- | :----------------------------------- | :-------------------------------------------------------------------------------------------- |
84
- | `LIGHTDASH_URL`, `LIGHTDASH_API_KEY` | `LIGHTDASH_TOOLS_AUDIT_LOG` (file; else stderr JSON), `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS` |
82
+ | Required | Optional |
83
+ | :----------------------------------- | :------------------------------------------------------------------------------------------------------------------ |
84
+ | `LIGHTDASH_URL`, `LIGHTDASH_API_KEY` | `LIGHTDASH_TOOLS_AUDIT_LOG` (file; else stderr JSON), [`LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS`](#project-allowlist) |
85
85
 
86
86
  Do **not** set OAuth client secrets for stdio. MCP ignores CLI `SAFETY_MODE` / `DRY_RUN`.
87
87
 
88
88
  ### HTTP OAuth (primary)
89
89
 
90
- | Required | Common optional |
91
- | :-------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------- |
92
- | `LIGHTDASH_URL`, `LIGHTDASH_TOOLS_MCP_PUBLIC_URL`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_ID`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET` | port, `ALLOWED_ORIGINS`, `ALLOWED_PROJECT_UUIDS`, token cache TTL |
90
+ | Required | Common optional |
91
+ | :-------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
92
+ | `LIGHTDASH_URL`, `LIGHTDASH_TOOLS_MCP_PUBLIC_URL`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_ID`, `LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET` | port, `ALLOWED_ORIGINS`, [`LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS`](#project-allowlist), [`LIGHTDASH_TOOLS_MCP_PROFILES`](#profile-allowlist), token cache TTL |
93
93
 
94
94
  On Cloud Run / hosted HTTP, leave `LIGHTDASH_TOOLS_AUDIT_LOG` unset — tool audits are stderr JSON (`channel: "audit"`) → Cloud Logging. See [cloud-run.md](../../docs/operators/cloud-run.md).
95
95
 
@@ -97,9 +97,9 @@ Register Lightdash redirect URI: `{PUBLIC_URL}/oauth/callback`. Clients connect
97
97
 
98
98
  ### Content-developer / content-governance signing
99
99
 
100
- | Required (non-test) | Notes |
101
- | :-------------------------------------- | :---------------------------------------------------------------------------------------------- |
102
- | `LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY` | ≥32-byte secret for HMAC `previewToken` / `requestState` (fail closed if unset; not encryption) |
100
+ | Required (non-test) | Notes |
101
+ | :-------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
102
+ | `LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY` | ≥32-byte secret for HMAC `previewToken` / `requestState` (fail closed if unset; not encryption). Required only when `content-developer` or `content-governance` is mounted (including unrestricted HTTP). |
103
103
 
104
104
  Governance soft-delete needs client form elicitation; missing capability → `ELICITATION_REQUIRED`.
105
105
 
@@ -110,6 +110,51 @@ Governance soft-delete needs client form elicitation; missing capability → `EL
110
110
  | Shared-key | `LIGHTDASH_API_KEY` + `LIGHTDASH_TOOLS_MCP_SHARED_KEY` |
111
111
  | Local none | `NODE_ENV=development` (not `production`) |
112
112
 
113
+ ### Profile allowlist
114
+
115
+ Optional HTTP-only mount ceiling. Unset or empty → all seven shipped profile paths. Non-empty → only listed profile ids are mounted; other paths (and their path-specific OAuth PRM) 404. Stdio ignores this variable (`stdio --profile` still required).
116
+
117
+ **Format**
118
+
119
+ - Comma-separated profile ids from the table above (`semantic-layer`, `content-reader`, …)
120
+ - Whitespace around commas is ignored
121
+ - No empty segments (double commas are rejected)
122
+ - Unknown ids fail at process startup
123
+
124
+ ```bash
125
+ export LIGHTDASH_TOOLS_MCP_PROFILES="content-reader,content-developer"
126
+ ```
127
+
128
+ Architecture: [ADR-0024](../../docs/adr/0024-mcp-http-profile-mount-allowlist-via-env.md).
129
+
130
+ ### Project allowlist
131
+
132
+ Optional deployment ceiling shared with the CLI. Unset or empty → unrestricted beyond RBAC, HTTP pin, and tool `projectUuid`. Non-empty → hard allowlist for all profiles.
133
+
134
+ **Format**
135
+
136
+ - Comma-separated Lightdash project UUIDs (RFC 4122)
137
+ - Whitespace around commas is ignored
138
+ - No empty segments (double commas are rejected)
139
+ - Invalid UUIDs fail at process startup
140
+ - Input is case-insensitive; values are normalized to lowercase
141
+
142
+ ```bash
143
+ # Single project
144
+ export LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS="aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa"
145
+
146
+ # Multiple (spaces optional)
147
+ export LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS="aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa, bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb"
148
+ ```
149
+
150
+ **Semantics**
151
+
152
+ - Ceiling only — not a default project; tools still need `projectUuid` or an HTTP `X-Lightdash-Project` pin
153
+ - When restricted, HTTP pin and every tool `projectUuid` must be in the set
154
+ - `list_projects` returns only allowlisted projects; cross-project promote requires upstream targets in the set
155
+
156
+ Architecture: [ADR-0008](../../docs/adr/0008-mcp-request-scope-and-hardening.md).
157
+
113
158
  Obsolete vars (`AUTH_MODE`, `EXPERIMENTAL_*`, `DANGEROUSLY_*`, `INSECURE_DEV`, `MCP_STORE`, `MCP_REDIS_URL`, free-form `MCP_PATH`) are **rejected**. See [ADR-0019](../../docs/adr/0019-mcp-stateless-protocol-core-without-redis-ephemeral-store.md).
114
159
 
115
160
  ## Profiles at a glance
@@ -147,7 +192,7 @@ Unsaved Explore-style metric queries (`run_metric_query`) with explore discovery
147
192
  - **Off MCP:** irrecoverable admin deletes, permanent content purge, broad org mutations — use `@lightdash-tools/client` or the CLI ([ADR-0004](../../docs/adr/0004-agent-safe-exposure-mcp-cli-vs-client-only.md)).
148
193
  - **Writes:** only on `content-developer` (preview gate). Soft-delete / promote: only on `content-governance` (form elicitation).
149
194
  - **Redaction:** emails masked unless `includeEmail=true`; scheduler destinations redacted unless `revealDestinations=true`; warehouse/dbt connection secrets never on MCP ([ADR-0011](../../docs/adr/0011-mcp-tool-response-sensitivity-classes.md)).
150
- - **Project scope:** optional HTTP pin `X-Lightdash-Project`, else tool `projectUuid`; optional ceiling `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS`.
195
+ - **Project scope:** optional HTTP pin `X-Lightdash-Project`, else tool `projectUuid`; optional ceiling [`LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS`](#project-allowlist).
151
196
 
152
197
  Profile tool allowlists are the capability surface — not CLI safety-mode.
153
198
 
@@ -5,7 +5,7 @@
5
5
  import { ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY } from '../config/env.js';
6
6
  export declare const PREVIEW_TOKEN_KEY_PURPOSE = "content-developer preview tokens are enabled";
7
7
  export declare const DESTRUCTIVE_REQUEST_STATE_KEY_PURPOSE = "content-governance destructive tools are enabled";
8
- /** HTTP ships all profiles; preview + destructive elicitation share one signing key. */
8
+ /** Preview + destructive elicitation share one signing key when write profiles are mounted. */
9
9
  export declare const HTTP_SIGNED_STATE_KEY_PURPOSE = "HTTP MCP exposes content-developer preview tokens and content-governance destructive tools";
10
10
  /** Resolve the HMAC signing key (configured env or test fallback). */
11
11
  export declare function resolveRequestStateKey(purpose: string): string;
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY", { en
13
13
  const TEST_FALLBACK_KEY = 'lightdash-tools-dev-request-state-key!!';
14
14
  exports.PREVIEW_TOKEN_KEY_PURPOSE = 'content-developer preview tokens are enabled';
15
15
  exports.DESTRUCTIVE_REQUEST_STATE_KEY_PURPOSE = 'content-governance destructive tools are enabled';
16
- /** HTTP ships all profiles; preview + destructive elicitation share one signing key. */
16
+ /** Preview + destructive elicitation share one signing key when write profiles are mounted. */
17
17
  exports.HTTP_SIGNED_STATE_KEY_PURPOSE = 'HTTP MCP exposes content-developer preview tokens and content-governance destructive tools';
18
18
  function isTestRuntime() {
19
19
  return process.env.VITEST === 'true' || process.env.NODE_ENV === 'test';
@@ -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");
@@ -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
@@ -77,7 +77,7 @@ program
77
77
  });
78
78
  program
79
79
  .command('http')
80
- .description('Run MCP server over Streamable HTTP (all fixed profile paths)')
80
+ .description('Run MCP server over Streamable HTTP (fixed profile paths)')
81
81
  .addHelpText('after', cli_help_js_1.formatProfilesHelp)
82
82
  .action(() => {
83
83
  runHttp();
@@ -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,8 @@ 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";
12
14
  /** Rejected — auth mode is inferred from credentials (ADR-0007). */
13
15
  export declare const ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = "LIGHTDASH_TOOLS_MCP_AUTH_MODE";
14
16
  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_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,8 @@ 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';
15
17
  /** Rejected — auth mode is inferred from credentials (ADR-0007). */
16
18
  exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = 'LIGHTDASH_TOOLS_MCP_AUTH_MODE';
17
19
  exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = 'LIGHTDASH_TOOLS_MCP_SHARED_KEY';
@@ -1,4 +1,5 @@
1
1
  import { SecretString } from '@lightdash-tools/client';
2
+ import { type EnabledProfilesPolicy } from './enabled-profiles.js';
2
3
  import type { McpAuthMode } from '../auth/auth-mode.js';
3
4
  export interface McpHttpConfig {
4
5
  lightdashUrl: string;
@@ -7,6 +8,8 @@ export interface McpHttpConfig {
7
8
  port: number;
8
9
  publicUrl?: string;
9
10
  mcpPath: string;
11
+ /** HTTP mount allowlist. Unrestricted when LIGHTDASH_TOOLS_MCP_PROFILES is unset. */
12
+ enabledProfiles: EnabledProfilesPolicy;
10
13
  authMode: McpAuthMode;
11
14
  sharedKey?: SecretString;
12
15
  /** Server-held Lightdash OAuth application client id (broker mode). */
@@ -7,10 +7,12 @@ exports.getOAuthCallbackUrl = getOAuthCallbackUrl;
7
7
  const client_1 = require("@lightdash-tools/client");
8
8
  const auth_mode_js_1 = require("../auth/auth-mode.js");
9
9
  const index_js_1 = require("../profiles/index.js");
10
+ const enabled_profiles_js_1 = require("./enabled-profiles.js");
10
11
  const env_js_1 = require("./env.js");
11
12
  const normalize_url_js_1 = require("./normalize-url.js");
12
13
  const obsolete_env_js_1 = require("./obsolete-env.js");
13
14
  const public_url_js_1 = require("./public-url.js");
15
+ const read_env_js_1 = require("./read-env.js");
14
16
  const DEFAULT_SCOPES_SUPPORTED = ['read', 'write', 'mcp:read', 'mcp:write'];
15
17
  const warnedAliases = new Set();
16
18
  function warnDeprecatedAlias(oldName, newName) {
@@ -19,13 +21,6 @@ function warnDeprecatedAlias(oldName, newName) {
19
21
  warnedAliases.add(oldName);
20
22
  console.warn(`Warning: ${oldName} is deprecated. Use ${newName}.`);
21
23
  }
22
- function readEnv(name, env) {
23
- // eslint-disable-next-line security/detect-object-injection -- env var names are fixed constants in this module
24
- const value = env[name];
25
- if (value === undefined || value === '')
26
- return undefined;
27
- return value;
28
- }
29
24
  function parsePositiveIntegerEnv(name, value) {
30
25
  const parsed = Number(value);
31
26
  if (!Number.isFinite(parsed) || !Number.isInteger(parsed) || parsed < 0) {
@@ -36,19 +31,19 @@ function parsePositiveIntegerEnv(name, value) {
36
31
  function readNumberEnv(env, primary, aliases, defaultValue,
37
32
  /** Silent fallback (e.g. Cloud Run `PORT`); read only when primary/aliases unset. */
38
33
  silentFallback) {
39
- const primaryValue = readEnv(primary, env);
34
+ const primaryValue = (0, read_env_js_1.readEnv)(primary, env);
40
35
  if (primaryValue !== undefined) {
41
36
  return parsePositiveIntegerEnv(primary, primaryValue);
42
37
  }
43
38
  for (const alias of aliases) {
44
- const aliasValue = readEnv(alias.name, env);
39
+ const aliasValue = (0, read_env_js_1.readEnv)(alias.name, env);
45
40
  if (aliasValue !== undefined) {
46
41
  warnDeprecatedAlias(alias.name, alias.newName);
47
42
  return parsePositiveIntegerEnv(alias.name, aliasValue);
48
43
  }
49
44
  }
50
45
  if (silentFallback !== undefined) {
51
- const fallbackValue = readEnv(silentFallback, env);
46
+ const fallbackValue = (0, read_env_js_1.readEnv)(silentFallback, env);
52
47
  if (fallbackValue !== undefined) {
53
48
  return parsePositiveIntegerEnv(silentFallback, fallbackValue);
54
49
  }
@@ -56,11 +51,11 @@ silentFallback) {
56
51
  return defaultValue;
57
52
  }
58
53
  function readStringEnv(env, primary, aliases) {
59
- const primaryValue = readEnv(primary, env);
54
+ const primaryValue = (0, read_env_js_1.readEnv)(primary, env);
60
55
  if (primaryValue !== undefined)
61
56
  return primaryValue;
62
57
  for (const alias of aliases) {
63
- const aliasValue = readEnv(alias.name, env);
58
+ const aliasValue = (0, read_env_js_1.readEnv)(alias.name, env);
64
59
  if (aliasValue !== undefined) {
65
60
  warnDeprecatedAlias(alias.name, alias.newName);
66
61
  return aliasValue;
@@ -101,7 +96,7 @@ function inferAuthMode(params) {
101
96
  if (sharedKeyRaw) {
102
97
  return auth_mode_js_1.MCP_AUTH_MODE_SHARED_KEY;
103
98
  }
104
- const legacyEnabled = readEnv(env_js_1.ENV_MCP_AUTH_ENABLED, env);
99
+ const legacyEnabled = (0, read_env_js_1.readEnv)(env_js_1.ENV_MCP_AUTH_ENABLED, env);
105
100
  if (legacyEnabled === '1' || legacyEnabled === 'true' || legacyEnabled === 'yes') {
106
101
  warnDeprecatedAlias(env_js_1.ENV_MCP_AUTH_ENABLED, `${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY} (+ LIGHTDASH_API_KEY)`);
107
102
  return auth_mode_js_1.MCP_AUTH_MODE_SHARED_KEY;
@@ -186,12 +181,12 @@ function emitMcpHttpSecurityWarnings(config) {
186
181
  emitCorsSecurityWarnings(config);
187
182
  }
188
183
  function readScopeList(env, primary, fallback) {
189
- const parsed = parseCsv(readEnv(primary, env));
184
+ const parsed = parseCsv((0, read_env_js_1.readEnv)(primary, env));
190
185
  return parsed.length > 0 ? parsed : fallback;
191
186
  }
192
187
  function readHttpAuthInputs(env) {
193
- const oauthClientId = readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID, env);
194
- const oauthClientSecretRaw = readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET, env);
188
+ const oauthClientId = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID, env);
189
+ const oauthClientSecretRaw = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET, env);
195
190
  const publicUrlRaw = readStringEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL, [
196
191
  { name: env_js_1.ENV_MCP_PUBLIC_URL, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL },
197
192
  ]);
@@ -223,11 +218,11 @@ function resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)
223
218
  }
224
219
  function loadMcpHttpConfig(env = process.env) {
225
220
  var _a;
226
- const lightdashUrlRaw = readEnv(client_1.ENV_LIGHTDASH_URL, env);
221
+ const lightdashUrlRaw = (0, read_env_js_1.readEnv)(client_1.ENV_LIGHTDASH_URL, env);
227
222
  if (!lightdashUrlRaw) {
228
223
  throw new Error(`${client_1.ENV_LIGHTDASH_URL} is required.`);
229
224
  }
230
- if (readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PATH, env) !== undefined) {
225
+ if ((0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PATH, env) !== undefined) {
231
226
  throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PATH} is unused and rejected. ` +
232
227
  `The MCP endpoint path is profile-owned (${(0, index_js_1.getDefaultProfile)().path}); leave this variable unset.`);
233
228
  }
@@ -241,20 +236,22 @@ function loadMcpHttpConfig(env = process.env) {
241
236
  { name: env_js_1.ENV_MCP_ALLOWED_ORIGINS, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS },
242
237
  ]);
243
238
  const allowedOrigins = parseCsv(allowedOriginsRaw);
244
- const proxyAuth = readEnv(client_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, env);
245
- const mcpPath = (0, index_js_1.getDefaultProfile)().path;
239
+ const proxyAuth = (0, read_env_js_1.readEnv)(client_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, env);
240
+ const enabledProfiles = (0, enabled_profiles_js_1.parseEnabledProfiles)((0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES, env));
241
+ const mcpPath = (0, enabled_profiles_js_1.resolveRootMcpPath)(enabledProfiles);
246
242
  const publicUrl = publicUrlRaw ? (0, normalize_url_js_1.normalizePublicUrl)(publicUrlRaw, (0, index_js_1.listProfilePaths)()) : undefined;
247
243
  assertPublicUrlSecurity(authMode, publicUrl);
248
- const validateToken = parseBooleanEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN, readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN, env), authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH);
244
+ const validateToken = parseBooleanEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN, (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN, env), authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH);
249
245
  assertValidateTokenPolicy(authMode, validateToken, env);
250
246
  const requiredScopes = readScopeList(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES, []);
251
- const scopesSupportedEnvSet = readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, env) !== undefined;
247
+ const scopesSupportedEnvSet = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, env) !== undefined;
252
248
  assertLightdashOAuthScopePolicy(authMode, requiredScopes, scopesSupportedEnvSet);
253
- return Object.assign(Object.assign({ lightdashUrl: (0, normalize_url_js_1.normalizeLightdashUrl)(lightdashUrlRaw), proxyAuthorization: proxyAuth ? new client_1.SecretString(proxyAuth) : undefined, host: (_a = readEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST, env)) !== null && _a !== void 0 ? _a : '0.0.0.0', port: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT, [
249
+ return Object.assign(Object.assign({ lightdashUrl: (0, normalize_url_js_1.normalizeLightdashUrl)(lightdashUrlRaw), proxyAuthorization: proxyAuth ? new client_1.SecretString(proxyAuth) : undefined, host: (_a = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST, env)) !== null && _a !== void 0 ? _a : '0.0.0.0', port: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT, [
254
250
  { name: env_js_1.ENV_MCP_HTTP_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
255
251
  { name: env_js_1.ENV_MCP_SERVER_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
256
252
  ], 3100, env_js_1.ENV_PLATFORM_PORT), publicUrl,
257
253
  mcpPath,
254
+ enabledProfiles,
258
255
  authMode, sharedKey: sharedKeyRaw ? new client_1.SecretString(sharedKeyRaw) : undefined }, resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)), { allowedOrigins, maxBodyBytes: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES, [{ name: env_js_1.ENV_MCP_MAX_BODY_BYTES, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES }], 1024 * 1024), requiredScopes, scopesSupported: readScopeList(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH ? [] : [...DEFAULT_SCOPES_SUPPORTED]), validateToken, tokenValidationCacheTtlMs: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS, [], 10000) });
259
256
  }
260
257
  function requiresLightdashApiKey(authMode) {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
+ const index_js_1 = require("../profiles/index.js");
5
+ const enabled_profiles_js_1 = require("./enabled-profiles.js");
4
6
  const env_js_1 = require("./env.js");
5
7
  const load_mcp_config_js_1 = require("./load-mcp-config.js");
6
8
  const originalEnv = Object.assign({}, process.env);
@@ -189,6 +191,45 @@ function setOAuthCreds() {
189
191
  const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
190
192
  (0, vitest_1.expect)(config.validateToken).toBe(false);
191
193
  });
194
+ (0, vitest_1.it)('keeps default mcpPath when MCP_PROFILES is unset', () => {
195
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
196
+ process.env.NODE_ENV = 'development';
197
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
198
+ (0, vitest_1.expect)(config.enabledProfiles).toEqual(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES);
199
+ (0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.SEMANTIC_LAYER_PROFILE_PATH);
200
+ });
201
+ (0, vitest_1.it)('keeps semantic-layer mcpPath when that id is in the allowlist', () => {
202
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
203
+ process.env.NODE_ENV = 'development';
204
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'semantic-layer, content-reader';
205
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
206
+ (0, vitest_1.expect)(config.enabledProfiles.restricted).toBe(true);
207
+ (0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.SEMANTIC_LAYER_PROFILE_PATH);
208
+ });
209
+ (0, vitest_1.it)('uses first PROFILE_IDS-enabled mcpPath when semantic-layer is omitted', () => {
210
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
211
+ process.env.NODE_ENV = 'development';
212
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'content-reader,content-developer';
213
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
214
+ (0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.CONTENT_DEVELOPER_PROFILE_PATH);
215
+ });
216
+ (0, vitest_1.it)('rejects unknown MCP_PROFILES ids and empty segments', () => {
217
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
218
+ process.env.NODE_ENV = 'development';
219
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'not-a-profile';
220
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES);
221
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'content-reader,';
222
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(/empty segments/);
223
+ });
224
+ (0, vitest_1.it)('still strips disabled profile suffixes from PUBLIC_URL', () => {
225
+ setOAuthCreds();
226
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'content-reader';
227
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL] =
228
+ 'https://mcp.example.com/content-governance/v1/mcp';
229
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
230
+ (0, vitest_1.expect)(config.publicUrl).toBe('https://mcp.example.com');
231
+ (0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.CONTENT_READER_PROFILE_PATH);
232
+ });
192
233
  (0, vitest_1.it)('rejects LIGHTDASH_TOOLS_MCP_PATH', () => {
193
234
  process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
194
235
  process.env.NODE_ENV = 'development';
@@ -5,6 +5,7 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.assertObsoleteEnvRejected = assertObsoleteEnvRejected;
7
7
  const env_js_1 = require("./env.js");
8
+ const read_env_js_1 = require("./read-env.js");
8
9
  const OBSOLETE_ENV_VARS = [
9
10
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE,
10
11
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH,
@@ -17,17 +18,10 @@ const OBSOLETE_ENV_VARS = [
17
18
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE,
18
19
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL,
19
20
  ];
20
- function readEnv(name, env) {
21
- // eslint-disable-next-line security/detect-object-injection -- env var names are fixed constants
22
- const value = env[name];
23
- if (value === undefined || value === '')
24
- return undefined;
25
- return value;
26
- }
27
21
  /** Fail closed when operators still set removed MCP env vars. */
28
22
  function assertObsoleteEnvRejected(env = process.env) {
29
23
  for (const name of OBSOLETE_ENV_VARS) {
30
- if (readEnv(name, env) !== undefined) {
24
+ if ((0, read_env_js_1.readEnv)(name, env) !== undefined) {
31
25
  if (name === env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE || name === env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL) {
32
26
  throw new Error(`${name} is removed (ADR-0019). ` +
33
27
  `MCP HTTP is now stateless (sessionless) and has no Redis ephemeral store. ` +
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Read a process env value, treating empty string as unset.
3
+ */
4
+ export declare function readEnv(name: string, env: NodeJS.ProcessEnv): string | undefined;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Read a process env value, treating empty string as unset.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readEnv = readEnv;
7
+ function readEnv(name, env) {
8
+ // eslint-disable-next-line security/detect-object-injection -- env var names are fixed constants at call sites
9
+ const value = env[name];
10
+ if (value === undefined || value === '')
11
+ return undefined;
12
+ return value;
13
+ }