Skip to content

crates: run stdio MCP servers in the worker - #243

Merged
moonthebot merged 3 commits into
mainfrom
factory/job-76-pr-4
Nov 23, 2026
Merged

moonthebot merged 3 commits into
mainfrom
factory/job-76-pr-4

Conversation

@moonthebot

@moonthebot moonthebot commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Stdio MCP servers could be registered and enabled per project, but runs ignored them. This change makes a run start them. It is PR 4 of the stdio MCP series (#240 to #242 came first).

The agent starts the server as a child process inside the worker, so it reaches /work and the worker's localhost. That bypasses the proxy, so there are no stored secrets, no enforced tool toggles and no connection check. Tool calls are read from the agent's output instead.

What changed:

  • The scheduler passes each active stdio server's command, base arguments and the project's extra arguments to the runner. It reads them on every run, so a change applies at the next run.
  • McpConfig now holds an optional proxy. A run with only stdio servers issues no run token and passes no FACTORY_MCP_TOKEN. Remote entries are unchanged.
  • A run with a stdio server writes its MCP config to a file in the job's agent config directory, which the run already mounts. One argv element over 128 KiB makes the kernel refuse to start the container, and 64 arguments of 4096 bytes exceed that. Claude reads --mcp-config /claude/factory-mcp.json. Copilot reads --additional-mcp-config @/copilot/factory-mcp.json. Codex reads [mcp_servers.<name>] tables in its config.toml. The podman flags do not change.
  • The runner writes those files to a temporary file in the same directory and renames it into place. A previous worker can leave a symlink at the name in the reused config directory, and the rename replaces the link where an in-place write would follow it out of the job directory.
  • Claude sets MCP_TIMEOUT=120000 through --settings. Codex sets startup_timeout_sec = 120. Copilot has no startup timeout setting.
  • A failed start becomes an mcp-unavailable warning. Claude reports it in the init line. Copilot is parsed from session.mcp_server_status_changed and session.mcp_servers_loaded.
  • The scheduler records a stdio tool call from the agent's output as an mcp-tool-call row under its job. Remote calls stay recorded by the proxy alone.

Checked against the pinned CLIs (copilot 1.0.114, codex 0.165.0, claude 2.1.330):

  • Claude MCP_TIMEOUT through the settings env works.
  • Codex reads a stdio table from config.toml, and escaped ", \ and spaces round-trip. It emits no event for a failed stdio server, so it gets no warning. docs/design.md says so.
  • Copilot's help documents @path for --additional-mcp-config. Its failed-status events come from the SDK types, and I did not confirm that -p JSON output emits them live. That needs a check on moon.

Docs

docs/design.md: the MCP stdio servers, MCP project settings, MCP proxy, MCP unavailable servers, Job MCP tool calls and Credentials rows, a new MCP stdio isolation row, the Architecture block, and the Claude, Codex and Copilot sections. The playwright-mcp recipe waits for the worker packages PR.

Verification

  • nix develop -c just lint: passed.
  • nix develop -c cargo test --workspace --locked: passed. It includes tests for each agent that pass 64 arguments of 4096 bytes through the file, and tests that a preexisting symlink is replaced and its target stays unchanged.
  • nix develop -c just check-tests: passed.

Signed-off-by: Copilot 223556219+Copilot@users.noreply.github.com

moonthebot and others added 3 commits November 23, 2026 21:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonthebot
moonthebot merged commit 4d0b91a into main Nov 23, 2026
3 checks passed
@moonthebot
moonthebot deleted the factory/job-76-pr-4 branch November 23, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant