Skip to content

fix(git): show blobs and trees for object specs in git_show - #4881

Open
jayzhou2309 wants to merge 2 commits into
modelcontextprotocol:mainfrom
jayzhou2309:fix/git-show-object-spec
Open

jayzhou2309 wants to merge 2 commits into
modelcontextprotocol:mainfrom
jayzhou2309:fix/git-show-object-spec

Conversation

@jayzhou2309

Copy link
Copy Markdown

Description

git_show fails on object specs such as HEAD:path/to/file, which agents send because git show accepts them. repo.commit() peels every revision with ^0, so the call returned Blob or Tree named 'file.py^0' not found. This resolves the revision with rev_parse first. 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

  • Server: git
  • Changes to: tools (git_show behavior and description), README

Motivation and Context

An LLM asked to read a file at a revision calls git_show with HEAD:logic/position_realtime_infos.py and 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?

  • New tests test_git_show_blob_object_spec and test_git_show_tree_object_spec fail on main with KeyError: "Blob or Tree named '^0' not found" and pass with the fix. The test commit lands first.
  • src/git: uv run pytest passes 49 tests. uv run ruff check is clean. uv run pyright reports 0 errors.
  • A stdio MCP client (the mcp Python SDK) called git_show on a scratch repo. On main, HEAD:logic/position_realtime_infos.py returns isError with the exact text from the issue. With the fix it returns the file content, HEAD: returns the root listing, and HEAD returns the same commit output as before.

Breaking Changes

None. Commit revisions produce the same output as before.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

The existing - prefix guard still runs before rev_parse. Blob content decodes with errors="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

jayzhou2309 and others added 2 commits September 28, 2026 04:40
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

No deployments
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.

[Git MCP] Blob or Tree named 'XXX.py^0' not found

1 participant