Skip to content

Your agent runs the team: start, watch, wait for and stop local workers through MCP - #56

Merged
flujo-app merged 2 commits into
mainfrom
lead-worker-tools
Nov 28, 2026
Merged

flujo-app merged 2 commits into
mainfrom
lead-worker-tools

Conversation

@flujo-app

@flujo-app flujo-app commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Part of #52, on top of #55. Covers item 6 of #46 (a FACTORY MCP server for the supervisor) for workers on this computer; fleets come later.

The agent you already use (Claude Code, Codex, any MCP client) can now run a team through factory-mcp: create it, assign the work, start each worker, wait for news, read the result, stop workers. Nobody has to write code.

What changes

  • Four supervisor tools on factory-mcp (only when it runs as the supervisor, root):
    • factory_start_worker {agentId, provider: claude|codex, instructions?, cwd?, model?, endpointFile?} starts one agent as its own claude -p or codex exec in the background, bound to that agent.
    • factory_workers shows each worker's state and its last steps, read from its output.
    • factory_wait {seconds} returns as soon as a task or worker changes, so the agent does not have to poll or sleep.
    • factory_stop_worker stops a worker and everything it started.
  • MCP instructions. The supervisor's connection tells the agent how to run a team (create, assign, start, wait, read, stop). A worker's connection tells it who it is.
  • Workers wait for free. One program run is one turn. Between turns a small runner watches the board, at no model cost, and starts the next turn only when the agent has something new to do (a review, findings to fix). A worker ends when nothing assigned to it is left open, after 30 turns, or when its program fails. Records and output are kept in <board>.workers/.
  • Built-in worker instructions teach the board for each role (builder, reviewer, coordinator); the supervisor's own text is added after them.
  • Sign-in. A Claude Code worker started from inside a Claude session leaves out that session's own settings (Claude Code refuses to start nested) but keeps the person's own login (ANTHROPIC_API_KEY, CLAUDE_CODE_OAUTH_TOKEN, CLAUDE_CONFIG_DIR). A Codex worker uses the normal Codex login with --ignore-user-config.
  • From code: factory.workers (LocalWorkers): start, list, get, stop.
  • Bug fixed: a Claude Code lite worker started with a prompt never started, because --mcp-config takes several values and Claude Code read the prompt as a config file ("MCP config file not found"). The prompt now comes first.

Checked for real

scripts/local-team-smoke.mjs (npm run smoke:local-team) runs a builder and a reviewer through the MCP tools only, on this Windows PC:

Supervisor Workers Result
this script Claude Code 2.1.289 accepted: handed in after 15 s, accepted after 25 s; the reviewer was woken once
this script Codex 0.163.0 accepted in about 40 s
a real Claude Code, given one plain sentence Claude Code accepted in about one minute; it used create, assign, start, wait, read and reported the poem
a real Claude Code, workers without a login Claude Code, then Codex the workers could not sign in; the supervising agent noticed, restarted them on Codex and finished

That last run showed that Claude Code does not hand its own login to the MCP servers it starts, so the guide explains how to pass one (claude mcp add factory -e CLAUDE_CODE_OAUTH_TOKEN=... -- factory-mcp team.sqlite), which the third run used. The records are in #57 (evidence/local-team-20261128.json).

Also checked: Claude Code 2.1.289 on Windows starts the installed factory-mcp from the packed tarball, with and without cmd /c, and sees the new tools.

Tests

test/local-workers.test.mjs (new, in the CI list, and its MCP test also runs against the installed package): headless commands and argument order; nested-session sign-in; built-in instructions; reading Claude Code and Codex output; a worker started in the background, bound to its agent, with the session's settings left out; a waiting worker woken by a hand-in and ended by acceptance; stopping a worker and its program; a program that cannot start; only the supervisor's connection can start workers, and factory_wait returns on a change.

Local checks (Windows and Linux, as in public-sdk.yml)

Commit bf340d9 (the same files as this branch after rebasing onto main with #54; checked by comparing the git trees), from a clean git -c core.autocrlf=false archive snapshot with a clean npm ci each time. Linux ran in disposable node:*-bookworm-slim Docker containers as the node user.

Platform Node npm audit focused tests Python (Modal, RunPod) packed install, SDK check, CLI help installed MCP tests evidence regressions
Windows v22.17.0 10.9.2 passed 351 passed passed passed 1 passed 7 passed
Windows v24.22.1 11.19.1 passed 351 passed passed passed 1 passed 7 passed
Linux v22.17.0 10.9.2 passed 351 passed passed passed 1 passed 7 passed
Linux v24.22.1 11.19.1 passed 351 passed passed passed 1 passed 7 passed

All four combinations passed.

…cal workers

- factory-mcp (as the supervisor, root) gets factory_start_worker,
  factory_workers, factory_wait and factory_stop_worker, plus MCP
  instructions that teach the agent how to run a team. A worker's own
  connection (--actor) explains its job instead and cannot start workers.
- A local worker runs claude -p or codex exec in the background, bound to
  its agent. Between turns its runner waits for the board at no model cost
  and wakes it when there is something new (a review, findings to fix); it
  ends when nothing assigned to it is left open, after 30 turns, or on an
  error. Records and output are kept in <board>.workers/.
- factory.workers (LocalWorkers) does the same from code.
- Claude Code started from inside a Claude session drops that session's
  settings (Claude Code refuses to nest) but keeps the person's login.
- Fixed: Claude Code read a lite worker's prompt as an MCP config file,
  because --mcp-config takes several values; the prompt now comes first.
- scripts/local-team-smoke.mjs runs a real builder and reviewer through the
  MCP tools, scripted or led by a real Claude Code from a plain request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant