git_show
Display the complete contents of a Git commit, including file changes and metadata, by specifying repository path and revision.
Instructions
Shows the contents of a commit
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | ||
| revision | Yes |
Implementation Reference
- The git_show handler function that executes the tool logic. It validates the revision, retrieves the commit, formats commit metadata (SHA, author, date, message), computes the diff against its parent (or NULL_TREE for the initial commit), and returns the combined output as a string.
def git_show(repo: git.Repo, revision: str) -> str: # Defense in depth: reject revisions starting with '-' to prevent flag injection, # even if a malicious ref with that name exists (e.g. via filesystem manipulation) if revision.startswith("-"): raise BadName(f"Invalid revision: '{revision}' - cannot start with '-'") commit = repo.commit(revision) output = [ f"Commit: {commit.hexsha!r}\n" f"Author: {commit.author!r}\n" f"Date: {commit.authored_datetime!r}\n" f"Message: {commit.message!r}\n" ] if commit.parents: parent = commit.parents[0] diff = parent.diff(commit, create_patch=True) else: diff = commit.diff(git.NULL_TREE, create_patch=True) for d in diff: output.append(f"\n--- {d.a_path}\n+++ {d.b_path}\n") if d.diff is None: continue if isinstance(d.diff, bytes): output.append(d.diff.decode('utf-8')) else: output.append(d.diff) return "".join(output) - The GitShow Pydantic model defining the input schema for the git_show tool, with fields repo_path (str) and revision (str).
class GitShow(BaseModel): repo_path: str revision: str - src/git/src/mcp_server_git/server.py:419-429 (registration)Registration of the git_show tool in the list_tools handler, using GitTools.SHOW enum, with description 'Shows the contents of a commit' and inputSchema from GitShow.model_json_schema().
Tool( name=GitTools.SHOW, description="Shows the contents of a commit", inputSchema=GitShow.model_json_schema(), annotations=ToolAnnotations( readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=False, ), ), - src/git/src/mcp_server_git/server.py:107-107 (registration)Enum definition GitTools.SHOW = 'git_show' providing the string name used to identify the tool.
SHOW = "git_show" - src/git/src/mcp_server_git/server.py:563-568 (registration)The call_tool handler that dispatches 'git_show' (GitTools.SHOW) by calling git_show(repo, arguments['revision']) and returning the result as TextContent.
case GitTools.SHOW: result = git_show(repo, arguments["revision"]) return [TextContent( type="text", text=result )]