Skip to main content
Glama
modelcontextprotocol

git MCP server

Official

git_branch

Read-onlyIdempotent

List local, remote, or all Git branches from a repository. Optionally filter branches that contain or do not contain a specific commit.

Instructions

List Git branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the Git repository.
branch_typeYesWhether to list local branches ('local'), remote branches ('remote') or all branches('all').
containsNoThe commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified
not_containsNoThe commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified

Implementation Reference

  • Pydantic model defining the input schema for the git_branch tool: repo_path, branch_type, optional contains/not_contains commit SHAs.
    class GitBranch(BaseModel):
        repo_path: str = Field(
            ...,
            description="The path to the Git repository.",
        )
        branch_type: str = Field(
            ...,
            description="Whether to list local branches ('local'), remote branches ('remote') or all branches('all').",
        )
        contains: Optional[str] = Field(
            None,
            description="The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified",
        )
        not_contains: Optional[str] = Field(
            None,
            description="The commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified",
        )
  • Enum registration of 'git_branch' as GitTools.BRANCH.
    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"
  • Tool registration in list_tools() listing GitTools.BRANCH with its schema.
        Tool(
            name=GitTools.BRANCH,
            description="List Git branches",
            inputSchema=GitBranch.model_json_schema(),
            annotations=ToolAnnotations(
                readOnlyHint=True,
                destructiveHint=False,
                idempotentHint=True,
                openWorldHint=False,
            ),
        )
    ]
  • Handler function that executes the 'git_branch' tool logic: validates inputs, then calls repo.git.branch() with appropriate flags.
    def git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, not_contains: str | None = None) -> str:
        # Defense in depth: reject values starting with '-' to prevent flag injection
        if contains and contains.startswith("-"):
            raise BadName(f"Invalid contains value: '{contains}' - cannot start with '-'")
        if not_contains and not_contains.startswith("-"):
            raise BadName(f"Invalid not_contains value: '{not_contains}' - cannot start with '-'")
    
        match contains:
            case None:
                contains_sha = (None,)
            case _:
                contains_sha = ("--contains", contains)
    
        match not_contains:
            case None:
                not_contains_sha = (None,)
            case _:
                not_contains_sha = ("--no-contains", not_contains)
    
        match branch_type:
            case 'local':
                b_type = None
            case 'remote':
                b_type = "-r"
            case 'all':
                b_type = "-a"
            case _:
                return f"Invalid branch type: {branch_type}"
    
        # None value will be auto deleted by GitPython
        branch_info = repo.git.branch(b_type, *contains_sha, *not_contains_sha)
    
        return branch_info
  • Dispatch in call_tool() that maps 'git_branch' name to the git_branch() handler function, passing extracted arguments.
    case GitTools.BRANCH:
        result = git_branch(
            repo,
            arguments.get("branch_type", 'local'),
            arguments.get("contains", None),
            arguments.get("not_contains", None),
        )
        return [TextContent(
            type="text",
            text=result
        )]
Behavior3/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true, covering the safety profile. The description adds no extra behavioral details (e.g., output format, ordering). Adequate but not enhanced.

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

Conciseness4/5

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

Extremely concise (one sentence) and front-loaded. Efficient for a simple list operation, though slightly under-specified.

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

Completeness3/5

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

With no output schema and a simple list operation, the description is adequate but doesn't specify return format. Annotations cover safety, and sibling context helps, but completeness is minimal.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all four parameters. The description does not add any additional meaning beyond what's in the schema.

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

Purpose5/5

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

The description 'List Git branches' uses a specific verb and resource, clearly indicating the tool's function. It distinguishes itself from siblings like git_create_branch (create) and git_checkout (switch).

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 on when to use this tool versus alternatives (e.g., git_create_branch for creation, git_checkout for switching). The description lacks context on scenarios or exclusions.

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