@lightdash-tools/mcp 0.12.0 → 0.13.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 (127) hide show
  1. package/README.md +23 -14
  2. package/dist/bin.d.ts +1 -0
  3. package/dist/bin.js +31 -57
  4. package/dist/cli-help.d.ts +5 -0
  5. package/dist/cli-help.js +23 -0
  6. package/dist/cli-help.test.js +24 -0
  7. package/dist/config/env.d.ts +2 -2
  8. package/dist/config/env.js +3 -3
  9. package/dist/config/load-mcp-config.js +10 -2
  10. package/dist/config/load-mcp-config.test.js +34 -6
  11. package/dist/config/obsolete-env.js +0 -4
  12. package/dist/config/obsolete-env.test.js +0 -5
  13. package/dist/config/runtime.js +1 -1
  14. package/dist/index.d.ts +5 -2
  15. package/dist/index.js +22 -32
  16. package/dist/notifications/operation-reporter.d.ts +13 -0
  17. package/dist/notifications/operation-reporter.js +45 -0
  18. package/dist/notifications/operation-reporter.test.js +79 -0
  19. package/dist/profiles/ai-agent-ops/v1/index.js +25 -6
  20. package/dist/profiles/ai-agent-ops/v1/prompts.test.js +2 -5
  21. package/dist/profiles/content-developer/v1/index.js +36 -6
  22. package/dist/profiles/content-developer/v1/prompts.test.js +7 -8
  23. package/dist/profiles/content-governance/v1/index.js +7 -6
  24. package/dist/profiles/content-governance/v1/prompts.test.js +2 -5
  25. package/dist/profiles/content-reader/v1/index.js +26 -6
  26. package/dist/profiles/content-reader/v1/prompts.test.js +2 -5
  27. package/dist/profiles/data-analyst/v1/index.js +19 -6
  28. package/dist/profiles/data-analyst/v1/prompts.test.js +2 -4
  29. package/dist/profiles/index.d.ts +3 -1
  30. package/dist/profiles/index.js +6 -1
  31. package/dist/profiles/index.test.js +29 -14
  32. package/dist/profiles/organization-audit/v1/index.js +27 -6
  33. package/dist/profiles/organization-audit/v1/prompts.test.js +2 -5
  34. package/dist/profiles/semantic-layer/v1/index.js +17 -6
  35. package/dist/profiles/semantic-layer/v1/prompts.js +3 -2
  36. package/dist/profiles/semantic-layer/v1/prompts.test.js +2 -5
  37. package/dist/profiles/semantic-layer/v1/resources/playbooks/compose-compile.md +14 -8
  38. package/dist/profiles/semantic-layer/v1/resources/playbooks/core.md +9 -9
  39. package/dist/profiles/semantic-layer/v1/resources/playbooks/explore.md +4 -3
  40. package/dist/profiles/test-support/playbook-invariants.d.ts +5 -0
  41. package/dist/profiles/test-support/playbook-invariants.js +14 -0
  42. package/dist/profiles/types.d.ts +6 -1
  43. package/dist/profiles/types.js +1 -1
  44. package/dist/protocol-contract.test.js +2 -2
  45. package/dist/server/capabilities.d.ts +2 -2
  46. package/dist/server/capabilities.js +3 -4
  47. package/dist/server/capabilities.test.js +4 -5
  48. package/dist/stdio.process.test.js +114 -193
  49. package/dist/tools/ai-agents/agents.d.ts +2 -0
  50. package/dist/tools/ai-agents/agents.js +5 -0
  51. package/dist/tools/ai-agents/discovery.d.ts +4 -0
  52. package/dist/tools/ai-agents/discovery.js +7 -0
  53. package/dist/tools/ai-agents/evaluations.d.ts +9 -0
  54. package/dist/tools/ai-agents/evaluations.js +12 -0
  55. package/dist/tools/ai-agents/threads.d.ts +2 -0
  56. package/dist/tools/ai-agents/threads.js +5 -0
  57. package/dist/tools/composition/explain-content.d.ts +1 -0
  58. package/dist/tools/composition/explain-content.js +4 -0
  59. package/dist/tools/organization/invariants.test.js +7 -3
  60. package/dist/tools/organization/inventory.d.ts +5 -0
  61. package/dist/tools/organization/inventory.js +8 -0
  62. package/dist/tools/organization/roles.d.ts +5 -0
  63. package/dist/tools/organization/roles.js +8 -0
  64. package/dist/tools/project/content.d.ts +4 -0
  65. package/dist/tools/project/content.js +7 -0
  66. package/dist/tools/project/delete-chart.d.ts +3 -1
  67. package/dist/tools/project/delete-chart.js +4 -2
  68. package/dist/tools/project/delete-dashboard.d.ts +3 -1
  69. package/dist/tools/project/delete-dashboard.js +4 -2
  70. package/dist/tools/project/developer-content-preview.d.ts +3 -0
  71. package/dist/tools/project/developer-content-preview.js +6 -0
  72. package/dist/tools/project/developer-content.d.ts +16 -1
  73. package/dist/tools/project/developer-content.js +18 -5
  74. package/dist/tools/project/developer-get-chart-as-code.d.ts +1 -0
  75. package/dist/tools/project/developer-get-chart-as-code.js +4 -0
  76. package/dist/tools/project/get-dashboard-promote-diff.d.ts +1 -0
  77. package/dist/tools/project/get-dashboard-promote-diff.js +4 -0
  78. package/dist/tools/project/invariants.test.js +6 -18
  79. package/dist/tools/project/parameters.d.ts +2 -0
  80. package/dist/tools/project/parameters.js +5 -0
  81. package/dist/tools/project/projects.d.ts +8 -2
  82. package/dist/tools/project/projects.js +34 -38
  83. package/dist/tools/project/projects.test.js +6 -6
  84. package/dist/tools/project/promote-dashboard.d.ts +3 -1
  85. package/dist/tools/project/promote-dashboard.js +4 -2
  86. package/dist/tools/project/reader-content.d.ts +3 -0
  87. package/dist/tools/project/reader-content.js +6 -0
  88. package/dist/tools/project/reader-execution.d.ts +2 -0
  89. package/dist/tools/project/reader-execution.js +5 -0
  90. package/dist/tools/project/reader-export-chart-image.d.ts +1 -0
  91. package/dist/tools/project/reader-export-chart-image.js +4 -0
  92. package/dist/tools/project/schedulers.d.ts +2 -0
  93. package/dist/tools/project/schedulers.js +5 -0
  94. package/dist/tools/project/spaces.d.ts +2 -0
  95. package/dist/tools/project/spaces.js +5 -0
  96. package/dist/tools/query/lifecycle.d.ts +2 -0
  97. package/dist/tools/query/lifecycle.js +5 -0
  98. package/dist/tools/query/run-metric-query.d.ts +1 -0
  99. package/dist/tools/query/run-metric-query.js +4 -0
  100. package/dist/tools/registry.d.ts +5 -284
  101. package/dist/tools/registry.js +9 -137
  102. package/dist/tools/registry.test.js +36 -0
  103. package/dist/tools/semantic/explores.d.ts +5 -1
  104. package/dist/tools/semantic/explores.js +8 -1
  105. package/dist/tools/semantic/metrics.d.ts +3 -1
  106. package/dist/tools/semantic/metrics.js +6 -1
  107. package/dist/tools/semantic/query.d.ts +2 -1
  108. package/dist/tools/semantic/query.js +11 -3
  109. package/dist/tools/semantic/query.test.d.ts +4 -0
  110. package/dist/tools/semantic/query.test.js +134 -0
  111. package/dist/tools/shared.d.ts +4 -1
  112. package/dist/tools/shared.js +6 -3
  113. package/dist/tools/space/access.d.ts +2 -0
  114. package/dist/tools/space/access.js +5 -0
  115. package/dist/tools/types.d.ts +18 -0
  116. package/dist/tools/types.js +29 -0
  117. package/dist/tools/types.test.d.ts +1 -0
  118. package/dist/tools/types.test.js +50 -0
  119. package/package.json +5 -5
  120. package/dist/index.test.js +0 -9
  121. package/dist/profiles/profile.membership.test.js +0 -36
  122. package/dist/tools/index.d.ts +0 -4
  123. package/dist/tools/index.js +0 -8
  124. package/dist/tools/index.test.js +0 -78
  125. /package/dist/{index.test.d.ts → cli-help.test.d.ts} +0 -0
  126. /package/dist/{profiles/profile.membership.test.d.ts → notifications/operation-reporter.test.d.ts} +0 -0
  127. /package/dist/tools/{index.test.d.ts → registry.test.d.ts} +0 -0
package/README.md CHANGED
@@ -6,9 +6,9 @@ Developing this package? See [CONTRIBUTING.md](./CONTRIBUTING.md).
6
6
 
7
7
  ## Choose a profile
8
8
 
9
- | Profile | Use when | HTTP path | Stdio | Catalog |
9
+ | Profile | Use when | HTTP path | Stdio `--profile` | Catalog |
10
10
  | :------------------- | :--------------------------------------- | :--------------------------- | :------------------- | :--------------------------------------------------------------- |
11
- | `semantic-layer` | Explore metrics, compile queries | `/semantic-layer/v1/mcp` | **default** | — |
11
+ | `semantic-layer` | Explore metrics, compile queries | `/semantic-layer/v1/mcp` | `semantic-layer` | — |
12
12
  | `organization-audit` | Read-only org governance | `/organization-audit/v1/mcp` | `organization-audit` | [inventory](../../docs/profiles/organization-audit/inventory.md) |
13
13
  | `content-reader` | Discover and run saved content | `/content-reader/v1/mcp` | `content-reader` | [inventory](../../docs/profiles/content-reader/inventory.md) |
14
14
  | `content-developer` | Author charts/dashboards (preview gate) | `/content-developer/v1/mcp` | `content-developer` | [inventory](../../docs/profiles/content-developer/inventory.md) |
@@ -20,11 +20,16 @@ Tool names are prefixed with `lightdash_`. MCP display names are shortened where
20
20
 
21
21
  ## Quick start
22
22
 
23
+ Commands: `stdio` | `http`. Stdio requires `--profile <id>` (see table). Bare invoke exits with help on stderr. Run `stdio --help` or `http --help` for a live list of profile ids, HTTP paths, and mounted tools.
24
+
23
25
  ### Stdio (local)
