git_delete_branch
Remove a branch from a Git repository to clean up your project's branch structure. Specify the repository path and branch name to delete it.
Instructions
Delete a branch from the repository.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the local Git repository | |
| branch_name | Yes | The name of the branch to delete | |
| force | No | Whether to force deletion |
Implementation Reference
- Core handler function that implements the git_delete_branch tool. Validates input, checks if branch is current, deletes using simpleGit, and returns structured MCP response.export async function handleGitDeleteBranch({ repo_path, branch_name, force = false, }) { try { const git = simpleGit(repo_path); // Get current branch to prevent deleting the active branch const currentBranch = await git.branch(); if (currentBranch.current === branch_name) { return { content: [ { type: "text", text: JSON.stringify( { error: "Cannot delete the currently checked out branch" }, null, 2 ), }, ], isError: true, }; } // Delete the branch if (force) { await git.deleteLocalBranch(branch_name, true); } else { await git.deleteLocalBranch(branch_name); } return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Deleted branch: ${branch_name}`, branch: branch_name, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to delete branch: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:188-209 (schema)Input schema definition and description for the git_delete_branch tool, included in the toolsList for MCP tool discovery.name: "git_delete_branch", description: "Delete a branch from the repository.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, branch_name: { type: "string", description: "The name of the branch to delete", }, force: { type: "boolean", description: "Whether to force deletion", default: false, }, }, required: ["repo_path", "branch_name"], }, },
- src/server.js:910-910 (registration)Registers the git_delete_branch tool name to its handler function in the server's handlersMap object for fast request dispatching.git_delete_branch: handleGitDeleteBranch,
- src/handlers/index.js:14-19 (registration)Imports the handleGitDeleteBranch handler from branch-operations.js into the handlers index module.import { handleGitBranchDiff, handleGitCheckoutBranch, handleGitDeleteBranch, handleGitMergeBranch, } from "./branch-operations.js";
- src/handlers/index.js:55-58 (registration)Re-exports handleGitDeleteBranch from the handlers index module for convenient import in server.js.handleGitBranchDiff, handleGitCheckoutBranch, handleGitDeleteBranch, handleGitMergeBranch,