Repository navigation
fix(server): MCP pull request tools default to origin, not upstream - #480
Merged
Merged
Conversation
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)
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)
Open
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Batch 1 (batch PR trial). One change so far.
Changes
#479: MCP pull request tools default to
origin, notupstreamProblem. In a fork checkout with both
originandupstreamremotes,pull_request_createopened the pull request on the upstream repository. The GitHub provider chooses the repository with a ranking copied fromgh(upstream over origin), the tool took no repository argument, and the head was sent asforkOwner: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'sresolveRepositoryandcreatesChangeRequestsInread beforeGH_REPO, thegh-resolvedmark and the ranking.GitManager.createPullRequesttakes an optionalrepositoryand pins the base: the named repository, elseorigin's. With nooriginand several remotes it fails and creates nothing.pull_request_creategains an optionalrepository; its description says it opens on origin's repository.locatedefaults a numbered PR toorigin's repository, so update, respond, review, merge, CI re-run, read and CI logs follow the same rule.pull_request_listare 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.tsandtools.ts(parameter and default),agentContextBudget.json(byte count for the changed tool list).Not run: the paid live
mcp-tool-useeval 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).