24
26
 
27
+ Required form: `stdio --profile <id>` — no default profile, no profile-as-command.
28
+
25
29
  ```bash
26
- npx @lightdash-tools/mcp # semantic-layer (default)
27
- npx @lightdash-tools/mcp content-reader # other profiles by name
30
+ npx @lightdash-tools/mcp stdio --profile semantic-layer
31
+ npx @lightdash-tools/mcp stdio --profile content-reader
32
+ pnpm dlx @lightdash-tools/mcp stdio --profile <id>
28
33
  ```
29
34
 
30
35
  Required env: `LIGHTDASH_URL`, `LIGHTDASH_API_KEY`. Logs go to **stderr**; stdout is JSON-RPC only ([stdio transport](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/stdio)).
@@ -36,7 +41,7 @@ Example Cursor / Claude Desktop config:
36
41
  "mcpServers": {
37
42
  "lightdash": {
38
43
  "command": "npx",
39
- "args": ["@lightdash-tools/mcp", "content-reader"],
44
+ "args": ["-y", "@lightdash-tools/mcp", "stdio", "--profile", "content-reader"],
40
45
  "env": {
41
46
  "LIGHTDASH_URL": "https://app.lightdash.cloud",
42
47
  "LIGHTDASH_API_KEY": "your_pat"
@@ -46,24 +51,27 @@ Example Cursor / Claude Desktop config:
46
51
  }
47
52
  ```
48
53
 
49
- Or install globally: `npm install -g @lightdash-tools/mcp`, then `lightdash-mcp [profile]`.
54
+ Or install globally: `npm install -g @lightdash-tools/mcp`, then `lightdash-mcp stdio --profile <id>`.
50
55
 
51
56
  ### Streamable HTTP (remote)
52
57
 
58
+ `http` mounts **every** fixed path from the profile table (no `--profile`); clients pick the path in the URL.
59
+
53
60
  ```bash
54
61
  export LIGHTDASH_URL="https://app.lightdash.cloud"
55
62
  export LIGHTDASH_TOOLS_MCP_PUBLIC_URL="https://lightdash-mcp.example.com"
56
63
  export LIGHTDASH_TOOLS_OAUTH_CLIENT_ID="..."
57
64
  export LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET="..."
58
65
  npx @lightdash-tools/mcp http
66
+ # pnpm one-shot: pnpm dlx @lightdash-tools/mcp http
59
67
  ```
60
68
 
61
- Profile MCP endpoints accept **POST** only ([Streamable HTTP 2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http); no protocol sessions). Default listen port: `3100` (`LIGHTDASH_TOOLS_MCP_HTTP_PORT`).
69
+ Profile MCP endpoints accept **POST** only ([Streamable HTTP 2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http); no protocol sessions). Default listen port: `3100` (`LIGHTDASH_TOOLS_MCP_HTTP_PORT`). On Cloud Run / containers, when that env is unset, the platform `PORT` is used.
62
70
 
63
71
  - Hosted OAuth (Cursor URL-only): [docs/operators/cursor-claude.md](../../docs/operators/cursor-claude.md)
64
72
  - Operator guide: [docs/operators/mcp-oauth.md](../../docs/operators/mcp-oauth.md)
65
73
 
66
- Local Compose smoke: `docker compose -f docker-compose.dev.yml --profile semantic-layer up --build` → `http://localhost:8080/semantic-layer/v1/mcp`.
74
+ Local Compose smoke: `docker compose -f docker-compose.dev.yml up --build` → `http://localhost:8080/semantic-layer/v1/mcp`.
67
75
 
68
76
  ## Configuration
69
77
 
@@ -164,12 +172,13 @@ Intentional API upgrades still go through the pinned OpenAPI sync (`config/light
164
172
 
165
173
  ## Migration from `@lightdash-tools/semantic-layer-mcp`
166
174
 
167
- | Removed | Use instead |
168
- | :------------------------------------ | :----------------------- |
169
- | `@lightdash-tools/semantic-layer-mcp` | `@lightdash-tools/mcp` |
170
- | Binary `lightdash-semantic-layer-mcp` | `lightdash-mcp` |
171
- | HTTP `/mcp` (old) | `/semantic-layer/v1/mcp` |
172
- | Unprefixed tool names | `lightdash_*` |
175
+ | Removed / old | Use instead |
176
+ | :-------------------------------------------- | :---------------------------------------- |
177
+ | `@lightdash-tools/semantic-layer-mcp` | `@lightdash-tools/mcp` |
178
+ | Binary `lightdash-semantic-layer-mcp` | `lightdash-mcp` |
179
+ | HTTP `/mcp` (old) | `/semantic-layer/v1/mcp` |
180
+ | Unprefixed tool names | `lightdash_*` |
181
+ | `lightdash-mcp <profile>` / `stdio <profile>` | `lightdash-mcp stdio --profile <profile>` |
173
182
 
174
183
  ## Further reading
175
184
 
package/dist/bin.d.ts CHANGED
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export {};
package/dist/bin.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
@@ -35,77 +36,50 @@ var __importStar = (this && this.__importStar) || (function () {
35
36
  Object.defineProperty(exports, "__esModule", { value: true });
36
37
  const common_1 = require("@lightdash-tools/common");
37
38
  const commander_1 = require("commander");
39
+ const cli_help_js_1 = require("./cli-help.js");
40
+ const index_js_1 = require("./profiles/index.js");
41
+ const version_js_1 = require("./server/version.js");
38
42
  const program = new commander_1.Command();
39
- const DEFAULT_STDIO_PROFILE = 'semantic-layer';
40
- const PROFILE_STDIO_DESCRIPTIONS = new Map([
41
- ['semantic-layer', 'Run semantic-layer profile on stdio'],
42
- ['organization-audit', 'Run organization-audit profile on stdio (read-only org governance)'],
43
- [
44
- 'content-reader',
45
- 'Run content-reader profile on stdio (saved-content discovery and bounded execution)',
46
- ],
47
- [
48
- 'content-developer',
49
- 'Run content-developer profile on stdio (chart/dashboard/space authoring behind preview -> validate -> apply)',
50
- ],
51
- [
52
- 'content-governance',
53
- 'Run content-governance profile on stdio (elicitation-gated soft-delete of charts and dashboards)',
54
- ],
55
- [
56
- 'ai-agent-ops',
57
- 'Run ai-agent-ops profile on stdio (thin AI-agent APIs and product evaluation runs)',
58
- ],
59
- [
60
- 'data-analyst',
61
- 'Run data-analyst profile on stdio (explore discovery and bounded ad-hoc metric queries)',
62
- ],
63
- ]);
64
- function profileStdioDescription(profileId) {
65
- const description = PROFILE_STDIO_DESCRIPTIONS.get(profileId);
66
- if (description === undefined) {
67
- throw new Error(`Missing stdio description for profile '${profileId}'`);
68
- }
69
- return description;
70
- }
71
43
  function runStdio(profileId) {
72
- if (profileId) {
73
- process.env.LIGHTDASH_TOOLS_MCP_STDIO_PROFILE = profileId;
74
- }
75
- void Promise.resolve().then(() => __importStar(require('./index.js')));
44
+ void Promise.resolve().then(() => __importStar(require('./index.js'))).then((m) => {
45
+ m.startStdio(profileId);
46
+ });
76
47
  }
77
48
  function runHttp() {
78
49
  void Promise.resolve().then(() => __importStar(require('./http.js')));
79
50
  }
51
+ const profileList = common_1.PROFILE_IDS.join(', ');
80
52
  program
81
53
  .name('lightdash-mcp')
82
- .description(`MCP server for Lightdash (${common_1.PROFILE_IDS.join(', ')}). Default stdio profile is ${DEFAULT_STDIO_PROFILE}.`)
83
- .version('0.12.0');
84
- program
85
- .command('stdio', { isDefault: true })
86
- .description(`Run MCP server on stdio with the default ${DEFAULT_STDIO_PROFILE} profile`)
54
+ .description(`MCP server for Lightdash (${profileList}). Use \`stdio --profile <id>\` or \`http\`.`)
55
+ .version(version_js_1.PACKAGE_VERSION)
56
+ .showHelpAfterError()
57
+ .addHelpText('after', () => '\nSee `lightdash-mcp stdio --help` or `lightdash-mcp http --help` for profiles, paths, and tools.\n')
87
58
  .action(() => {
88
- runStdio(DEFAULT_STDIO_PROFILE);
59
+ console.error(`Transport required. Use \`lightdash-mcp stdio --profile <id>\` (profiles: ${profileList}) or \`lightdash-mcp http\`.`);
60
+ // Stdio MCP requires stdout for JSON-RPC only — help must go to stderr.
61
+ program.outputHelp({ error: true });
62
+ process.exitCode = 1;
89
63
  });
90
- for (const profileId of common_1.PROFILE_IDS) {
91
- program
92
- .command(profileId)
93
- .description(profileStdioDescription(profileId))
94
- .action(() => {
95
- runStdio(profileId);
96
- });
97
- }
98
64
  program
99
- .command('http')
100
- .description('Run MCP server over Streamable HTTP (all fixed profile paths)')
101
- .action(() => {
102
- runHttp();
65
+ .command('stdio')
66
+ .description('Run MCP server on stdio')
67
+ .requiredOption('--profile <id>', `Profile id (${profileList})`)
68
+ .addHelpText('after', cli_help_js_1.formatProfilesHelp)
69
+ .action((opts) => {
70
+ const id = (0, index_js_1.parseProfileId)(opts.profile);
71
+ if (!id) {
72
+ console.error(`Invalid profile '${opts.profile}'. Expected one of: ${profileList}.`);
73
+ process.exitCode = 1;
74
+ return;
75
+ }
76
+ runStdio(id);
103
77
  });
104
78
  program
105
- .command('serve-http')
106
- .description('Deprecated alias for `http`')
79
+ .command('http')
80
+ .description('Run MCP server over Streamable HTTP (all fixed profile paths)')
81
+ .addHelpText('after', cli_help_js_1.formatProfilesHelp)
107
82
  .action(() => {
108
- console.warn('Warning: `serve-http` is deprecated; use `lightdash-mcp http`.');
109
83
  runHttp();
110
84
  });
111
85
  program.parse(process.argv);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Offline Commander help inventory from profile mounts (ADR-0022).
3
+ */
4
+ /** Profile id → path → short tool ids for `stdio --help` / `http --help`. */
5
+ export declare function formatProfilesHelp(): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Offline Commander help inventory from profile mounts (ADR-0022).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatProfilesHelp = formatProfilesHelp;
7
+ const common_1 = require("@lightdash-tools/common");
8
+ const index_js_1 = require("./profiles/index.js");
9
+ const shared_js_1 = require("./tools/shared.js");
10
+ /** Profile id → path → short tool ids for `stdio --help` / `http --help`. */
11
+ function formatProfilesHelp() {
12
+ const lines = [
13
+ '',
14
+ `Profiles (id, HTTP path, tools as short ids; wire name = ${shared_js_1.TOOL_PREFIX}<id>):`,
15
+ ];
16
+ for (const id of common_1.PROFILE_IDS) {
17
+ const profile = (0, index_js_1.getProfile)(id);
18
+ lines.push(` ${id} ${profile.path}`);
19
+ lines.push(` ${(0, index_js_1.listToolIds)(profile).join(', ')}`);
20
+ }
21
+ lines.push('');
22
+ return lines.join('\n');
23
+ }
@@ -0,0 +1,24 @@
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 cli_help_js_1 = require("./cli-help.js");
6
+ const index_js_1 = require("./profiles/index.js");
7
+ const shared_js_1 = require("./tools/shared.js");
8
+ (0, vitest_1.describe)('formatProfilesHelp', () => {
9
+ (0, vitest_1.it)('lists every profile id, path, and mounted tool id in PROFILE_IDS order', () => {
10
+ const text = (0, cli_help_js_1.formatProfilesHelp)();
11
+ (0, vitest_1.expect)(text).toContain(`wire name = ${shared_js_1.TOOL_PREFIX}<id>`);
12
+ for (const id of common_1.PROFILE_IDS) {
13
+ const profile = (0, index_js_1.getProfile)(id);
14
+ (0, vitest_1.expect)(text).toContain(id);
15
+ (0, vitest_1.expect)(text).toContain(profile.path);
16
+ for (const toolId of (0, index_js_1.listToolIds)(profile)) {
17
+ (0, vitest_1.expect)(text).toContain(toolId);
18
+ }
19
+ }
20
+ const firstId = common_1.PROFILE_IDS[0];
21
+ const lastId = common_1.PROFILE_IDS[common_1.PROFILE_IDS.length - 1];
22
+ (0, vitest_1.expect)(text.indexOf(firstId)).toBeLessThan(text.indexOf(lastId));
23
+ });
24
+ });
@@ -4,6 +4,8 @@
4
4
  */
5
5
  export declare const ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = "LIGHTDASH_TOOLS_MCP_HTTP_HOST";
6
6
  export declare const ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = "LIGHTDASH_TOOLS_MCP_HTTP_PORT";
7
+ /** Platform listen port (Cloud Run / many PaaS). Used only when dedicated MCP port env is unset. */
8
+ export declare const ENV_PLATFORM_PORT = "PORT";
7
9
  export declare const ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = "LIGHTDASH_TOOLS_MCP_PUBLIC_URL";
8
10
  /** Rejected at config load — MCP path is profile-owned (see profiles/). */
9
11
  export declare const ENV_LIGHTDASH_TOOLS_MCP_PATH = "LIGHTDASH_TOOLS_MCP_PATH";
@@ -31,8 +33,6 @@ export declare const ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED =
31
33
  export declare const ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = "LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN";
32
34
  export declare const ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = "LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH";
33
35
  export declare const ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = "LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL";
34
- /** Obsolete stdio selector (renamed to LIGHTDASH_TOOLS_MCP_STDIO_PROFILE). */
35
- export declare const ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA = "LIGHTDASH_TOOLS_MCP_STDIO_PERSONA";
36
36
  /** Legacy aliases (deprecated). */
37
37
  export declare const ENV_MCP_HTTP_PORT = "MCP_HTTP_PORT";
38
38
  export declare const ENV_MCP_SERVER_PORT = "MCP_SERVER_PORT";
@@ -4,9 +4,11 @@
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_STDIO_PERSONA = 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_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_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
+ /** Platform listen port (Cloud Run / many PaaS). Used only when dedicated MCP port env is unset. */
11
+ exports.ENV_PLATFORM_PORT = 'PORT';
10
12
  exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = 'LIGHTDASH_TOOLS_MCP_PUBLIC_URL';
11
13
  /** Rejected at config load — MCP path is profile-owned (see profiles/). */
12
14
  exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = 'LIGHTDASH_TOOLS_MCP_PATH';
@@ -34,8 +36,6 @@ exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = 'LIGHTDASH_T
34
36
  exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = 'LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN';
35
37
  exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = 'LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH';
36
38
  exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = 'LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL';
37
- /** Obsolete stdio selector (renamed to LIGHTDASH_TOOLS_MCP_STDIO_PROFILE). */
38
- exports.ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA = 'LIGHTDASH_TOOLS_MCP_STDIO_PERSONA';
39
39
  /** Legacy aliases (deprecated). */
40
40
  exports.ENV_MCP_HTTP_PORT = 'MCP_HTTP_PORT';
41
41
  exports.ENV_MCP_SERVER_PORT = 'MCP_SERVER_PORT';
@@ -33,7 +33,9 @@ function parsePositiveIntegerEnv(name, value) {
33
33
  }
34
34
  return parsed;
35
35
  }
36
- function readNumberEnv(env, primary, aliases, defaultValue) {
36
+ function readNumberEnv(env, primary, aliases, defaultValue,
37
+ /** Silent fallback (e.g. Cloud Run `PORT`); read only when primary/aliases unset. */
38
+ silentFallback) {
37
39
  const primaryValue = readEnv(primary, env);
38
40
  if (primaryValue !== undefined) {
39
41
  return parsePositiveIntegerEnv(primary, primaryValue);
@@ -45,6 +47,12 @@ function readNumberEnv(env, primary, aliases, defaultValue) {
45
47
  return parsePositiveIntegerEnv(alias.name, aliasValue);
46
48
  }
47
49
  }
50
+ if (silentFallback !== undefined) {
51
+ const fallbackValue = readEnv(silentFallback, env);
52
+ if (fallbackValue !== undefined) {
53
+ return parsePositiveIntegerEnv(silentFallback, fallbackValue);
54
+ }
55
+ }
48
56
  return defaultValue;
49
57
  }
50
58
  function readStringEnv(env, primary, aliases) {
@@ -245,7 +253,7 @@ function loadMcpHttpConfig(env = process.env) {
245
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, [
246
254
  { name: env_js_1.ENV_MCP_HTTP_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
247
255
  { name: env_js_1.ENV_MCP_SERVER_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
248
- ], 3100), publicUrl,
256
+ ], 3100, env_js_1.ENV_PLATFORM_PORT), publicUrl,
249
257
  mcpPath,
250
258
  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) });
251
259
  }
@@ -14,6 +14,7 @@ function clearMcpEnv() {
14
14
  }
15
15
  delete process.env.LIGHTDASH_URL;
16
16
  delete process.env.LIGHTDASH_API_KEY;
17
+ delete process.env.PORT;
17
18
  }
