Skip to main content
Glama
modelcontextprotocol

git MCP server

Official

git_show

Display commit details and changes to review code modifications in Git repositories.

Instructions

Shows the contents of a commit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes
revisionYes

Implementation Reference

  • The main handler function for the 'git_show' tool. It retrieves the specified commit, formats its metadata (hash, author, date, message), computes the diff against the parent commit (or null tree for root), and returns the formatted output.
    def git_show(repo: git.Repo, revision: str) -> str:
        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)
  • Pydantic BaseModel defining the input schema for the git_show tool, requiring 'repo_path' and 'revision' fields.
    class GitShow(BaseModel):
        repo_path: str
        revision: str
  • Registration of the 'git_show' tool (via GitTools.SHOW) in the MCP server's list_tools method, including name, description, and input schema.
    Tool(
        name=GitTools.SHOW,
        description="Shows the contents of a commit",
        inputSchema=GitShow.model_json_schema(),
    ),
  • Definition of the 'git_show' tool name constant within the GitTools enum.
    SHOW = "git_show"
  • Tool dispatcher logic in the call_tool handler that extracts arguments, calls the git_show function, and formats the response as TextContent.
    case GitTools.SHOW:
        result = git_show(repo, arguments["revision"])
        return [TextContent(
            type="text",
            text=result
        )]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/modelcontextprotocol/git'

If you have feedback or need assistance with the MCP directory API, please join our Discord server