Skip to content

factory-server: mcp: let a project append stdio arguments - #242

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

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

Conversation

@moonthebot

@moonthebot moonthebot commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

A stdio MCP server runs inside the worker, so a project needs a way to tune it, such as adding --headless to playwright-mcp. This is PR 3 of 5. Runs do not start stdio servers yet, so a saved list takes effect once worker support lands in a later change.

A project's page for a stdio server has the enabled switch and the five stage checkboxes. It shows the server's command and base arguments read-only. It adds an Extra arguments list for the project, edited one box per argument, with the full command line shown under it. The preview keeps whitespace, quotes an argument that has spaces, and writes line breaks as $'...' escapes. The page has no header fields, no Refresh connection button and no tool list. The project's pipeline panels and MCP servers card list a stdio server too.

The list is stored per project and server in a new project_mcp_args table. Reading it returns an empty list only when no row exists, and a malformed stored list is a store error. Any collaborator of the project may edit it. The arguments reach only that project's workers, and a collaborator already sets the checks command, which is arbitrary bash in the same workers. Turning the server off keeps the list, and a pipeline save leaves it alone. Deleting the server or removing the project deletes it.

The save handler reads the posted pairs in order, and only for a stdio server, then checks them with the registry's argument rules before any write. A violation returns 400 and changes nothing, not the list, the enabled flag or the stages. Posted arg and arg_escaped fields for a remote server are ignored, even when malformed. The check route answers a stdio server with a 400. A login that collaborates on another project alone gets 404 on the page and on a post to it.

Docs

Updated the MCP project settings, MCP connection check, MCP tool toggles and Settings layout rows in docs/design.md. The two rows say a stdio server has neither the check nor tool toggles, and that both need a throwaway container and are a follow-up.

Verification

  • nix develop -c just lint: passed
  • nix develop -c just test: passed, with new store and dashboard tests for order, isolation between projects, keeping the list when off, cleanup on delete and project removal, the 400 cases, the check 4xx and the cross-project 404
  • nix develop -c just check-tests: passed
  • nix develop -c just e2e tests/project-settings.spec.ts: 21 passed, including a test that edits the extra arguments, checks a whitespace-sensitive argument in the preview, keeps the list when the server is toggled off and on, and uses the pipeline panel switch

Signed-off-by: moonthebot tchavadar+moon@protonmail.com

moonthebot and others added 2 commits November 23, 2026 20:56
A project's page for a stdio server has the enabled switch, the stages,
the server's command and base arguments read-only, and an Extra
arguments list stored per project and server.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Decode extra arguments only for a stdio server, fail on a malformed
stored list, show whitespace in the command line preview, and say that
saved arguments take effect once worker support lands.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonthebot
moonthebot merged commit 63f8f1d into main Nov 23, 2026
3 checks passed
@moonthebot
moonthebot deleted the factory/job-76-pr-3 branch November 23, 2026 21:11
moonthebot added a commit that referenced this pull request Nov 23, 2026
## 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>

---------

Co-authored-by: moonthebot <289833623+moonthebot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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