18
19
  function setOAuthCreds() {
19
20
  process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
@@ -38,6 +39,39 @@ function setOAuthCreds() {
38
39
  const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
39
40
  (0, vitest_1.expect)(config.port).toBe(3200);
40
41
  });
42
+ (0, vitest_1.it)('uses platform PORT when dedicated MCP port env is unset', () => {
43
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
44
+ process.env.PORT = '8080';
45
+ process.env.NODE_ENV = 'development';
46
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
47
+ (0, vitest_1.expect)(config.port).toBe(8080);
48
+ (0, vitest_1.expect)(console.warn).not.toHaveBeenCalled();
49
+ });
50
+ (0, vitest_1.it)('prefers LIGHTDASH_TOOLS_MCP_HTTP_PORT over platform PORT', () => {
51
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
52
+ process.env.LIGHTDASH_TOOLS_MCP_HTTP_PORT = '3200';
53
+ process.env.PORT = '8080';
54
+ process.env.NODE_ENV = 'development';
55
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
56
+ (0, vitest_1.expect)(config.port).toBe(3200);
57
+ });
58
+ (0, vitest_1.it)('prefers obsolete MCP_HTTP_PORT over platform PORT', () => {
59
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
60
+ process.env.MCP_HTTP_PORT = '3300';
61
+ process.env.PORT = '8080';
62
+ process.env.NODE_ENV = 'development';
63
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
64
+ (0, vitest_1.expect)(config.port).toBe(3300);
65
+ (0, vitest_1.expect)(console.warn).toHaveBeenCalled();
66
+ });
67
+ (0, vitest_1.it)('ignores invalid platform PORT when dedicated MCP port is set', () => {
68
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
69
+ process.env.LIGHTDASH_TOOLS_MCP_HTTP_PORT = '3200';
70
+ process.env.PORT = 'not-a-port';
71
+ process.env.NODE_ENV = 'development';
72
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
73
+ (0, vitest_1.expect)(config.port).toBe(3200);
74
+ });
41
75
  (0, vitest_1.it)('infers OAuth when client id, secret, and public URL are set', () => {
42
76
  var _a;
43
77
  setOAuthCreds();
@@ -131,12 +165,6 @@ function setOAuthCreds() {
131
165
  process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV] = '1';
132
166
  (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(/is removed/);
133
167
  });
134
- (0, vitest_1.it)('rejects obsolete STDIO_PERSONA env', () => {
135
- process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
136
- process.env.NODE_ENV = 'development';
137
- process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA] = 'semantic-layer';
138
- (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(/STDIO_PROFILE/);
139
- });
140
168
  (0, vitest_1.it)('rejects non-HTTPS public URL in OAuth mode', () => {
141
169
  setOAuthCreds();
142
170
  process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL] = 'http://mcp.example.com';
@@ -16,7 +16,6 @@ const OBSOLETE_ENV_VARS = [
16
16
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV,
17
17
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STORE,
18
18
  env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL,
19
- env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA,
20
19
  ];
21
20
  function readEnv(name, env) {
22
21
  // eslint-disable-next-line security/detect-object-injection -- env var names are fixed constants
@@ -34,9 +33,6 @@ function assertObsoleteEnvRejected(env = process.env) {
34
33
  `MCP HTTP is now stateless (sessionless) and has no Redis ephemeral store. ` +
35
34
  `Remove this variable from your environment.`);
36
35
  }
37
- if (name === env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA) {
38
- throw new Error(`${name} is removed. Use LIGHTDASH_TOOLS_MCP_STDIO_PROFILE or a stdio subcommand (for example: lightdash-mcp semantic-layer).`);
39
- }
40
36
  throw new Error(`${name} is removed. Auth is inferred from credentials: set ` +
41
37
  `${env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID}, ${env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET}, ` +
42
38
  `and ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL} for hosted OAuth; ` +
@@ -6,7 +6,6 @@ const obsolete_env_js_1 = require("./obsolete-env.js");
6
6
  (0, vitest_1.describe)('assertObsoleteEnvRejected', () => {
7
7
  (0, vitest_1.afterEach)(() => {
8
8
  delete process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE];
9
- delete process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA];
10
9
  });
11
10
  (0, vitest_1.it)('rejects obsolete AUTH_MODE env', () => {
12
11
  process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE] = 'lightdash-oauth';
@@ -15,8 +14,4 @@ const obsolete_env_js_1 = require("./obsolete-env.js");
15
14
  (0, vitest_1.it)('allows unset obsolete vars', () => {
16
15
  (0, vitest_1.expect)(() => (0, obsolete_env_js_1.assertObsoleteEnvRejected)({})).not.toThrow();
17
16
  });
18
- (0, vitest_1.it)('rejects obsolete STDIO_PERSONA env', () => {
19
- process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_STDIO_PERSONA] = 'semantic-layer';
20
- (0, vitest_1.expect)(() => (0, obsolete_env_js_1.assertObsoleteEnvRejected)()).toThrow(/STDIO_PROFILE/);
21
- });
22
17
  });
@@ -24,7 +24,7 @@ function warnIgnoredCliGuardrailEnvVars(env = process.env, warn = console.warn)
24
24
  }
