Repository navigation
fix(cli): fall back to --project-ref in MCP tools when calls omit projectRef #5153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Project lookup tests use prohibited mocks The suite uses 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,10 @@ export class McpContext { | |
| return options.projectRef; | ||
| } | ||
|
|
||
| if (this.options.projectRef) { | ||
| return this.options.projectRef; | ||
| } | ||
|
Comment on lines
+149
to
+151
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Startup flag overrides explicit config path Without a call-level Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| const projectDir = await this.getProjectDir({ cwd: options.cwd }); | ||
|
|
||
| if (!projectDir.ok) { | ||
|
|
||
There was a problem hiding this comment.
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.getProjectRefmethod.Was this helpful? React with 👍 or 👎 to provide feedback.