Skip to main content
Glama
modelcontextprotocol

git MCP server

Official

git_diff

Read-onlyIdempotent

Compare differences between Git branches or commits. Specify a repository path and target branch or commit to view line-by-line changes.

Instructions

Shows differences between branches or commits

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes
targetYes
context_linesNo

Implementation Reference

  • The git_diff function that executes the diff logic. Uses GitPython's repo.git.diff() to show differences between branches or commits, with security checks against flag injection (rejects targets starting with '-') and validates the target is a real git ref via repo.rev_parse().
    def git_diff(repo: git.Repo, target: str, context_lines: int = DEFAULT_CONTEXT_LINES) -> str:
        # Defense in depth: reject targets starting with '-' to prevent flag injection,
        # even if a malicious ref with that name exists (e.g. via filesystem manipulation)
        if target.startswith("-"):
            raise BadName(f"Invalid target: '{target}' - cannot start with '-'")
        repo.rev_parse(target)  # Validates target is a real git ref, throws BadName if not
        return repo.git.diff(f"--unified={context_lines}", target)
  • GitDiff Pydantic BaseModel schema defining input parameters: repo_path (str), target (str), and optional context_lines (int, default 3).
    class GitDiff(BaseModel):
        repo_path: str
        target: str
        context_lines: int = DEFAULT_CONTEXT_LINES
  • Tool registration under the name 'git_diff' (from GitTools.DIFF enum value 'git_diff') with description 'Shows differences between branches or commits', using GitDiff.model_json_schema() for input validation and readOnlyHint=True.
    Tool(
        name=GitTools.DIFF,
        description="Shows differences between branches or commits",
        inputSchema=GitDiff.model_json_schema(),
        annotations=ToolAnnotations(
            readOnlyHint=True,
            destructiveHint=False,
            idempotentHint=True,
            openWorldHint=False,
        ),
    ),
  • The call_tool handler that dispatches the 'git_diff' tool name to the git_diff function, passing arguments['target'] and context_lines.
    case GitTools.DIFF:
        diff = git_diff(repo, arguments["target"], arguments.get("context_lines", DEFAULT_CONTEXT_LINES))
        return [TextContent(
            type="text",
            text=f"Diff with {arguments['target']}:\n{diff}"
        )]
  • GitTools enum defining DIFF = 'git_diff' as the constant used for the tool name throughout the code.
    class GitTools(str, Enum):
        STATUS = "git_status"
        DIFF_UNSTAGED = "git_diff_unstaged"
        DIFF_STAGED = "git_diff_staged"
        DIFF = "git_diff"
        COMMIT = "git_commit"
        ADD = "git_add"
        RESET = "git_reset"
        LOG = "git_log"
        CREATE_BRANCH = "git_create_branch"
        CHECKOUT = "git_checkout"
        SHOW = "git_show"
    
        BRANCH = "git_branch"
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description does not add behavioral context beyond what annotations already provide (readOnly, non-destructive, idempotent). It is acceptable but offers no extra transparency about edge cases or performance.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is only one sentence, making it concise. However, it lacks essential details, so the brevity harms completeness rather than being a virtue.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of sibling tools and three parameters, the description is too minimal. It omits parameter explanations, usage context, and output expectations, making it incomplete for effective tool selection.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description does not explain any parameter (repo_path, target, context_lines). The agent gets no help understanding the meaning or format of parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it shows differences between branches or commits, matching the tool's name. However, it does not differentiate from the sibling tools git_diff_staged and git_diff_unstaged, which are more specific variants.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool over its siblings (e.g., git_diff_staged, git_diff_unstaged). The agent is left to infer usage without explicit when-to or when-not-to directions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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