Skip to main content
Glama
MementoRC

MCP Git Server

by MementoRC

git_create_branch

Create a new branch in a Git repository, optionally specifying a base branch to start from, using the MCP Git Server's branch management tool.

Instructions

Creates a new branch from an optional base branch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_branchNo
branch_nameYes
repo_pathYes

Implementation Reference

  • Core handler function that implements the git_create_branch tool logic using GitPython Repo.create_head() to create a new branch from an optional base branch, with existence checks and error handling.
    def git_create_branch(
        repo: Repo,
        branch_name: str,
        base_branch: str | None = None,
        start_point: str | None = None,
    ) -> str:
        """Create new branch from base - UPDATED VERSION 2024"""
        try:
            # INTEGRATED DEBUG LOGGING
            # Use start_point if provided, otherwise fall back to base_branch
            effective_base = start_point if start_point is not None else base_branch
    
            # Check if branch already exists
            existing_branches = [branch.name for branch in repo.branches]
            if branch_name in existing_branches:
                return f"❌ Branch '{branch_name}' already exists"
    
            # Create new branch
            if effective_base:
                # Verify base branch exists
                if effective_base not in existing_branches and effective_base not in [
                    branch.name for branch in repo.remote().refs
                ]:
                    return f"❌ Base branch '{effective_base}' not found"
    
                repo.create_head(branch_name, effective_base)
            else:
                repo.create_head(branch_name)
    
            return f"✅ Created branch '{branch_name}'"
    
        except GitCommandError as e:
            return f"❌ Branch creation failed: {str(e)}"
        except Exception as e:
            return f"❌ Branch creation error: {str(e)}"
  • Pydantic schema/model for input validation of git_create_branch tool parameters.
    class GitCreateBranch(BaseModel):
        repo_path: str
        branch_name: str
        base_branch: str | None = None
  • Registration of the git_create_branch handler in the GitToolRouter via _get_git_handlers() method, wrapping the operations function with error handling and repo preparation.
    "git_create_branch": self._create_git_handler(
        git_create_branch,
        requires_repo=True,
        extra_args=["branch_name", "base_branch"],
    ),
  • ToolDefinition registration in ToolRegistry for git_create_branch, including schema reference and metadata; handler later overridden by router.
    ToolDefinition(
        name=GitTools.CREATE_BRANCH,
        category=ToolCategory.GIT,
        description="Create a new branch from an optional base branch",
        schema=GitCreateBranch,
        handler=placeholder_handler,
        requires_repo=True,
    ),
  • Protected wrapper for git_create_branch that adds repository binding validation and remote integrity checks before calling the core handler.
    async def protected_git_create_branch(
        self, repo_path: str, branch_name: str, base_branch: str | None = None
    ) -> str:
        """Git create branch with repository binding protection."""
        validated_path = await self._validate_and_prepare_operation(repo_path)
        repo = Repo(validated_path)
        return git_create_branch(repo, branch_name, base_branch)
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits such as whether it requires write permissions, if it validates branch names, what happens on conflicts, or error conditions (e.g., if base branch doesn't exist). 'Creates' implies mutation, but no further details are provided.

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's front-loaded with the core action and includes key detail about the base branch being optional, making it appropriately sized for its purpose.

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 3 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on parameter meanings, behavioral context (e.g., side effects, errors), and return values, making it inadequate for a mutation tool with multiple inputs.

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 0%, so the description must compensate but only mentions 'optional base branch' implicitly referring to one parameter. It doesn't explain the semantics of repo_path (e.g., local path vs. URL) or branch_name (format constraints). Baseline is 3 due to minimal compensation for low coverage.

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 action ('Creates a new branch') and resource ('branch'), specifying it's from an optional base branch. It distinguishes from siblings like git_checkout or git_merge by focusing on creation, but doesn't explicitly differentiate from all siblings (e.g., git_init also creates something).

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 like git_checkout for switching branches or git_init for initializing repos. The description mentions 'optional base branch' but doesn't explain when to specify it versus using default behavior, or prerequisites like needing an existing repo.

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