Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mcp-project-ref-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"trigger.dev": patch
---

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

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.

48 changes: 48 additions & 0 deletions packages/cli-v3/src/mcp/context.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { describe, expect, it, vi } from "vitest";
import { McpContext } from "./context.js";

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

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.


const server = () => new McpServer({ name: "trigger.dev", version: "test" });

describe("McpContext.getProjectRef", () => {
it("prefers the projectRef passed on the tool call", async () => {
const ctx = new McpContext(server(), { projectRef: "proj_flag" });
await expect(ctx.getProjectRef({ projectRef: "proj_call" })).resolves.toBe("proj_call");
});

it("falls back to the --project-ref option when the call omits one", async () => {
const ctx = new McpContext(server(), { projectRef: "proj_flag" });
await expect(ctx.getProjectRef({})).resolves.toBe("proj_flag");
});

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

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.

});
});
4 changes: 4 additions & 0 deletions packages/cli-v3/src/mcp/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export class McpContext {
return options.projectRef;
}

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

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.


const projectDir = await this.getProjectDir({ cwd: options.cwd });

if (!projectDir.ok) {
Expand Down