25
25
  if (ignored.length > 0) {
26
26
  warn(`Warning: ${ignored.join(', ')} ${ignored.length === 1 ? 'is' : 'are'} set but ignored by MCP. ` +
27
- 'Those variables apply to the CLI only. MCP uses catalog profile membership + auth/RBAC + optional ' +
27
+ 'Those variables apply to the CLI only. MCP uses profile tools mounts + auth/RBAC + optional ' +
28
28
  `${common_1.ENV_LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS} + optional X-Lightdash-Project (ADR-0008).`);
29
29
  }
30
30
  const removedDefault = env.LIGHTDASH_TOOLS_PROJECT_UUID;
package/dist/index.d.ts CHANGED
@@ -2,10 +2,13 @@
2
2
  * MCP server entrypoint (Stdio). Use LIGHTDASH_URL and LIGHTDASH_API_KEY.
3
3
  * Logging: stderr only (stdout is JSON-RPC).
4
4
  *
5
- * Optional profile via LIGHTDASH_TOOLS_MCP_STDIO_PROFILE (set by bin subcommands).
5
+ * Profile is selected by CLI argv (`lightdash-mcp stdio --profile <id>`)
6
+ * and passed into {@link startStdio} — not via env.
6
7
  *
7
8
  * Uses SDK `serveStdio` so the process speaks 2026-07-28 (and legacy initialize
8
9
  * via `legacy: 'serve'`). Hand-wiring `StdioServerTransport` + `connect()` stays
9
10
  * on the 2025-era wire only.
10
11
  */
11
- export {};
12
+ import type { ProfileId } from './profiles/types.js';
13
+ /** Start stdio MCP for an explicit profile (CLI-selected). */
14
+ export declare function startStdio(profileId: ProfileId): void;
package/dist/index.js CHANGED
@@ -3,14 +3,15 @@
3
3
  * MCP server entrypoint (Stdio). Use LIGHTDASH_URL and LIGHTDASH_API_KEY.
4
4
  * Logging: stderr only (stdout is JSON-RPC).
5
5
  *
6
- * Optional profile via LIGHTDASH_TOOLS_MCP_STDIO_PROFILE (set by bin subcommands).
6
+ * Profile is selected by CLI argv (`lightdash-mcp stdio --profile <id>`)
7
+ * and passed into {@link startStdio} — not via env.
7
8
  *
8
9
  * Uses SDK `serveStdio` so the process speaks 2026-07-28 (and legacy initialize
9
10
  * via `legacy: 'serve'`). Hand-wiring `StdioServerTransport` + `connect()` stays
10
11
  * on the 2025-era wire only.
11
12
  */
12
13
  Object.defineProperty(exports, "__esModule", { value: true });
13
- const common_1 = require("@lightdash-tools/common");
14
+ exports.startStdio = startStdio;
14
15
  const stdio_1 = require("@modelcontextprotocol/server/stdio");
15
16
  const audit_js_1 = require("./audit/audit.js");
16
17
  const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
@@ -19,36 +20,25 @@ const runtime_js_1 = require("./config/runtime.js");
19
20
  const available_projects_js_1 = require("./governance/available-projects.js");
20
21
  const index_js_1 = require("./profiles/index.js");
21
22
  const server_js_1 = require("./server/server.js");
22
- function resolveStdioProfile() {
23
- const raw = process.env.LIGHTDASH_TOOLS_MCP_STDIO_PROFILE;
24
- if (!raw) {
25
- return (0, index_js_1.getDefaultProfile)();
23
+ /** Start stdio MCP for an explicit profile (CLI-selected). */
24
+ function startStdio(profileId) {
25
+ try {
26
+ (0, obsolete_env_js_1.assertObsoleteEnvRejected)(process.env);
27
+ (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
28
+ (0, available_projects_js_1.validateAvailableProjectsConfig)();
29
+ (0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
30
+ const profile = (0, index_js_1.getProfile)(profileId);
31
+ const contextProvider = new env_context_provider_js_1.EnvContextProvider();
32
+ (0, stdio_1.serveStdio)(() => (0, server_js_1.createLightdashMcpServer)(contextProvider, { profile }), {
33
+ legacy: 'serve',
34
+ onerror: (error) => {
35
+ console.error('MCP stdio error:', error);
36
+ },
37
+ });
38
+ console.error(`Lightdash MCP server (${profile.id}) running on stdio`);
26
39
  }
27
- const id = (0, index_js_1.parseProfileId)(raw);
28
- if (!id) {
29
- throw new Error(`Invalid LIGHTDASH_TOOLS_MCP_STDIO_PROFILE='${raw}'. Expected one of: ${common_1.PROFILE_IDS.join(', ')}.`);
40
+ catch (err) {
41
+ console.error('Fatal:', err);
42
+ process.exit(1);
30
43
  }
31
- return (0, index_js_1.getProfile)(id);
32
- }
33
- function main() {
34
- (0, obsolete_env_js_1.assertObsoleteEnvRejected)(process.env);
35
- (0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
36
- (0, available_projects_js_1.validateAvailableProjectsConfig)();
37
- (0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
38
- const profile = resolveStdioProfile();
39
- const contextProvider = new env_context_provider_js_1.EnvContextProvider();
40
- (0, stdio_1.serveStdio)(() => (0, server_js_1.createLightdashMcpServer)(contextProvider, { profile }), {
41
- legacy: 'serve',
42
- onerror: (error) => {
43
- console.error('MCP stdio error:', error);
44
- },
45
- });
46
- console.error(`Lightdash MCP server (${profile.id}) running on stdio`);
47
- }
48
- try {
49
- main();
50
- }
51
- catch (err) {
52
- console.error('Fatal:', err);
53
- process.exit(1);
54
44
  }
@@ -0,0 +1,13 @@
1
+ import type { ServerContext } from '@modelcontextprotocol/server';
2
+ export type OperationPhase = 'calling-service' | 'completed' | 'preparing' | 'processing-response' | 'waiting';
3
+ export type OperationPhaseEvent = {
4
+ phase: OperationPhase;
5
+ operation: string;
6
+ message: string;
7
+ completedUnits?: number;
8
+ totalUnits?: number;
9
+ };
10
+ export interface OperationReporter {
11
+ phase(event: OperationPhaseEvent): Promise<void>;
12
+ }
13
+ export declare function createOperationReporter(context: ServerContext | undefined): OperationReporter;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createOperationReporter = createOperationReporter;
4
+ class NoopOperationReporter {
5
+ async phase() {
6
+ // Intentionally empty when the client did not opt in to progress notifications.
7
+ }
8
+ }
9
+ class McpProgressOperationReporter {
10
+ constructor(token, notify) {
11
+ this.token = token;
12
+ this.notify = notify;
13
+ this.current = 0;
14
+ }
15
+ async phase(event) {
16
+ var _a;
17
+ const requestedProgress = (_a = event.completedUnits) !== null && _a !== void 0 ? _a : this.current + 1;
18
+ this.current = Math.max(this.current + 1, requestedProgress);
19
+ const params = {
20
+ progressToken: this.token,
21
+ progress: this.current,
22
+ message: event.message,
23
+ };
24
+ if (event.totalUnits !== undefined) {
25
+ params.total = event.totalUnits;
26
+ }
27
+ try {
28
+ await this.notify({ method: 'notifications/progress', params });
29
+ }
30
+ catch (_b) {
31
+ // Progress reporting is best-effort and must never fail the tool invocation.
32
+ }
33
+ }
34
+ }
35
+ function createOperationReporter(context) {
36
+ var _a;
37
+ const progressContext = context;
38
+ const mcpReq = progressContext === null || progressContext === void 0 ? void 0 : progressContext.mcpReq;
39
+ const token = (_a = mcpReq === null || mcpReq === void 0 ? void 0 : mcpReq._meta) === null || _a === void 0 ? void 0 : _a.progressToken;
40
+ const notify = mcpReq === null || mcpReq === void 0 ? void 0 : mcpReq.notify;
41
+ if (token === undefined || notify === undefined) {
42
+ return new NoopOperationReporter();
43
+ }
44
+ return new McpProgressOperationReporter(token, notify.bind(mcpReq));
45
+ }