Skip to content

Commit 1067293

Browse files
d-cscarderne
authored andcommitted
fix(cli): thread --dev-only into McpContext so the env guard fires (#32)
1 parent 256a45a commit 1067293

4 files changed

Lines changed: 64 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
fix(cli): honor the MCP server's `--dev-only` flag

packages/cli-v3/src/commands/mcp.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { tryCatch } from "@trigger.dev/core/utils";
66
import type { Command } from "commander";
77
import { z } from "zod";
88
import { CommonCommandOptions, commonOptions, wrapCommandAction } from "../cli/common.js";
9-
import { CLOUD_API_URL } from "../consts.js";
109
import { serverMetadata } from "../mcp/config.js";
1110
import { McpContext } from "../mcp/context.js";
11+
import { toMcpContextOptions } from "../mcp/contextOptions.js";
1212
import { FileLogger } from "../mcp/logger.js";
1313
import { registerTools } from "../mcp/tools.js";
1414
import { printStandloneInitialBanner } from "../utilities/initialBanner.js";
@@ -95,13 +95,7 @@ export async function mcpCommand(options: McpCommandOptions) {
9595
? new FileLogger(options.logFile, server)
9696
: undefined;
9797

98-
const context = new McpContext(server, {
99-
projectRef: options.projectRef,
100-
fileLogger,
101-
apiUrl: options.apiUrl ?? CLOUD_API_URL,
102-
profile: options.profile,
103-
readonly: options.readonly,
104-
});
98+
const context = new McpContext(server, toMcpContextOptions(options, fileLogger));
10599

106100
registerTools(context);
107101

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, expect, it } from "vitest";
2+
import { toMcpContextOptions } from "./contextOptions.js";
3+
import type { McpCommandOptions } from "../commands/mcp.js";
4+
5+
// The dev-only guards only work if `--dev-only` is threaded from the parsed
6+
// CLI options into the McpContext. These tests pin that wiring.
7+
const baseOptions = {
8+
projectRef: "proj_123",
9+
apiUrl: "https://api.example.com",
10+
profile: "default",
11+
readonly: false,
12+
devOnly: false,
13+
} as unknown as McpCommandOptions;
14+
15+
describe("toMcpContextOptions", () => {
16+
it("threads devOnly=true through to the context options", () => {
17+
expect(toMcpContextOptions({ ...baseOptions, devOnly: true }, undefined).devOnly).toBe(true);
18+
});
19+
20+
it("threads devOnly=false through to the context options", () => {
21+
expect(toMcpContextOptions({ ...baseOptions, devOnly: false }, undefined).devOnly).toBe(false);
22+
});
23+
24+
it("carries the other relevant options across", () => {
25+
const result = toMcpContextOptions(baseOptions, undefined);
26+
expect(result.projectRef).toBe("proj_123");
27+
expect(result.apiUrl).toBe("https://api.example.com");
28+
expect(result.profile).toBe("default");
29+
expect(result.readonly).toBe(false);
30+
});
31+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CLOUD_API_URL } from "../consts.js";
2+
import type { McpCommandOptions } from "../commands/mcp.js";
3+
import type { McpContextOptions } from "./context.js";
4+
import type { FileLogger } from "./logger.js";
5+
6+
/**
7+
* Map parsed CLI options onto the `McpContext` options. `devOnly` must be
8+
* forwarded here or the context sees `undefined` and its dev-only guards
9+
* never fire.
10+
*
11+
* Kept in its own module (type-only imports) so the wiring can be
12+
* unit-tested without loading the full command/tool/build chain.
13+
*/
14+
export function toMcpContextOptions(
15+
options: McpCommandOptions,
16+
fileLogger: FileLogger | undefined
17+
): McpContextOptions {
18+
return {
19+
projectRef: options.projectRef,
20+
fileLogger,
21+
apiUrl: options.apiUrl ?? CLOUD_API_URL,
22+
profile: options.profile,
23+
readonly: options.readonly,
24+
devOnly: options.devOnly,
25+
};
26+
}

0 commit comments

Comments
 (0)