Skip to main content
Glama
MementoRC

MCP Git Server

by MementoRC

git_diff_branches

Compare changes between two branches in a Git repository to identify differences, enabling clear review and analysis of code updates.

Instructions

Show differences between two branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_branchYes
compare_branchYes
repo_pathYes

Implementation Reference

  • The core handler function git_diff_branches that performs the git diff operation between two specified branches, including branch validation, stat-only mode, truncation for large diffs, and error handling.
    def git_diff_branches(
        repo: Repo,
        base_branch: str,
        compare_branch: str,
        stat_only: bool = False,
        max_lines: int | None = None,
    ) -> str:
        """Show differences between two branches with size limiting options"""
        try:
            # Verify branches exist
            all_branches = [branch.name for branch in repo.branches] + [
                ref.name.split("/")[-1] for ref in repo.remote().refs
            ]
    
            if base_branch not in all_branches:
                return f"❌ Base branch '{base_branch}' not found"
            if compare_branch not in all_branches:
                return f"❌ Compare branch '{compare_branch}' not found"
    
            # Build diff command arguments
            diff_range = f"{base_branch}...{compare_branch}"
    
            if stat_only:
                # Return only file statistics
                diff_output = repo.git.diff("--stat", diff_range)
                if not diff_output.strip():
                    return f"No differences between {base_branch} and {compare_branch}"
                return f"Diff statistics between {base_branch} and {compare_branch}:\n{diff_output}"
    
            # Get full diff
            diff_output = repo.git.diff(diff_range)
    
            if not diff_output.strip():
                return f"No differences between {base_branch} and {compare_branch}"
    
            # Apply line limit if specified
            if max_lines and max_lines > 0:
                lines = diff_output.split("\n")
                if len(lines) > max_lines:
                    truncated_output = "\n".join(lines[:max_lines])
                    truncated_output += (
                        f"\n\n... [Truncated: showing {max_lines} of {len(lines)} lines]"
                    )
                    truncated_output += "\nUse --stat flag for summary or increase max_lines for more content"
                    return truncated_output
    
            # Check if output is extremely large and warn
            if len(diff_output) > 50000:  # 50KB threshold
                lines_count = len(diff_output.split("\n"))
                warning = f"⚠️  Large diff detected ({lines_count} lines, ~{len(diff_output) // 1000}KB)\n"
                warning += "Consider using stat_only=true for summary or max_lines parameter to limit output\n\n"
                return warning + diff_output
    
            return diff_output
    
        except GitCommandError as e:
            return f"❌ Diff failed: {str(e)}"
        except Exception as e:
            return f"❌ Diff error: {str(e)}"
  • Pydantic BaseModel defining the input schema/parameters for the git_diff_branches tool.
    class GitDiffBranches(BaseModel):
        repo_path: str
        base_branch: str
        compare_branch: str
        stat_only: bool | None = False
        max_lines: int | None = None
  • Registration of the git_diff_branches handler in the CallToolHandler._get_git_handlers() method, wrapping the core function with error handling and repo validation.
    "git_diff_branches": self._create_git_handler(
        git_diff_branches,
        requires_repo=True,
        extra_args=["base_branch", "compare_branch"],
  • ToolDefinition registration in ToolRegistry.initialize_default_tools(), associating the tool name, schema, and category.
    ToolDefinition(
        name=GitTools.DIFF_BRANCHES,
        category=ToolCategory.GIT,
        description="Show differences between two branches",
        schema=GitDiffBranches,
        handler=placeholder_handler,
        requires_repo=True,
  • Export of the git_diff_branches function from the git module for use in handlers.
    git_diff_branches,
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('show differences') but doesn't describe what the output includes (e.g., commit diffs, file changes), whether it's read-only or has side effects, or any constraints like authentication needs or rate limits. This is a significant gap for a tool with no annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste—it directly states the tool's purpose without redundancy. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 complexity of a diff tool with 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on behavior, parameter meanings, output format, and usage context, making it inadequate for an agent to reliably invoke the tool without additional inference.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate but adds no parameter information. It doesn't explain what 'base_branch', 'compare_branch', or 'repo_path' mean, their expected formats, or how they interact (e.g., order of comparison). With 3 undocumented parameters, the description fails to provide necessary semantic context.

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 the verb ('show differences') and resource ('between two branches'), making the purpose immediately understandable. It distinguishes from siblings like git_diff_staged or git_diff_unstaged by specifying branch comparison, though it doesn't explicitly contrast with git_diff (which might handle other comparisons).

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 versus alternatives like git_diff or other git_* tools. The description implies usage for branch comparisons but lacks explicit context, prerequisites, or exclusions, leaving the agent to infer based on tool names alone.

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

Related 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/MementoRC/mcp-git'

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