工作树工具MCP服务器
使用Claude实现git工作树自动化管理的MCP服务器。使Claude能够自动创建、管理和清理git工作树。
特性
- 自动用户名检测 -从GitHub CLI或git配置
- 全工作台管理 -创建、列出、清理工作树
- 依赖项安装 -自动检测并运行pnpm/npm/yarn
- .env文件复制 -自动复制环境文件
- GitHub集成 -直接从工作树创建PR
- 状态检查 -检查工作台是否清洁并准备进行PR
安装
选项1:npm(全局)
npm install -g worktree-tools-mcp选项2:从GitHub安装
npm install -g git+https://github.com/georgeasoto/worktree-tools-mcp.git选项3:npx(无需安装)
直接与npx一起使用:
npx -y git+https://github.com/georgeasoto/worktree-tools-mcp.git方案4:地方发展
git clone https://github.com/georgeasoto/worktree-tools-mcp.git
cd worktree-tools-mcp
npm install
npm run build
npm linkClaude代码的配置
添加到您的Claude Code配置文件中(通常 ~/.config/Claude/claude_desktop_config.json 或类似):
选项1:使用npx(推荐-始终保持最新)
{
"mcpServers": {
"worktree-tools": {
"command": "npx",
"args": ["-y", "git+https://github.com/georgeasoto/worktree-tools-mcp.git"]
}
}
}选项2:如果全局安装
{
"mcpServers": {
"worktree-tools": {
"command": "worktree-tools-mcp"
}
}
}方案3:地方发展
{
"mcpServers": {
"worktree-tools": {
"command": "node",
"args": ["/Users/YOUR_USERNAME/worktree-tools-mcp/dist/index.js"]
}
}
}添加配置后,重新启动Claude Code以启用MCP服务器。
可用工具
create_worktree
使用自动设置创建新的git工作树。
参数:
ticket(必填):票号(例如“CO-4493”、“PROJ-123”)branchName(必填):分支名称(空格转换为连字符)cwd(可选):工作目录(默认为当前目录)openIde(可选):创建后在IDE中打开(“游标”、“vscode”、“auto”)
例子:
{
"ticket": "CO-4493",
"branchName": "billing feature"
}它的作用:
- 自动检测GitHub CLI或git config中的用户名
- 在以下位置创建工作台
../-worktrees/username/TICKET/branch-name - 创建分支:
username/TICKET/branch-name - 从源/主获取最新更改
- 自动检测并安装依赖项(pnpm/npm/yarn)
- 从主仓库复制所有.env文件
list_worktrees
列出所有带有状态信息的工作树。
参数:
cwd(可选):工作目录
退货:
- 带有分支、路径和状态的工作树数组
- 状态包括:干净/脏,提交前/提交后
cleanup_worktree
删除工作台,并可选择删除其分支。
参数:
worktreePath(必填):要移除的工作台路径deleteBranch(可选):同时删除本地分支(默认值:false)cwd(可选):工作目录
它的作用:
- 删除工作树目录
- (可选)删除本地分支
- 清理空的父目录
worktree_status
获取工作台的状态。
参数:
worktreePath(必填):要检查的工作台路径
退货:
- 清洁/脏污状态
- 领先/落后于大师
- 已准备好进入PR状态
- 人类可读信息
create_pr
从工作树创建GitHub pull请求。
参数:
worktreePath(必填):通往工作台的路径title(可选):PR标题(如果未提供,则由提交自动生成)body(可选):PR主体(如果未提供,则自动生成)draft(可选):创建为PR草稿(默认值:false)
要求:
- GitHub CLI必须经过身份验证(
gh auth login) - 或设置
GITHUB_TOKEN环境变量
退货:
- PR网址
- PR编号
- PR标题
Claude使用示例
配置后,Claude可以自动管理工作树:
示例1:创建新工作台
User: "Create a worktree for ticket CO-1234 called payment integration"
Claude: [calls create_worktree tool]
Claude: "I've created a new worktree at ~/repos/myproject-worktrees/username/CO-1234/payment-integration
with dependencies installed and .env files copied. The worktree is ready to use."示例2:列出所有工作树
User: "Show me all my active worktrees"
Claude: [calls list_worktrees tool]
Claude: "You have 3 active worktrees:
1. CO-1234/payment-integration - 5 commits ahead, clean
2. CO-5678/user-dashboard - 2 commits ahead, uncommitted changes
3. CO-9012/api-refactor - up to date"示例3:从工作台创建PR
User: "Create a PR for my payment integration work"
Claude: [calls create_pr tool]
Claude: "I've created PR #123: 'Add payment integration'
URL: https://github.com/org/repo/pull/123"示例4:清理工作台
User: "Clean up the payment integration worktree"
Claude: [calls cleanup_worktree tool with deleteBranch: true]
Claude: "I've removed the worktree and deleted the local branch."用户名检测
用户名将按此优先级自动检测:
- 手动覆盖 -从
.worktree-configrepo根目录中的文件 - GitHub命令行界面 -用途
gh api user --jq .login - Git配置 -转换
user.name转换为用户名格式(小写、连字符)
如果检测失败,您将收到一条明确的错误消息和说明。
目录结构
工作树组织如下:
~/repos/
├── myproject/ (main repository)
└── myproject-worktrees/ (all worktrees)
└── username/
├── CO-1234/
│ └── payment-integration/
└── CO-5678/
└── user-dashboard/发展
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build
npm run build
# Test the MCP server
npm run build && node dist/index.js配套Bash脚本
此MCP服务器补充了工作树工具bash脚本(位于 ~/.checkout-scripts/ 或 ~/.worktree-tools/).您可以同时使用:
- Bash脚本 -用于手动CLI使用
- MCP服务器 -克劳德自动化
两者都实现了相同的逻辑,可以互换使用。bash脚本提供了一个零依赖的CLI接口,而MCP服务器使Claude能够自动化工作树操作。
需求
- Node.js 18+
- Git
- 可选:GitHub CLI(
gh)更好地检测用户名和创建PR - 可选:
pnpm,npm,或yarn用于依赖项安装
许可证
麻省理工学院
