Skip to main content
Glama

branch_delete

Delete a specific branch in a Git repository by specifying the branch name and repository path. Enables precise branch management through the Git MCP Server for enhanced Git operations.

Instructions

Delete a branch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesBranch name
pathNoPath to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)

Implementation Reference

  • Primary implementation of the branch_delete tool handler. Validates repository and branch existence, ensures it's not the current branch, executes 'git branch -D <name>', handles errors, manages caching, and returns formatted success message.
    static async branchDelete({ path, name }: BranchOptions, context: GitToolContext): Promise<GitToolResult> {
      const resolvedPath = this.getPath({ path });
      return await this.executeOperation(
        context.operation,
        resolvedPath,
        async () => {
          const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath);
          PathValidator.validateBranchName(name);
          await RepositoryValidator.validateBranchExists(repoPath, name, context.operation);
          
          const currentBranch = await RepositoryValidator.getCurrentBranch(repoPath, context.operation);
          if (currentBranch === name) {
            throw ErrorHandler.handleValidationError(
              new Error(`Cannot delete the currently checked out branch: ${name}`),
              { operation: context.operation, path: repoPath }
            );
          }
          
          const result = await CommandExecutor.executeGitCommand(
            `branch -D ${name}`,
            context.operation,
            repoPath
          );
    
          return {
            content: [{
              type: 'text',
              text: `Branch '${name}' deleted successfully\n${CommandExecutor.formatOutput(result)}`
            }]
          };
        },
        {
          command: 'branch_delete',
          invalidateCache: true, // Invalidate branch cache
          stateType: RepoStateType.BRANCH
        }
      );
    }
  • Registers the 'branch_delete' tool with the MCP server, defining its name, description, and input schema (path and name parameters).
    {
      name: 'branch_delete',
      description: 'Delete a branch',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: `Path to repository. ${PATH_DESCRIPTION}`,
          },
          name: {
            type: 'string',
            description: 'Branch name',
          },
        },
        required: ['name'],
      },
    },
  • Dispatch handler in the tool executor switch statement that validates arguments using isBranchOptions and calls the main GitOperations.branchDelete handler.
    case 'branch_delete': {
      const validArgs = this.validateArguments(operation, args, isBranchOptions);
      return await GitOperations.branchDelete(validArgs, context);
    }
  • Type definition for BranchDeleteOptions interface used in branch operations (though simplified in tool usage).
    export interface BranchDeleteOptions extends GitOperationOptions {
      /** Name of the branch to delete */
      name: string;
      /** Whether to force delete even if not merged */
      force?: boolean;
      /** Also delete the branch from remotes */
      remote?: boolean;
    }
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. 'Delete' implies a destructive, irreversible mutation, but the description doesn't specify consequences (e.g., data loss, inability to undo), permissions required, or error conditions (e.g., if the branch doesn't exist). This is inadequate for a mutation tool with zero 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 extremely concise with just three words, front-loading the core action. There is zero waste or redundancy, making it easy to parse quickly. However, this conciseness comes at the cost of completeness, as noted in other dimensions.

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 tool's complexity (destructive mutation with 2 parameters) and lack of annotations and output schema, the description is incomplete. It doesn't cover behavioral aspects like safety, return values, or error handling. For a delete operation, this gap could lead to misuse by an agent, making it inadequate overall.

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%, with clear descriptions for both parameters ('name' and 'path'), so the schema does the heavy lifting. The description adds no additional meaning about parameters beyond what's in the schema, such as format examples or constraints. Baseline 3 is appropriate as the schema provides sufficient documentation.

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 'Delete a branch' clearly states the verb ('Delete') and resource ('a branch'), making the tool's purpose immediately understandable. It distinguishes from siblings like 'branch_create' or 'branch_list' by specifying the destructive action. However, it doesn't explicitly mention the repository context, which is implied but could be more specific.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., ensure the branch isn't currently checked out), exclusions (e.g., cannot delete protected branches), or related tools like 'tag_delete' for similar operations. Without such context, an agent might misuse it.

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/Sheshiyer/git-mcp-v2'

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