Skip to content

fix: use selected refs for repository path completion - #3981

Open
ZainnQureshii wants to merge 1 commit into
github:mainfrom
ZainnQureshii:fix/completion-selected-ref
Open

ZainnQureshii wants to merge 1 commit into
github:mainfrom
ZainnQureshii:fix/completion-selected-ref

Conversation

@ZainnQureshii

@ZainnQureshii ZainnQureshii commented Nov 28, 2026 •

Copy link
Copy Markdown

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/kafka tag 0.8.1 and ask for path suggestions under contrib/. The bare ref 0.8.1 resolves to the same-named branch, so completion suggests contrib/LICENSE and contrib/NOTICE. Opening either suggestion on the tag fails with 404 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 returned contrib/hadoop-consumer/ and contrib/hadoop-producer/ before and after the fix.

No upstream issue is associated with this fix.

What changed

  • pkg/github/repository_resource_completions.go:246 used the bare branch or tag name. It now sends refs/heads/<branch> or refs/tags/<tag> to the tree lookup at pkg/github/repository_resource_completions.go:273, matching resource reads at pkg/github/repository_resource.go:151 and pkg/github/repository_resource.go:157. The branch and tag templates share the path resolver at pkg/github/repository_resource_completions.go:25.
  • The other Git Trees calls operate on different inputs. get_repository_tree accepts one tree identifier or uses the default branch (pkg/github/git.go:92, pkg/github/git.go:110). The get_file_contents tree 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:274 extends 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

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

The change affects suggestions for repository resource paths.

Prompts tested (tool changes only)

N/A. The regression exercises repository resource completion.

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Completion still makes one tree request with the same credentials and result limit.

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Note: 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

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Both 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 -v failed on main with the updated test and passed all five cases with the fix.
  • go test ./pkg/github -run 'Complet|RepositoryResource' -count=1 passed.

Docs

  • Not needed
  • Updated (README / docs / examples)

The resource templates and their inputs are unchanged, so the docs stay as they are.

Skills

  • Updated relevant skills or confirmed no bundled skill applies

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

@ZainnQureshii
ZainnQureshii requested a review from a team as a code owner November 28, 2026 18:00
Copilot AI adaptive review requested due to automatic review settings November 28, 2026 18:00

Copilot AI left a comment

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.

🟢 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 as refs/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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants