Repository navigation
feat: add opt-in whole-argument wildcards for stdio MCP commands - #317
Conversation
## Problem A harness can resolve MCP arguments only at runtime. Exact command matching rejects those values when the operator cannot put them in box.toml in advance. ## Solution Honor complete "*" argument slots when the operator enables experimental-features.mcp-argument-wildcards. Match the executable, argument count, and fixed arguments, and refuse ambiguous server matches. Copy received values into star slots after configured expansion. Check policy against the same effective arguments that the contained server receives. The operator approved the opt-in setting and received-value launch behavior. There are no new MCP fields or protocol changes. Enabled records use version 25; disabled records keep their existing format and behavior. Offline schema generation refuses wildcard commands because no caller supplies their values. Update the configuration, policy, design, and rollback documentation. ## Tests Passed the all-features build, all 725 unit tests, and all 16 runtime_mcp_start tests. wildcard_matching_skips_only_whole_star_arguments_after_opt_in pins matching and the opt-in. wildcard_slots_launch_received_values_without_expanding_them pins actual launch values. wildcard_launches_require_policy_to_permit_the_effective_command pins policy refusal. overlapping_wildcard_commands_start_no_server pins ambiguity. mcp_wildcards_require_opt_in_and_an_enabled_record_version pins record compatibility. offline_schema_generation_refuses_enabled_wildcard_commands pins the offline refusal. The required feature review has found no source defect so far. Full regression, runtime mutation, lint, and containment gates remain in progress at the user's request to publish the draft PR now. Linux compilation is unavailable locally because the target is not installed; Linux CI must cover that platform.
|
Assessment: Request Changes I reviewed head Assumptions and rules checked that held
The tests are thorough: each one fails when the behaviour it covers is removed. |
|
Assessment: Request Changes Re-review at Re-checked at this head, still held
|
|
Assessment: Approve Re-review at Assumptions and rules checked that held
|
Merge upstream/main and resolve configuration and documentation conflicts. Preserve file-attributes and tool grammars; store enabled MCP wildcards as record version 26.
|
Assessment: Approve Re-review at Assumptions and rules checked that held
|
Description
The verified motivating case is Boxy importing a Claude Code MCP configuration. Claude Code documents variable expansion in MCP
args:${VAR}is substituted when set,${VAR:-default}supplies a fallback when unset, and an unset variable without a default is retained literally with a warning. The imported argument and the value Claude Code supplies at launch can therefore differ.Box's existing full-command contract uses the configured command both to identify the MCP server and to construct its launch arguments. It cannot express “keep these arguments fixed, but accept and forward whichever value the caller supplies in this position.” Copying
${TOKEN}does not match Claude Code's substituted credential. Resolving it during import freezes one value, can put a credential inbox.toml, and does not account for a different runtime environment. Matching only the executable would lose the distinction between servers that share launchers such asnpxoruvx.Codex has a different native stdio path. Its configured argument strings are passed to the process launcher without shell interpolation. An ordinary Codex argument
${TOKEN}remains literal. Copying that text into Box's configured command also has a problem: Core expands configured${...}references and supports only its three OTEL values, so a configured${TOKEN}is refused. A wildcard lets Core preserve the literal caller argument without treating it as a configured expansion reference. The examples below distinguish these behaviors rather than assuming all harnesses expand arguments alike.A whole-argument
*accepts the value produced by the caller, whether resolved or literal. Core does not need to reproduce Claude Code's interpolation or default handling.This PR supplies the Core mechanism. Boxy's import changes will follow separately.
Configuration and behavior
Enable argument wildcards for an individual stdio MCP server:
argument_wildcardsdefaults tofalse. Enabling it gives whole-argument*entries their wildcard meaning for that server. With the setting omitted or false, a star remains literal. The setting applies only to stdio MCP servers.The executable, argument count, and fixed arguments still match. An exact command takes priority over a matching wildcard entry. Otherwise one wildcard entry must match. Startup rejects overlapping wildcard entries, including overlaps that appear after configured expansion. Wildcard entries have no specificity ranking.
The launcher forwards caller-supplied wildcard values unchanged, and policy checks the same effective command and arguments that the contained server receives. Core adds no environment-variable parser. Offline
box policy generate-schemarequires concrete arguments because it has no caller supplying wildcard values.The approved interface is a default-off, per-server
argument_wildcardsfield. Enabling it requires stored-record version 26; version 25 remains reserved for main’sfile-attributessetting. Configurations with the flag omitted or false retain their previous record shape. The operator also approved forwarding caller-supplied values, exact-command priority, and startup rejection of overlapping wildcard entries. Any workload process can invoke an MCP alias. A program-onlyshell:spawnpermit matches every value in wildcard positions, and the server runs with its configured permissions. A wildcard in a package or endpoint position therefore delegates that choice to the caller.Examples by harness
The command names and credentials below are illustrative. The expansion behavior is grounded in the linked documentation or source. Patterns assume
argument_wildcards = trueon the MCP entry.1. Claude Code: set or unset environment variable
Claude Code substitutes
TOKENwhen it is set. When it is unset and has no default, Claude Code warns and retains${TOKEN}literally. Both behaviors are documented in environment variable expansion.One fixed reference or credential in
box.tomlcannot express all three possible launches. One wildcard pattern can.2. Claude Code: a reference embedded in an argument
Claude Code's variable substitution applies within an
argsstring. This uses the same documented expansion as example 1.The entire argument becomes
*, so the caller controls its prefix as well as its value.--token=*remains literal text.3. Claude Code: multiple references and a default
Claude Code documents
${VAR:-default}as using the default when the variable is unset. An explicitly empty value counts as set. This example composes those documented substitutions in one argument.Boxy cannot freeze one composed value that covers these runtime environments. Core accepts the resulting argument without parsing the references or selecting a default.
4. Codex: native stdio arguments remain literal
Codex's native stdio configuration stores
argsas strings. The launch path converts them toOsStringand passes them to the process command's.args(&args); it does not invoke a shell to expand them.envandenv_varsconfigure the child's environment separately.Codex's
config.toml(the harness configuration):Here,
env_varsis a Codex setting that forwardsTOKENinto the server's environment. It does not substituteTOKENinto the argument array.Box's
box.toml(using the agreed per-server opt-in):Runtime arguments, even with
TOKEN=credential-ain Codex's environment:Box cannot use
${TOKEN}as a concrete configured argument: its configured-argument expansion rejects names outside the supported OTEL values, and an unexpandable command cannot start. The wildcard receives${TOKEN}as caller data and forwards it literally. Codex supplies that literal text; this is not a claim that Codex substitutes it. Box behavior is pinned bya_server_whose_command_does_not_expand_is_named_and_does_not_startandwildcard_slots_launch_received_values_without_expanding_theminruntime_mcp_start.rs.Sources: Codex MCP configuration, configuration parsing, argument conversion, and process launch.
Direct invocation
Box matches the argument array supplied to the MCP alias and forwards wildcard arguments unchanged.
With
argument_wildcards = trueandcommand = ["example-server", "--token", "*"]:args = ["--token", "${TOKEN}"]andTOKEN=credential-acredential-aTOKEN=credential-a${TOKEN}These examples use direct MCP alias invocations. Strands Shell does not currently route external commands into MCP matching; adding that routing is outside this change.
Type of Change
New feature
Testing
an_otlp_target_receives_the_records_with_the_secret_attachedfailed withno batch carried a verdict, across 8 received. Other completed integration targets passed; the remaining targets were still running when local validation was stopped.CN-I-08/timeout: owned marker readiness. The run and planned isolated/baseline comparisons were not completed.Checklist