Repository navigation
fix(cli): fall back to --project-ref in MCP tools when calls omit projectRef - #5153
NickFasulo wants to merge 1 commit into
Conversation
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Hi @NickFasulo, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
| if (this.options.projectRef) { | ||
| return this.options.projectRef; | ||
| } |
There was a problem hiding this comment.
🔍 Startup flag overrides explicit config path
Without a call-level projectRef, getProjectRef skips even an explicitly supplied configPath. If both projects contain the task, triggerTaskTool runs it in the startup project instead.
Was this helpful? React with 👍 or 👎 to provide feedback.
| vi.mock("@trigger.dev/core/utils", () => ({ | ||
| tryCatch: async <T>(p: Promise<T>): Promise<[Error | null, T | null]> => { | ||
| try { | ||
| return [null, await p]; | ||
| } catch (e) { | ||
| return [e as Error, null]; | ||
| } | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("@trigger.dev/core/v3", () => ({ | ||
| ApiClient: class {}, | ||
| })); | ||
|
|
||
| vi.mock("../apiClient.js", () => ({ | ||
| CliApiClient: class {}, | ||
| })); | ||
|
|
||
| vi.mock("../config.js", () => ({ | ||
| loadConfig: async () => ({}), | ||
| })); | ||
|
|
||
| vi.mock("./auth.js", () => ({ | ||
| mcpAuth: async () => ({ ok: true, auth: { apiUrl: "", accessToken: "" } }), | ||
| })); |
There was a problem hiding this comment.
🔍 Project lookup tests use prohibited mocks
The suite uses vi.mock despite the testing rules banning mocks. The flag-precedence cases need neither authentication nor API clients.
Was this helpful? React with 👍 or 👎 to provide feedback.
| it("still errors when no projectRef is provided anywhere", async () => { | ||
| const ctx = new McpContext(server(), {}); | ||
| await expect(ctx.getProjectRef({})).rejects.toThrow(); |
There was a problem hiding this comment.
🔍 Missing-project test stops before config lookup
The final test passes when getProjectDir rejects the unconnected server's lack of roots. It never checks getProjectRef after a successful directory lookup.
Was this helpful? React with 👍 or 👎 to provide feedback.
| fix(cli): use the --project-ref option in MCP tools when a call passes no projectRef | ||
|
|
||
| `trigger mcp --project-ref <ref>` started in a directory without a `trigger.config.ts` previously still failed with "No project ref found. Please provide a projectRef." because `McpContext.getProjectRef` never read the server option. Tools now fall back to the `--project-ref` passed at server start before trying config detection. |
There was a problem hiding this comment.
🔍 Release note leads with implementation details
The release-note rules call for a plain, user-facing sentence. The changeset uses a commit prefix and names the internal McpContext.getProjectRef method.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #5139
What
trigger mcp --project-ref <ref>started outside a directory containingtrigger.config.tsanswered "No project ref found. Please provide a projectRef." from tools likelist_runs, becauseMcpContext.getProjectRefnever readthis.options.projectRef— it only checked the tool call argument and then fell through to config detection from the client's roots/cwd.Fix
Added the documented fallback: call-level
projectRef→--project-refserver option →trigger.config.tsdetection. The CLI flag now wins over config detection, which matches the flag's purpose (it's what you pass when detection can't work).Testing
Added
src/mcp/context.test.tscovering all three branches: call-level ref wins,--project-reffallback used when the call omits one, and the original error when nothing supplies a ref.npx vitest run src/mcp/context.test.ts— 3/3 pass.