Skip to content

fix(server): MCP pull request tools default to origin, not upstream - #480

Merged
shuv1337 merged 6 commits into
mainfrom
batch/s2-1
Nov 23, 2026
Merged

shuv1337 merged 6 commits into
mainfrom
batch/s2-1

Conversation

@shuv1337

Copy link
Copy Markdown
Owner

Batch 1 (batch PR trial). One change so far.

Changes

#479: MCP pull request tools default to origin, not upstream

Problem. In a fork checkout with both origin and upstream remotes, pull_request_create opened the pull request on the upstream repository. The GitHub provider chooses the repository with a ranking copied from gh (upstream over origin), the tool took no repository argument, and the head was sent as forkOwner:branch, so GitHub accepted it. The other pull request tools had the same default when given a PR number without a repository.

Fix.

  • ChangeRequestRepository, a context reference the GitHub provider's resolveRepository and createsChangeRequestsIn read before GH_REPO, the gh-resolved mark and the ranking.
  • GitManager.createPullRequest takes an optional repository and pins the base: the named repository, else origin's. With no origin and several remotes it fails and creates nothing.
  • pull_request_create gains an optional repository; its description says it opens on origin's repository.
  • locate defaults a numbered PR to origin's repository, so update, respond, review, merge, CI re-run, read and CI logs follow the same rule.
  • The desktop "Create PR" path, project identity and pull_request_list are unchanged.

Upstream-shared files touched (all of them; kept additive): SourceControlProvider.ts (new export), GitHubSourceControlProvider.ts (read the pin first), GitManager.ts (one input field, one resolver, one wrapper), handlers.ts and tools.ts (parameter and default), agentContextBudget.json (byte count for the changed tool list).

Not run: the paid live mcp-tool-use eval for the changed tool description (no API key in the build checkout); its dry run passed.

Refs #479

Built by Gemini 4 Neon (Antigravity) in S2Code; planned by Claude Fable 5.2 and Gemini 4 Neon; batch assembled by Claude Fable 5.2 (Claude Code).

MCP pull request tools inherited gh's upstream > github > origin ranking on fork checkouts, so pull_request_create opened PRs on upstream and numbered PR tools acted on upstream by default instead of origin.

Add an ambient ChangeRequestRepository Context.Reference read first by GitHubSourceControlProvider (resolveRepository and createsChangeRequestsIn), pin GitManager.createPullRequest to origin's repository by default (or a named owner/name repository, refusing ambiguous multi-remote checkouts without origin and non-GitHub repository overrides), expose optional repository on pull_request_create, and default numbered MCP PR operations in locate to repositoryIdentity.origin when on the same host.

Touched upstream-shared files:
- packages/source-control-core/src/server/SourceControlProvider.ts: add ChangeRequestRepository Context.Reference defaulting to null.
- packages/source-control-github/src/server/GitHubSourceControlProvider.ts: honor ChangeRequestRepository ahead of GH_REPO, gh-resolved, and remote ranking in resolveRepository and createsChangeRequestsIn.
- packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts: extend repository precedence table with pinned origin/upstream cases.
- apps/server/src/git/GitManager.ts: add optional repository to createPullRequest, enforce GitHub base-repository resolution rules, and provide ChangeRequestRepository to openPrFromBranch.
- apps/server/src/git/GitManager.test.ts: test origin default, named repository pin, malformed repository, ambiguous multi-remote refusal, sole non-origin remote, and non-GitHub repository rejection.
- apps/server/src/mcp/toolkits/pullRequests/tools.ts: add optional owner/name repository parameter, result repository annotation, and updated description on pull_request_create.
- apps/server/src/mcp/toolkits/pullRequests/handlers.ts: forward repository in pull_request_create and default numbered locate lookups to same-host repositoryIdentity.origin.
- apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts: verify repository forwarding, schema validation, and origin-first default for numbered PR operations.
- apps/server/src/provider/agentContextBudget.json: update mcpToolListJsonBytes budget for the new pull_request_create parameter and description.

Refs #479

Model: Gemini 4 Neon (High) (Antigravity harness)
Address round-1 review findings on batch PR #480 (issue #479):

1. Origin present but not usable: parseGitHubRemoteRepository falls back from raw config to expanded `git remote get-url <name>` for insteadOf rewrites, and fails closed with a GitManagerError asking for repository (owner/name) whenever origin is not a usable GitHub repo (keeping only single plain-local-path test fixtures unpinned).
2. No origin, single remote: pin the sole remote's parsed GitHub repository instead of returning null, fail closed if it does not parse, and propagate `git remote` errors as GitManagerError instead of defaulting to an empty list.
3. Head classification honors ChangeRequestRepository: when pinned, resolveBranchHeadContext derives isCrossRepository from the pin (and targetsRemote) instead of the origin/isForeignRemote heuristic, so creating a same-repo PR on a non-origin fork remote uses a plain head, matches the created PR, and avoids duplicate creation on retry.
4. Agent context budget: tightened pull_request_create description to cut 72 bytes off the previous delta (mcpToolListJsonBytes: 59262 -> 59190, +47 over 59143) without dropping pushed-branch, link, return-open, origin, or repository (owner/name) facts.
5. ThreadPullRequestInput.repository description: dropped to avoid adding +315 bytes across the 7 tools sharing ThreadPullRequestInput.
6. Test signal: removed duplicated pin logic from the fake createsChangeRequestsIn in GitManager.test.ts and replaced the echoing heads assertion in GitHubSourceControlProvider.test.ts with listChangeRequests-under-pin.
7. Upstream-sync footprint: restored all existing test cases/tables and import blocks to match main verbatim (purely additive test diffs), and shared one exported GitManager.isOwnerRepository helper between GitManager.ts and tools.ts.

Refs #479

Model: Gemini 4 Neon (High) (Antigravity harness)
@shuv1337 shuv1337 added the agent-context-increase Approves growth in agent context budget label Nov 23, 2026
Both fix-check reviewers found "Pass repository (owner/name) elsewhere" easy to misread. Use the reviewer's wording; the tool list grows by 8 bytes (59198), covered by the agent-context-increase label on the batch PR.

Refs #479

Claude Fable 5.2 (Claude Code)
@shuv1337
shuv1337 merged commit 612212e into main Nov 23, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-context-increase Approves growth in agent context budget

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant