worktree-tools-mcp

worktree-tools-mcp

Enables Claude to create, manage, and clean up git worktrees automatically, including dependency installation and GitHub PR creation.

Category
访问服务器

README

Worktree Tools MCP Server

MCP server for automated git worktree management with Claude. Enables Claude to create, manage, and clean up git worktrees automatically.

Features

  • Automatic username detection - From GitHub CLI or git config
  • Full worktree management - Create, list, cleanup worktrees
  • Dependency installation - Auto-detects and runs pnpm/npm/yarn
  • .env file copying - Automatically copies environment files
  • GitHub integration - Create PRs directly from worktrees
  • Status checking - Check if worktrees are clean and ready for PR

Installation

Option 1: npm (Global)

npm install -g worktree-tools-mcp

Option 2: Install from GitHub

npm install -g git+https://github.com/georgeasoto/worktree-tools-mcp.git

Option 3: npx (No Installation)

Use directly with npx:

npx -y git+https://github.com/georgeasoto/worktree-tools-mcp.git

Option 4: Local Development

git clone https://github.com/georgeasoto/worktree-tools-mcp.git
cd worktree-tools-mcp
npm install
npm run build
npm link

Configuration for Claude Code

Add to your Claude Code configuration file (typically ~/.config/Claude/claude_desktop_config.json or similar):

Option 1: Using npx (Recommended - Always up to date)

{
  "mcpServers": {
    "worktree-tools": {
      "command": "npx",
      "args": ["-y", "git+https://github.com/georgeasoto/worktree-tools-mcp.git"]
    }
  }
}

Option 2: If installed globally

{
  "mcpServers": {
    "worktree-tools": {
      "command": "worktree-tools-mcp"
    }
  }
}

Option 3: Local development

{
  "mcpServers": {
    "worktree-tools": {
      "command": "node",
      "args": ["/Users/YOUR_USERNAME/worktree-tools-mcp/dist/index.js"]
    }
  }
}

After adding the configuration, restart Claude Code to enable the MCP server.

Available Tools

create_worktree

Create a new git worktree with automatic setup.

Parameters:

  • ticket (required): Ticket number (e.g., "CO-4493", "PROJ-123")
  • branchName (required): Branch name (spaces converted to hyphens)
  • cwd (optional): Working directory (defaults to current)
  • openIde (optional): Open in IDE after creation ("cursor", "vscode", "auto")

Example:

{
  "ticket": "CO-4493",
  "branchName": "billing feature"
}

What it does:

  1. Auto-detects username from GitHub CLI or git config
  2. Creates worktree at ../<repo-name>-worktrees/username/TICKET/branch-name
  3. Creates branch: username/TICKET/branch-name
  4. Fetches latest changes from origin/master
  5. Auto-detects and installs dependencies (pnpm/npm/yarn)
  6. Copies all .env files from main repo

list_worktrees

List all worktrees with status information.

Parameters:

  • cwd (optional): Working directory

Returns:

  • Array of worktrees with branch, path, and status
  • Status includes: clean/dirty, commits ahead/behind

cleanup_worktree

Remove a worktree and optionally delete its branch.

Parameters:

  • worktreePath (required): Path to worktree to remove
  • deleteBranch (optional): Also delete the local branch (default: false)
  • cwd (optional): Working directory

What it does:

  1. Removes the worktree directory
  2. Optionally deletes the local branch
  3. Cleans up empty parent directories

worktree_status

Get the status of a worktree.

Parameters:

  • worktreePath (required): Path to worktree to check

Returns:

  • Clean/dirty status
  • Commits ahead/behind master
  • Ready for PR status
  • Human-readable message

create_pr

Create a GitHub pull request from a worktree.

Parameters:

  • worktreePath (required): Path to worktree
  • title (optional): PR title (auto-generated from commits if not provided)
  • body (optional): PR body (auto-generated if not provided)
  • draft (optional): Create as draft PR (default: false)

Requirements:

  • GitHub CLI must be authenticated (gh auth login)
  • Or set GITHUB_TOKEN environment variable

Returns:

  • PR URL
  • PR number
  • PR title

Usage Examples with Claude

Once configured, Claude can automatically manage worktrees:

Example 1: Create a new worktree

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."

Example 2: List all worktrees

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"

Example 3: Create PR from worktree

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"

Example 4: Clean up worktree

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."

Username Detection

Usernames are automatically detected with this priority:

  1. Manual override - From .worktree-config file in repo root
  2. GitHub CLI - Uses gh api user --jq .login
  3. Git config - Converts user.name to username format (lowercase, hyphens)

If detection fails, you'll get a clear error message with instructions.

Directory Structure

Worktrees are organized as:

~/repos/
├── myproject/                        (main repository)
└── myproject-worktrees/              (all worktrees)
    └── username/
        ├── CO-1234/
        │   └── payment-integration/
        └── CO-5678/
            └── user-dashboard/

Development

# 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

Companion Bash Scripts

This MCP server complements the worktree-tools bash scripts (located at ~/.checkout-scripts/ or ~/.worktree-tools/). You can use both:

  • Bash scripts - For manual CLI usage
  • MCP server - For Claude automation

Both implement the same logic and can be used interchangeably. The bash scripts provide a zero-dependency CLI interface, while the MCP server enables Claude to automate worktree operations.

Requirements

  • Node.js 18+
  • Git
  • Optional: GitHub CLI (gh) for better username detection and PR creation
  • Optional: pnpm, npm, or yarn for dependency installation

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选