Skip to content

fix(cli): fall back to --project-ref in MCP tools when calls omit projectRef - #5153

Closed
NickFasulo wants to merge 1 commit into
triggerdotdev:mainfrom
NickFasulo:fix/mcp-project-ref-fallback
Closed

NickFasulo wants to merge 1 commit into
triggerdotdev:mainfrom
NickFasulo:fix/mcp-project-ref-fallback

Conversation

@NickFasulo

Copy link
Copy Markdown

Fixes #5139

What

trigger mcp --project-ref <ref> started outside a directory containing trigger.config.ts answered "No project ref found. Please provide a projectRef." from tools like list_runs, because McpContext.getProjectRef never read this.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-ref server option → trigger.config.ts detection. 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.ts covering all three branches: call-level ref wins, --project-ref fallback 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.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot closed this Nov 23, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Devin Review

Comment on lines +149 to +151
if (this.options.projectRef) {
return this.options.projectRef;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +5 to +29
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: "" } }),
}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +44 to +46
it("still errors when no projectRef is provided anywhere", async () => {
const ctx = new McpContext(server(), {});
await expect(ctx.getProjectRef({})).rejects.toThrow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +5 to +7
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mcp --project-ref is parsed but never used to find the project

1 participant