Skip to content

feat: add opt-in whole-argument wildcards for stdio MCP commands - #317

Merged
notowen333 merged 4 commits into
strands-agents:mainfrom
notowen333:codex/mcp-argument-wildcards
Nov 5, 2026
Merged

notowen333 merged 4 commits into
strands-agents:mainfrom
notowen333:codex/mcp-argument-wildcards

Conversation

@notowen333

@notowen333 notowen333 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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 in box.toml, and does not account for a different runtime environment. Matching only the executable would lose the distinction between servers that share launchers such as npx or uvx.

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:

[mcp.example]
type = "stdio"
command = ["example-server", "--token", "*"]
argument_wildcards = true

argument_wildcards defaults to false. 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-schema requires concrete arguments because it has no caller supplying wildcard values.

The approved interface is a default-off, per-server argument_wildcards field. Enabling it requires stored-record version 26; version 25 remains reserved for main’s file-attributes setting. 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-only shell:spawn permit 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 = true on the MCP entry.

1. Claude Code: set or unset environment variable

Claude Code substitutes TOKEN when 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.

Claude Code config:
  "command": "example-server", "args": ["--token", "${TOKEN}"]

Box command pattern:
  ["example-server", "--token", "*"]

Claude Code supplies:
  TOKEN=credential-a → ["example-server", "--token", "credential-a"]
  TOKEN=credential-b → ["example-server", "--token", "credential-b"]
  TOKEN unset        → ["example-server", "--token", "${TOKEN}"]

One fixed reference or credential in box.toml cannot 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 args string. This uses the same documented expansion as example 1.

Claude Code config:
  "command": "example-server", "args": ["--token=${TOKEN}"]

Box command pattern:
  ["example-server", "*"]

Claude Code supplies:
  TOKEN=credential-a → ["example-server", "--token=credential-a"]
  TOKEN unset        → ["example-server", "--token=${TOKEN}"]

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.

Claude Code config:
  "command": "example-server",
  "args": ["--auth", "${CLIENT_ID}:${CLIENT_SECRET:-dev-secret}"]

Box command pattern:
  ["example-server", "--auth", "*"]

Claude Code supplies:
  CLIENT_ID=client-a, CLIENT_SECRET=secret-a → ["example-server", "--auth", "client-a:secret-a"]
  CLIENT_ID=client-a, CLIENT_SECRET unset   → ["example-server", "--auth", "client-a:dev-secret"]
  CLIENT_ID=client-b, CLIENT_SECRET=secret-b → ["example-server", "--auth", "client-b:secret-b"]

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 args as strings. The launch path converts them to OsString and passes them to the process command's .args(&args); it does not invoke a shell to expand them. env and env_vars configure the child's environment separately.

Codex's config.toml (the harness configuration):

[mcp_servers.example]
command = "example-server"
args = ["--token", "${TOKEN}"]
env_vars = ["TOKEN"]

Here, env_vars is a Codex setting that forwards TOKEN into the server's environment. It does not substitute TOKEN into the argument array.

Box's box.toml (using the agreed per-server opt-in):

[mcp.example]
type = "stdio"
command = ["example-server", "--token", "*"]
argument_wildcards = true

Runtime arguments, even with TOKEN=credential-a in Codex's environment:

Codex supplies: ["example-server", "--token", "${TOKEN}"]
Box forwards:  ["example-server", "--token", "${TOKEN}"]

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 by a_server_whose_command_does_not_expand_is_named_and_does_not_start and wildcard_slots_launch_received_values_without_expanding_them in runtime_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 = true and command = ["example-server", "--token", "*"]:

Invocation Wildcard argument received and forwarded by Box
Claude Code with args = ["--token", "${TOKEN}"] and TOKEN=credential-a credential-a
Native Codex with the same argument strings and TOKEN=credential-a Literal ${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

  • Final merged tree: all-features build passed, including the rebuilt containment executable; 745 library tests and 35 alias tests passed.
  • Clippy passed with zero Box-owned warnings and six existing vendored Shell warnings. Formatting and the no-default-features build passed.
  • All 13 new behavior tests have failing mutation checks for the safeguards they exercise. Documentation review passed.
  • The examples gate passed with its documented warning that no scripted examples remain. Doctests passed (0 tests).
  • The broader integration run was not fully green: an_otlp_target_receives_the_records_with_the_secret_attached failed with no batch carried a verdict, across 8 received. Other completed integration targets passed; the remaining targets were still running when local validation was stopped.
  • The deterministic containment run reported CN-I-08 / timeout: owned marker readiness. The run and planned isolated/baseline comparisons were not completed.
  • At the operator's explicit request, further local validation was stopped so the branch could be pushed and CI could finish validation. The two observed failures are recorded here without claiming they are baseline failures.
  • Platform coverage is macOS only. The local Linux Rust target is not installed (E0463); Linux validation is delegated to CI.

Checklist

  • I have read the contributing instructions.
  • I have reviewed and understand the code in this change.
  • The change is focused on opt-in MCP argument wildcards.
  • Tests cover matching, launch values, policy refusal, ambiguity, and compatibility.
  • The per-server setting, reference documentation, and merge conflicts are addressed.
  • Complete the remaining validation in CI and assess any reproduced failures.

## 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.
@notowen333 notowen333 changed the title Add opt-in whole-argument wildcards for stdio MCP commands feat: add opt-in whole-argument wildcards for stdio MCP commands Nov 4, 2026
@notowen333
notowen333 marked this pull request as ready for review November 4, 2026 23:53
Comment thread docs/user/mcp.md Resolved
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Request Changes

I reviewed head 0c02115. The matching and launch logic is sound for single servers. I left two blocking comments. Two wildcard-overlapping servers pass startup, and one of them can never start (I proved this with a probe test). The docs also never say that the untrusted workload chooses every * value, or that the policy they teach permits all of those values.

Assumptions and rules checked that held
  • With the flag off, admission still goes through for_command with exact matching, and * stays a literal (wildcard_arguments_remain_literal_without_opt_in).
  • prepare copies received values only at declared * positions. Fixed arguments keep their ${OTEL_*} expansion, and received text is not expanded again.
  • Rebuilding argv after Boundary::translate is safe. Argv is passed through .args() and is not part of the digested containment config, and translate derives no grants from arguments.
  • shell:spawn sees the same effective argv that the leaf execs (args and command), so a forbid on the received value takes effect (wildcard_launches_require_policy_to_permit_the_effective_command).
  • The record version is wired through correctly: v25 is in the accepted list, its stamp is checked against record_version, and a disabled record serializes the same bytes as before.
  • Offline generate-schema refuses a config that enables wildcards and uses them, and accepts the flag-off and concrete-argument forms.

The tests are thorough: each one fails when the behaviour it covers is removed.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Request Changes

Re-review at c21976e. The new commit only changes docs. It resolves the caller-control documentation finding. The finding that one server can pass startup but never start (admission.rs:29) is still open, because the matching and startup-check code hasn't changed.

Re-checked at this head, still held
  • With the flag off, exact matching and a literal * are unchanged.
  • Only the * positions are replaced, and the replacement happens after fixed-argument expansion.
  • shell:spawn sees the effective argv that the leaf execs.
  • New docs claim: the workload cannot add wildcards. This holds, because box.toml is a protected source and the agent can't write it.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Approve

Re-review at ad60912. Both earlier blocking findings are resolved. This commit adds a precedence rule: a command without wildcards wins over a wildcard command. I checked that rule against the cases below and found no wrong result.

Assumptions and rules checked that held
  • Exact command first: server --token abc selects the exact entry in either declaration order. That includes the entry's expanded ${OTEL_*} form. Any other value selects the wildcard entry.
  • Overlap check is exact: it refuses only pairs that one request could match, such as [--token *] with [* abc]. It allows pairs that differ in arity, program, or a fixed argument, and it treats --token=* as literal text.
  • Overlap after expansion: entries that differ only once expanded are refused at hosted.rs before the workload starts, so [${X} * a] and [x b *] with X=x are caught.
  • Flag off: neither new check runs, and matching stays exact with * as a literal (set_argument_wildcards(false) in the runtime test starts the box).
  • Docs: docs/user/mcp.md and docs/design/mcp.md describe both the precedence rule and when overlapping entries are refused.
  • Everything from the earlier rounds still holds: only * positions receive values, shell:spawn sees the effective argv, record v25 is wired through, and the caller-control limits are documented.

Comment thread crates/box/src/record/config/mcp.rs Resolved
Comment thread docs/user/mcp.md Resolved
Comment thread docs/user/mcp.md Resolved
Comment thread docs/user/mcp.md Resolved
Comment thread crates/box/src/record/config/mcp.rs Resolved
Merge upstream/main and resolve configuration and documentation conflicts. Preserve file-attributes and tool grammars; store enabled MCP wildcards as record version 26.
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Assessment: Approve

Re-review at bf66e3d. This commit turns the wildcard setting into a per-server [mcp.<name>] argument_wildcards key, moves the record to version 26 after the rebase onto file-attributes (v25), and runs the overlap check without a global flag. I traced every path that reads the new flag and found no wrong result. The 9 related unit tests pass locally on Linux. Your own checklist still has an open CI item, covering the two integration failures you saw locally.

Assumptions and rules checked that held
  • argument_wildcards = true with no * in the command: has_argument_wildcards() is false, so the server matches exactly. prepare rebuilds the same expanded arguments, and the record stamps v26, as mcp.md says.
  • Literal ["s","*"] beside a wildcard ["s","*"]: both are allowed, because the shared-command key now includes whether the entry has wildcards. A request for s * reaches the literal entry, and other values reach the wildcard entry (literal_star_entry_remains_exact_beside_an_enabled_pattern).
  • Two entries with the same command and no wildcards (one with the flag set but no *): both have has_argument_wildcards() == false, so they are still refused as a shared command.
  • Exact command first, overlap refused at load and again before the workload starts: both still hold. Neither check depends on a global flag any more.
  • The key outside stdio MCP tables: in [agent], [tool.*], or an http MCP entry, the key is refused. The interim [experimental-features] mcp-argument-wildcards key, which was never released, is also refused.
  • Record versions: v26 is in the accepted list, the stamp has to equal record_version(...), a v25 record that carries wildcards is refused, and a record without wildcards serializes byte for byte as before.
  • Wildcard values come only from the declared * positions: prepare reads fixed_arguments(), so a fixed argument that expands to * does not become a wildcard.

@notowen333
notowen333 merged commit da49931 into strands-agents:main Nov 5, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants