Skip to content

Commit 4ec9769

Browse files
committed
feat: add MCP server with 6 tools for AI agent orchestration
1 parent 5f8cea5 commit 4ec9769

File tree

8 files changed

+450
-0
lines changed

8 files changed

+450
-0
lines changed

CLAUDE.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# workz MCP Integration
2+
3+
workz exposes all its operations as MCP tools so AI agents can manage worktrees directly.
4+
5+
## Setup
6+
7+
```bash
8+
claude mcp add workz -- workz mcp
9+
```
10+
11+
Or add manually to your Claude Code config (`~/.claude/settings.json`):
12+
13+
```json
14+
{
15+
"mcpServers": {
16+
"workz": {
17+
"command": "workz",
18+
"args": ["mcp"]
19+
}
20+
}
21+
}
22+
```
23+
24+
## Available Tools
25+
26+
| Tool | Description |
27+
|------|-------------|
28+
| `workz_start` | Create a worktree with auto-synced deps and env |
29+
| `workz_list` | List all worktrees as JSON |
30+
| `workz_status` | Rich status: branch, dirty state, last commit |
31+
| `workz_sync` | Sync symlinks/env into an existing worktree |
32+
| `workz_done` | Remove a worktree (with optional force) |
33+
| `workz_conflicts` | Detect files modified in multiple worktrees |
34+
35+
## Parallel Agent Workflow
36+
37+
To run parallel agents on independent tasks:
38+
39+
1. Use `workz_start` to create isolated worktrees for each task
40+
2. Each agent gets its own branch, deps, env — no interference
41+
3. Use `workz_conflicts` to check for overlapping file changes before merging
42+
4. Use `workz_done` to clean up when finished

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ categories = ["command-line-utilities", "development-tools"]
1212
clap = { version = "4", features = ["derive"] }
1313
anyhow = "1"
1414
serde = { version = "1", features = ["derive"] }
15+
serde_json = "1"
1516
toml = "0.8"
1617
glob = "0.3"
1718
skim = "0.10"

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,42 @@ workz start feature/x --ai --ai-tool gemini # launches Gemini CLI
232232
workz start feature/y --ai --ai-tool windsurf # launches Windsurf
233233
```
234234

235+
## MCP Server
236+
237+
workz ships a built-in MCP server so AI agents can manage worktrees themselves — no human needed.
238+
239+
### Setup
240+
241+
```bash
242+
claude mcp add workz -- workz mcp
243+
```
244+
245+
Or add to `~/.claude/settings.json`:
246+
247+
```json
248+
{
249+
"mcpServers": {
250+
"workz": {
251+
"command": "workz",
252+
"args": ["mcp"]
253+
}
254+
}
255+
}
256+
```
257+
258+
### Tools exposed to agents
259+
260+
| Tool | Description |
261+
|------|-------------|
262+
| `workz_start` | Create a worktree with auto-synced deps and env |
263+
| `workz_list` | List all worktrees as structured JSON |
264+
| `workz_status` | Rich status: branch, dirty state, last commit |
265+
| `workz_sync` | Sync symlinks/env into an existing worktree |
266+
| `workz_done` | Remove a worktree (with optional force) |
267+
| `workz_conflicts` | Detect files modified in multiple worktrees |
268+
269+
Once configured, Claude Code and other MCP-compatible agents can create and manage worktrees autonomously without any manual setup.
270+
235271
## How It Compares
236272

237273
| Feature | workz | worktrunk | gwq | fracture | branchlet |

src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ pub enum Commands {
8282
base: Option<String>,
8383
},
8484

85+
/// Start an MCP server exposing workz tools to AI agents (stdio transport)
86+
Mcp,
87+
8588
/// Print shell integration script
8689
Init {
8790
/// Shell to generate integration for

src/git.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,13 @@ pub fn merged_branches(base: &str) -> Result<Vec<String>> {
205205
.filter(|b| !b.is_empty() && b != base)
206206
.collect())
207207
}
208+
209+
/// List files with uncommitted changes (staged or unstaged) in a worktree.
210+
pub fn modified_files(path: &Path) -> Result<Vec<String>> {
211+
let output = git_in(path, &["status", "--porcelain"])?;
212+
Ok(output
213+
.lines()
214+
.filter(|l| l.len() > 3)
215+
.map(|l| l[3..].trim().to_string())
216+
.collect())
217+
}

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod cli;
22
mod config;
33
mod git;
4+
mod mcp;
45
mod sync;
56

67
use anyhow::{bail, Result};
@@ -35,6 +36,7 @@ fn main() -> Result<()> {
3536
Commands::Sync => cmd_sync(),
3637
Commands::Status => cmd_status(),
3738
Commands::Clean { merged, base } => cmd_clean(merged, base.as_deref()),
39+
Commands::Mcp => mcp::run(),
3840
Commands::Init { shell } => cmd_init(&shell),
3941
}
4042
}

0 commit comments

Comments
 (0)