Repository navigation
fix(mcp)!: preserve ordinary program execution beside MCP aliases - #357
Conversation
## Problem A declared MCP server installs an alias for its launcher. This alias also intercepts ordinary calls such as npx --version. A call that does not match the server command is refused, so the declaration hides the ordinary program. ## Solution Return a distinct non-match from MCP admission. The alias then searches the agent's PATH, skips its own directory and image, and replaces itself with the ordinary executable inside the existing agent sandbox. Add McpReady and McpUnmatched responses and advance the broker protocol from version 7 to 8. The broker and alias must be upgraded together. Wait for the response before reading stdin, and send readiness before relaying server output. Keep policy denials, invalid expansions, ambiguous matches, and protocol errors as failures. Preserve matched server authorization and add no sandbox grants. Document ordinary fallback, the mistyped-command behavior, and exit statuses. ## Tests unmatched_aliases_preserve_process_inputs_and_skip_their_own_image proves argument, input, environment, working-directory, output, and exit preservation for npx, uvx, and node. It fails against the previous alias implementation. fallback_retains_signal_termination and fallback_closes_inherited_and_broker_descriptors check process termination and descriptor closure. only_a_valid_nonmatch_response_can_execute_fallback rejects invalid routes. the_alias_waits_for_readiness_before_sending_input checks the input boundary. an_mcp_route_that_never_answers_times_out checks the bounded routing wait. ordinary_fallback_keeps_agent_grants_and_never_receives_server_secrets proves the containment boundary with positive controls for matched server access. The final macOS checks pass for all six fallback process tests, 19 MCP startup tests, 37 alias unit tests, and four filesystem_modes tests. The latter caught and now pin preservation of clean stream closure after MCP readiness. The named broker and hosted lifecycle tests pass with readiness consumption. Package build, clippy, formatting, the build without default features, and site_manifest pass. Box has no new warnings. Dependency warnings are unchanged. The doc-test gate has no examples. The example script builds successfully but finds no remaining scripted examples. Documentation review passes. The deterministic suite finishes green with 129 passed and 12 declared Linux-only skips. An image-guard failure from an overlapping rebuild and an elapsed-time failure under load both pass on isolated reruns. tool_grammars::a_push_is_denied_until_a_test_exits_0_and_stays_allowed_after_a_restart still fails because its fake cargo exits 137 instead of 1. The same named test fails with identical output on unchanged base 3eda3e2. Leave this pre-existing host failure outside this change. All other executed package tests pass after the targeted fixes and reruns. Five existing tests remain ignored: two live HTTPS fixtures, two long-running stress tests, and the upstream shell append issue. Native Linux tests have not run. Full cross-compilation is blocked by the missing aarch64-linux-gnu-gcc toolchain on this Mac.
|
Assessment: Comment (approve once the inline suggestion is addressed or declined) Reviewed at 6064d2a. Fallback is correctly limited to an explicit broker non-match, and it runs in the caller's existing sandbox. I found one lookup difference (unset Assumptions and rules checked that held
The fallback tests pin both its process behaviour and its containment. |
An unset PATH became an empty string, which split into one empty entry and searched only the working directory. That directory is usually agent-writable, so a planted program could replace the system one. Fallback now uses /usr/bin:/bin for an absent or empty PATH, matching ProcessConfig::search_path.
|
Assessment: Approve Re-reviewed at 66390a2, which adds the Checked since 6064d2a, all held
|
|
Assessment: Approve Re-reviewed at c4b2342. The only change since 66390a2 is that the unmatched-route record is no longer an Checked at c4b2342, all held
|
Description
Declaring an MCP server through
npxcurrently blocks unrelated calls such asnpx --version. This change lets unmatched commands run the ordinary executable inside the agent's existing sandbox.Examples
Suppose the declared command is
npx -y [email protected], with exact argument matching. Calls through Box'snpxalias behave as follows:npx --versionnpx, if the agent's grants allow itnpx -y [email protected]npx -y [email protected]strands.box.mcp.unmatchedPolicy denials, ambiguous matches, and broker errors still fail closed. They never trigger fallback.
Trade-off
A mistyped server command can now run without Box's MCP tool checks. It receives only the agent's grants and environment, with no declared-server secrets or extra grants.
Operators can find these mismatches through the informational
strands.box.mcp.unmatchedlog in scopestrands-box.mcp. It records the program, redacted arguments, and available request correlation. It carries no policy verdict or ordinary execution outcome. Default targets and targets selectinglogsreceive it. See the approved decision.Why the
!?Previously,
npx --versionwas rejected as an MCP launch. It now gets a response telling the alias to run the realnpx. A denied server launch still gets an error.This changes the broker protocol from version 7 to 8. Old and new binaries cannot communicate, so the broker and alias must be upgraded together.
Execution compatibility
Related Issues
Fixes #354
Type of Change
Bug fix; breaking internal protocol change.
Testing
Telemetry update, macOS ARM64: 1,015 tests passed; one existing HTTPS-dependent test was ignored. Five compilable mutations failed at the intended assertions. Clippy, formatting, the build without default features, site-manifest checks, and independent review passed. Linux was not rerun for this telemetry change.
Earlier fallback validation, Linux: all 27 affected tests pass (run), including fallback containment and secret isolation.
Earlier broad validation, macOS: 1,265 passed, 5 existing ignored. One
tool_grammarstest fails with exit 137 instead of 1; the same failure reproduces on clean base3eda3e2.Package build, Clippy, formatting, no-default-features build, and site-manifest checks pass. Five mutation checks caught the intended defects.
Full workspace and live-agent checks were not run.
I ran the relevant suites (
just check, orcargo test --workspace --all-features)If I touched Rust, I ran
cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.