fix(git): show blobs and trees for object specs in git_show - #4881
Open
jayzhou2309 wants to merge 2 commits into
Open
jayzhou2309 wants to merge 2 commits into
jayzhou2309 wants to merge 2 commits into
Conversation
repo.commit() peels every revision with ^0, so HEAD:path/to/file failed with "Blob or Tree named 'file^0' not found". Resolve the revision with rev_parse first, return file content for a blob and a listing for a tree, and keep the commit output for everything else. Fixes modelcontextprotocol#1682 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Description
git_showfails on object specs such asHEAD:path/to/file, which agents send becausegit showaccepts them.repo.commit()peels every revision with^0, so the call returnedBlob or Tree named 'file.py^0' not found. This resolves the revision withrev_parsefirst. A blob returns its content, a tree returns a listing (subdirectories end in/), and every other revision keeps the existing commit output.Fixes #1682
Server Details
git_showbehavior and description), READMEMotivation and Context
An LLM asked to read a file at a revision calls
git_showwithHEAD:logic/position_realtime_infos.pyand gets an error it can't act on. The tool description now names the<revision>:<path>form, so clients know it works.How Has This Been Tested?
test_git_show_blob_object_specandtest_git_show_tree_object_specfail onmainwithKeyError: "Blob or Tree named '^0' not found"and pass with the fix. The test commit lands first.src/git:uv run pytestpasses 49 tests.uv run ruff checkis clean.uv run pyrightreports 0 errors.mcpPython SDK) calledgit_showon a scratch repo. Onmain,HEAD:logic/position_realtime_infos.pyreturnsisErrorwith the exact text from the issue. With the fix it returns the file content,HEAD:returns the root listing, andHEADreturns the same commit output as before.Breaking Changes
None. Commit revisions produce the same output as before.
Types of changes
Checklist
Additional context
The existing
-prefix guard still runs beforerev_parse. Blob content decodes witherrors="replace"so a binary file doesn't raise.An AI agent (Claude Code, running Claude Opus 5.5) wrote this change, reproduced the bug, and ran the tests above.
From Claude Code