feat(git): add git worktree tools (list, add, remove) - #4791
Open
karawitan wants to merge 1 commit into
Open
Conversation
Add three new tools to mcp-server-git for managing git worktrees: - git_worktree_list: List all worktrees of a repository - git_worktree_add: Create a new worktree, optionally with a new branch - git_worktree_remove: Remove a worktree, with optional force flag Each tool includes defense-in-depth guards rejecting arguments starting with '-' to prevent flag injection, matching the pattern used by existing tools (git_diff, git_checkout, git_show, etc.). The implementation uses GitPython's low-level `repo.git.worktree` command interface since GitPython does not provide a high-level worktree API. All 55 tests pass (8 new worktree tests + 47 existing), pyright clean, ruff clean. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add three new tools to
mcp-server-gitfor managing git worktrees:git_worktree_list— List all worktrees of a repositorygit_worktree_add— Create a new worktree, optionally creating a new branch for itgit_worktree_remove— Remove a worktree, with optionalforceflag for modified worktreesServer Details
git(mcp-server-git)Motivation and Context
Git worktrees are a standard git feature for working on multiple branches simultaneously in separate directories without stashing. They are commonly used in parallel development workflows (e.g., working on a feature branch while keeping the main branch checked out for quick fixes).
The official
mcp-server-gitcurrently has no worktree support, forcing LLM agents to fall back to shell commands. Several third-party MCP git servers already implement worktree tools (e.g.,mcp-server-git-rs,lileeei/mcp-git-tools,georgeasoto/worktree-tools-mcp), indicating clear demand. Adding this to the reference server provides a consistent, tested, and security-hardened implementation.How Has This Been Tested?
pyright: 0 errors, 0 warningsruff: All checks passedBreaking Changes
None. This is purely additive — three new tools are registered alongside the existing 12.
Types of changes
Checklist
Additional context
Security
Each new tool includes defense-in-depth guards rejecting arguments starting with
-to prevent flag injection, matching the established pattern in existing tools (git_diff,git_checkout,git_show,git_create_branch,git_log,git_branch). Thegit_worktree_removetool is annotated withdestructiveHint=truesince it deletes a working directory.Implementation
GitPython does not provide a high-level worktree API (it only has a
WorkTreeRepositoryUnsupportedexception). The implementation uses GitPython's low-levelrepo.git.worktreecommand interface, which wraps thegit worktreesubcommand directly. This is the same approach the existinggit_branchtool uses (repo.git.branch(...)).Tool annotations
git_worktree_listgit_worktree_addgit_worktree_remove