Repository navigation
fix: use selected refs for repository path completion - #3981
Open
ZainnQureshii wants to merge 1 commit into
Open
ZainnQureshii wants to merge 1 commit into
ZainnQureshii wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported, and the changes are covered by tests for qualified branch and tag refs alongside existing reference types.
No open issues 🎉
What changed in this PR
This PR fixes repository resource path completion so tree lookups use fully qualified branch and tag refs, matching the refs used when reading the selected resource. This prevents suggestions from being generated from a same-named branch when the user selected a tag, or vice versa.
Changes:
- Qualifies branch refs as
refs/heads/<branch>and tag refs asrefs/tags/<tag>. - Preserves existing SHA, pull-request, and default-branch resolution behavior.
- Extends completion tests for colliding branch and tag names and other reference types.
| File | Description |
|---|---|
| pkg/github/repository_resource_completions.go | Resolves branch and tag selections to fully qualified refs before requesting repository trees. |
| pkg/github/repository_resource_completions_test.go | Verifies tree requests and path suggestions for branches, tags, SHAs, pull requests, and the default branch. |
Review effort: Lite (adaptive)
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.
Summary
Repository resource path completion now requests the tree for the selected branch or tag, using the same ref namespace as resource reads.
Why
In an MCP client that supports resource completions, select the
apache/kafkatag0.8.1and ask for path suggestions undercontrib/. The bare ref0.8.1resolves to the same-named branch, so completion suggestscontrib/LICENSEandcontrib/NOTICE. Opening either suggestion on the tag fails with404 Not Found, because neither file exists there (pkg/github/repository_resource.go:192,pkg/github/repository_resource.go:246). With the fix, both stale suggestions disappear. The replay returnedcontrib/hadoop-consumer/andcontrib/hadoop-producer/before and after the fix.No upstream issue is associated with this fix.
What changed
pkg/github/repository_resource_completions.go:246used the bare branch or tag name. It now sendsrefs/heads/<branch>orrefs/tags/<tag>to the tree lookup atpkg/github/repository_resource_completions.go:273, matching resource reads atpkg/github/repository_resource.go:151andpkg/github/repository_resource.go:157. The branch and tag templates share thepathresolver atpkg/github/repository_resource_completions.go:25.get_repository_treeaccepts one tree identifier or uses the default branch (pkg/github/git.go:92,pkg/github/git.go:110). Theget_file_contentstree lookups use the already resolved ref (pkg/github/repositories.go:1061,pkg/github/repositories_helper.go:311,pkg/github/repositories_helper.go:366). Both tools take their inputs from separate tool calls.pkg/github/repository_resource_completions_test.go:274extends the ref-selection test so a same-named branch and tag produce different suggestions. It also covers SHA, pull request head, and default-branch completion.MCP impact
The change affects suggestions for repository resource paths.
Prompts tested (tool changes only)
N/A. The regression exercises repository resource completion.
Security / limits
Completion still makes one tree request with the same credentials and result limit.
Tool renaming
deprecated_tool_aliases.goNote: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.
Lint & tests
./script/lint./script/testBoth scripts passed with Go 1.27.4 on macOS arm64. golangci-lint v2.14.0 reported zero issues.
go test ./pkg/github -run '^TestCompletePath_RequestsTreeForResolvedRef$' -count=1 -vfailed onmainwith the updated test and passed all five cases with the fix.go test ./pkg/github -run 'Complet|RepositoryResource' -count=1passed.Docs
The resource templates and their inputs are unchanged, so the docs stay as they are.
Skills
The change affects resource completion. No bundled skill covers that behavior.
AI assistance
Prepared with AI assistance (Codex and Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code