Repository navigation
Conversation
An annotated tag ref points at a tag object. resolveGitReference returned that object's SHA as if it were a commit, so get_file_contents built repo://.../sha/<tag object>/contents/... resource URIs that the server's own repository resource cannot read (404), and the resolved refs it reports name the tag object instead of the commit. Peel annotated tags with the Git tags API so the SHA names the tagged commit, as it already does for branches and lightweight tags.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Nested annotated tags trigger authenticated API requests without a depth limit, allowing repository-controlled chains to prolong file reads and exhaust the caller’s API quota.
1 open issue
What changed in this PR
This PR fixes annotated-tag resolution in get_file_contents so returned resource URIs identify the tagged commit rather than the tag object and can be read back.
Changes:
- Follow annotated tag objects to resolve their target SHA.
- Add a regression test for resolving an annotated tag to a commit.
| File | Description |
|---|---|
pkg/github/repositories_test.go |
Adds an annotated-tag resolution regression test. |
pkg/github/repositories_helper.go |
Resolves annotated tags before returning content options. |
Review effort: Balanced (adaptive)
A repository can nest annotated tags arbitrarily deep, and each level costs the caller an API request. Return an error once the chain is deeper than maxAnnotatedTagDepth (10).
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
get_file_contentsnow resolves an annotated tag to the commit it points at, so therepo://.../sha/{sha}/contents/...URI it returns can be read back. Before, the URI named the tag object and reading it failed with 404.Why
An annotated tag ref (
refs/tags/v1.0.0in this repo) points at a tag object, not a commit.resolveGitReferencereturnedreference.Object.SHAas is, so for annotated tags it returned the tag object's SHA:repo://github/github-mcp-server/sha/c7fc888…/contents/go.mod, and reading it through the server's ownrepository_content_committemplate fails with404 Not Found(raw content does not accept tag object SHAs). For files of 1 MB or more the tool returns no content, only a resource link (and a download URL), and that link cannot be read either;Branches and lightweight tags were fine because their ref already points at a commit.
No upstream issue is associated with this fix. Reproduced on
mainat 9a72d8d.flowchart TD A[get_file_contents with ref v1.0.0] --> B{Annotated tag ref} B -->|Before| C[URI names the tag object and reads back 404] B -->|After| D[URI names the tagged commit and reads back the file]What changed
pkg/github/repositories_helper.go: after the ref is resolved, peel annotated tags withGit.GetTaguntil the object is not a tag, and return that SHA. One extra API call, only for annotated tags.pkg/github/repositories_test.go:Test_resolveGitReferencecase "annotated tag resolves to the tagged commit" (ref returns atype: tagobject, tag API returns the commit).Narrated recording in the MCP Inspector, before then after (sound on). Server run with
--read-only --toolsets=repos,security_advisories:evidence.mp4
Edge cases and unchanged behaviour checked (in the running server through the Inspector, as shown in the video):
ref: refs/tags/v1.0.0(fully qualified annotated tag) ->sha/569a48d…(the tagged commit)cli/cliv2.60.0->sha/44ee177…, the same commit as beforemain->sha/9a72d8d…(branch head), unchangedheads/,tags/, PR ref and SHA cases inTest_resolveGitReferenceunchanged and passingMCP impact
get_file_contentsinput/output schema is unchanged; for annotated tags the returned resource URI and resolved SHA now name the commit.Prompts tested (tool changes only)
Security / limits
Tool renaming
deprecated_tool_aliases.goLint & tests
./script/lintgofmt -s -l pkg/githubclean; golangci-lint v2.14.0 (the pinned version) on./pkg/github/...: 0 issues../script/testgo test ./pkg/github/passes. The new case fails onmain(expected: "commit-sha",actual: "tag-object-sha") and passes with the fix. I did not run the whole repository suite.Docs
Skills
No bundled skill describes ref resolution.
AI assistance (Claude Code) was used to find the bug, write the fix and test, and record the video.
🤖 Generated with Claude Code