git_branch
List local, remote, or all Git branches in a repository, optionally filtering by commit history to manage branch visibility.
Instructions
List Git branches
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the Git repository. | |
| branch_type | Yes | Whether to list local branches ('local'), remote branches ('remote') or all branches('all'). | |
| contains | No | The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified | |
| not_contains | No | The commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified |
Implementation Reference
- The core handler function for the 'git_branch' tool. It uses GitPython's repo.git.branch() to list branches filtered by type (local, remote, all), --contains, and --no-contains commit SHAs.def git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, not_contains: str | None = None) -> str: 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
- Pydantic BaseModel defining the input schema for the git_branch tool, including repo_path, branch_type, contains, and not_contains fields.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", )
- src/git/src/mcp_server_git/server.py:343-348 (registration)Registration of the 'git_branch' tool in the server's list_tools() method, providing name, description, and input schema.Tool( name=GitTools.BRANCH, description="List Git branches", inputSchema=GitBranch.model_json_schema(), )
- src/git/src/mcp_server_git/server.py:478-488 (registration)Dispatch logic in the call_tool handler that matches on GitTools.BRANCH and invokes the git_branch function with parsed 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 )]
- src/git/src/mcp_server_git/server.py:108-108 (registration)Enum constant defining the tool name 'git_branch' in GitTools.BRANCH = "git_branch"