Repository navigation
fix(mcp): forward only server-wide globals and refuse per-command flags at startup - #52
Merged
Merged
Conversation
`mcp` forwarded every global flag given on its command line to each tool call's child. Flags that describe one command broke the server: `mcp --debug --screenshot x.html` failed every tool other than snapshot and click from the first call (including `desktop_skills_get`, which the server instructions say to read first), and every snapshot or click after the first, because the debug file is create-once. `mcp --wait-for` failed every tool without a post-action wait the same way. Each global now has an explicit scope. Server-wide flags (--session, --agent-id, --headed, --trace, --trace-strict, --verbose) are forwarded as before. Per-command flags (--debug, --screenshot, --wait-for, --wait-for-gone, --wait-timeout) and any global without a scope make `mcp` print an INVALID_ARGS envelope with a suggestion and exit 1 before it serves anything. A test fails when a new global flag has no scope. The process test that used --debug to show globals reach every call now uses an invalid --agent-id, and the server instructions no longer list --wait-for as a server flag. Item 11 of the upstream register `vercel-labs#602`.
gshost1
added a commit
that referenced
this pull request
Nov 8, 2026
…warding --verbose Review of the first change found gaps in how `mcp` refuses its flags: - The refusal envelope went to stdout, which an MCP client reads as JSON-RPC, so the user never saw why the server exited. It now goes to stderr through the same JSON writer the CLI uses, and an argument error exits 2 like every other argument error. - An invalid --session or --agent-id was forwarded and failed every call. `mcp` now checks both once with the child's own validators. - A non-UTF-8 value was forwarded after a lossy conversion, which could point a child at a different --trace file. It is now refused. - The long-name check ran before the scope check, so a short-only global would have been dropped silently, and a global missing from the scope table got the per-command message. Both are now an internal error that says the flag is not classified for mcp. - --verbose only produced child stderr that the server buffers and then discards. It is now server-only: it turns on the server's own debug log and is not forwarded. The tests now check the refusal while stdin is still open, prove valid values reach the child through the trace it writes, and clean up their scratch directory. The module is renamed to global_forward and its entry point to collect_forwarded_globals. main.rs gains a small write_response helper so the refusal reuses the envelope writer instead of copying it.
gshost1
added a commit
that referenced
this pull request
Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
agent-desktop mcpforwarded every global flag given on its command line to every per-call child. The visual-debug flags (--debug,--screenshot=PATH) and the post-action wait flags (--wait-for,--wait-for-gone,--wait-timeout) belong to one command, not to a server. Withmcp --debug --screenshot x.html, every tool other than snapshot and click failed from the first call (INVALID_ARGS "--debug supports snapshot and click only", includingdesktop_skills_get, which the server's instructions tell clients to read first), and every snapshot or click after the first failed with "Cannot create debug output", because the path is created once. With--wait-for, every tool without a post-action wait failed. This makes each global's scope explicit and hasmcprefuse per-command flags before serving. Ledger rows STATE-4 and BINARY-9.State before and after
Scope of each global
--session--agent-id--headedLeaseRole::of_callreads it--trace--trace-strict--trace--verbose--debug,--screenshot--wait-for,--wait-for-gone,--wait-timeoutWhat changed
src/mcp/global_scope.rs(new):GlobalScope { ServerWide, ServerOnly, PerCommand }and the table above.src/mcp/global_forward.rs(new, moved frommod.rs):collect_forwarded_globals(scope by id, startup validation of--sessionwithresolve_active_sessionand--agent-idwithvalidate_agent_id, UTF-8 check) andrefuse_start.src/main.rs:emit_responsesplit so the envelope writer (write_response) can target stderr; the refusal reuses it.src/mcp/mod.rs: module declarations and the call site; the server instructions no longer list--wait-for.src/tests/mcp_process.rs:mcp_server_global_flags_reach_every_callasserted the old behavior (it expected "--debug supports snapshot and click only"); it now runs a call with a valid--traceand--sessionand checks the child's trace records that session. New refusal test keeps stdin open and requires the server to exit by itself.apps/docs/content/docs/guides/mcp.mdx,docs/json-output.md(exit codes),README.md, one sentence inAGENTS.md.Prior art: none upstream; item 11 of the open upstream issue
#602register. Upstream#587(open, read-only server mode) also editssrc/mcp/mod.rs; the logic lives in new files to keep that diff small.How tested
Each test fails with its rule broken and passes with it:
visual_debug_flags_are_refused_and_never_forwarded(audit sketch; onmain,forwarded_globalsreturned["--debug", "--screenshot=/tmp/x.html"]) andpost_action_wait_flags_are_refused_before_or_after_mcp.mcpwith the debug flags, the wait flags, or an invalid--agent-idexits by itself within 20 s with code 2, empty stdout and the envelope on stderr. (Envelope back on stdout with exit 1: fails on the code, then on "stdout is JSON-RPC only"; reading stdin before refusing: times out.)--verbosenot forwarded; identity validation; short-only and unclassified flags refused with their own codes;--sessionreaches the child's trace.Gates on head
bab3f4d5(main42b97e61merged in): fmt, clippy-D warnings, source-rule and architecture scripts, core Windows check, Win32 leakage check,cargo tree, host-set tests 4833 passed, 0 failed. Re-cycled ontomain3fce1ebb(PRs #47, #49, #51 changedCargo.lock,crates/core/src/lib.rs,docs/json-output.md) as24c0ac10: gates green on a re-run (4900 passed, 0 failed; the first run failed only the batch CLI flake, now root-caused as the batch's 5 s permission preflight), CI 13/13 green.Review: a high code review and a security review. The security review found nothing exploitable; its non-UTF-8 note and the code review's stdout, exit-code, short-flag, verbose and validation findings are applied here.
Security
The refusal happens before any file is opened or stdin is read, and the error names the flags, never their values, so a screenshot path does not appear. Forwarded values keep the
--flag=valueform (one argv element each), tool-call arguments cannot set globals, and non-UTF-8 values are refused instead of being altered.Performance
One table lookup per global at startup.
Risks
mcp --wait-for ...(and the other per-command flags) now fails at startup with exit 2 instead of on each call; it never worked except for snapshot and ref actions.--wait-foris not available through MCP at all until it becomes a per-call argument.mcp --verbosenow logs the server's own activity instead of being passed to children.AGENT_DESKTOP_SESSION/AGENT_DESKTOP_AGENT_IDin the server's environment are still checked only by each child.main, not changed: the server reads each child's stderr with no size limit.What's left
--wait-foras a per-call argument on the snapshot and ref-action tools;version --debug --screenshot x.htmlstill fails on the CLI because visual debug is validated before the version arm (BINARY-9 remainder). Merge rule: rules 1 and 2 (head hasmain3fce1ebbmerged in, gates and CI green on it, GitHub reports CLEAN,maindid not move during CI).