Skip to content

feat: support MCP 2026-07-28 over stdio - #350

Merged
notowen333 merged 9 commits into
strands-agents:mainfrom
notowen333:codex/mcp-modern-stdio
Nov 9, 2026
Merged

notowen333 merged 9 commits into
strands-agents:mainfrom
notowen333:codex/mcp-modern-stdio

Conversation

@notowen333

@notowen333 notowen333 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

MCP 2026-07-28 clients do not send initialize. Box required that handshake before tools/list, so these clients connected but could not use any tools.

This adds support for the request metadata, results, and input-answer retries used by that protocol. Requests still pass the catalog and policy checks. A retried call is admitted before its input answers. Continuations retain at most 64 retry allowances, including separate allowances for identical calls. At capacity, a new continuation replaces the oldest allowance. A policy-denied retry releases its allowance. Neither case closes the connection.

Legacy handshakes remain supported. Offline schema discovery probes the server and falls back according to the MCP compatibility rules. If the server closes stdout without replying, discovery restarts it once with initialize first. A valid discovery reply that arrives during the fallback handshake selects a fresh process using modern requests, even if the initialize error arrives first. These paths share one restart within the original deadline. Partial or malformed replies fail discovery. Duplicate JSON keys in server frames are now rejected for both protocol paths.

A server can finish work and suppress its reply after cancellation. Waiting for that reply left executed calls outside response-based policy budgets. Cancelling a modern admitted item call now records one indeterminate mcp:call::response immediately. Late replies add no second event, including input_required. Connection shutdown records remaining admitted item calls after the server stops, and terminal replies are recorded before client delivery can fail. This follows the existing policy rule that uncertain outcomes count; an MCP response does not prove tool success. A valid input_required received before cancellation still records no response. The broker forwards the final buffered frame before closing server stdin and refuses input after EOF, so definitely unsent calls cannot create response events.

Cancellation also releases the request's active slot. Up to 1,024 cancelled request IDs remain reserved for late replies, with the operator-approved 16 MiB budget for retained strings. Exceeding either limit closes the connection and stops the server; other calls may be interrupted and the client must reconnect. The triggering call's outcome is recorded before checking either limit.

The tool-grammar test fixtures now compile small native programs with known exit codes. macOS rejected a copied Apple false executable with a code-signature violation during validation; the replacement preserves contained execution and the existing status and policy assertions.

Configuration keys, policy action names, and Box broker framing are unchanged. The MCP user and design docs cover the behavior and limits.

Related Issues

None linked.

Type of Change

New feature

Testing

  • Passed on this fix: Box and Policy builds with all features; Box without default features; Policy default and no-default builds; Policy default tests (415 passed, six existing ignored); Policy default clippy; and warning-fatal Policy documentation in both feature modes.

  • MCP regressions: all 25 modern-exchange tests passed in the full suite. modern_cancellation_counts_a_call_even_if_the_server_never_replies proves that the second Search is denied with -32001. Targeted mutation checks detect missing or duplicate outcome records, counting a valid input_required, lost accounting during reply delivery, and the active-slot leak. The two new EOF regressions failed before the ordering fix and passed after it.

  • Review: independent code and documentation review findings are resolved. The additional EOF tests prove that the last buffered request reaches the server before input closes, and input after EOF creates no response event.

  • Still running at push cc4ae8d: the combined all-feature Box/Policy suite and remaining lint, formatting, manifest, example, and deterministic-containment gates. The completed 831 Box unit tests report no failures; the final large-directory fixture is still running. These checks are not yet reported as passed. The branch was pushed immediately at the operator’s request.

  • Current CI: the new commit is pushed; CI results are pending. The previous head, 0eba8c9, passed CI, including Linux ARM64 and macOS tests, deterministic containment, lint, packaging, and the site manifest. Those results do not validate this new commit.

  • Live test passed at d15ee53: Claude Code 2.1.318 with mcp-server-time==2026.10.28 returned the real UTC time and reported the policy denial for convert_time. Separate client checks passed modern discovery, direct modern startup, and legacy startup. Captured server frames contained allowed calls and no denied calls.

  • Live client caveat: Boxy base eed1942 required a temporary policy-generation patch from ip to Core's ip4/ip6 fields. That patch is not part of this PR.

  • Live SDK scope: the earlier smoke test was not repeated for this fix; its local credentials and runtime prerequisites are unavailable.

  • I ran the relevant suites; completed and pending checks are listed above

  • All remaining validation gates have completed

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

MCP 2026-07-28 carries version and capabilities on each request. A modern client
can discover a server but Box refuses its tools/list because no initialize
handshake occurred. The time server reproduces the failure with Claude Code.

## Solution

Validate modern request metadata and route its requests through the existing
catalog and policy admission. Preserve legacy error and timeout fallback.
Validate modern replies before catalog capture. Bind input-answer retries to
original parameters and server state, decide each nested method, and record a
response event only for the terminal reply. Bound pending state and retain
cancelled IDs until their late reply arrives. Probe modern servers during
offline schema discovery. Update the MCP operator and mechanism documentation.

The user authorizes the MCP protocol behavior change. No configuration key,
policy action name, containment rule, or broker framing changes. Protocol
extension result types remain refused until their semantics can be validated.

## Tests

modern_stdio_lists_and_calls_with_or_without_discovery proves modern startup.
modern_metadata_is_checked_on_every_request pins version and capability checks.
modern_tool_calls_still_require_catalog_and_policy_admission and
modern_tool_arguments_still_meet_the_generated_policy_action pin policy checks.
modern_input_answers_are_correlated_and_decided_before_forwarding pins nested
policy admission, retry identity, and terminal response accounting.
modern_pending_request_and_continuation_limits_are_enforced and
modern_input_requests_require_capabilities_and_unambiguous_methods pin bounds.
modern_cancellation_ignores_late_replies_and_reserves_the_id pins cancellation.
a_failed_modern_probe_can_fall_back_to_the_legacy_handshake and
a_pending_probe_does_not_prevent_legacy_timeout_fallback pin legacy fallback.
Offline discovery tests pin modern pagination, modern errors, legacy fallback,
and rejection of partial frames across timeout. The schema generation suite
passes all 20 cases. Adversarial mutation tests prove each new regression fails
when its relevant behavior is removed or broken.

Package and helper builds, no-default-features build, formatting, and clippy pass.
Clippy has no owned warnings; six existing vendored Shell warnings remain.
The deterministic suite has 129 passes and 12 declared Linux-only skips.
The full workspace run is still in progress when this draft commit is created.
Three runtime_mcp_policy_staging concurrency tests time out in the parallel run;
isolated reruns remain pending. These cases do not use the modern discovery probe.
A filesystem test passes after an overlapping build stops replacing its helper.
The Linux cross-check lacks the target standard library. No Linux success is claimed.
Live tests against this commit follow after the draft PR is opened. Preliminary
contained modern and legacy probes pass; Claude startup still times out before
its tool catalog is available. This does not establish Claude end-to-end success.
@notowen333 notowen333 changed the title Support MCP 2026-07-28 over stdio fix: support MCP 2026-07-28 over stdio Nov 6, 2026
@notowen333 notowen333 changed the title fix: support MCP 2026-07-28 over stdio feat: support MCP 2026-07-28 over stdio Nov 6, 2026
@notowen333
notowen333 marked this pull request as ready for review November 6, 2026 19:29
Comment thread crates/box/src/run/broker/mcp/server.rs Resolved
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Assessment: Request Changes

Admission, retry binding, and legacy compatibility work as described. There are two lifecycle gaps: continuations that clients abandon eventually make the connection fail, and a slow-starting modern-only server fails offline discovery. Both are reproduced in local tests and described in the inline comments.

What I checked and found correct
  • A retry has to match the original method and canonical params plus the server's requestState. A forged state, changed arguments, or an invented input ID is refused before forwarding.
  • The outer call meets its catalog and policy checks before its input answers get any mcp:call decision. If the outer call is refused, no answer is decided or forwarded.
  • -32022/-32021/-32020 keep the connection modern, and any other probe error or a silent probe allows initialize. This matches the stdio backward-compatibility rules in the 2026-07-28 spec.
  • A legacy connection in Active keeps its existing routing. server/discover and modern _meta requests on that connection are refused.
  • After a cancellation, the late reply is dropped and no ::response event is recorded, which matches the spec's "ignore the response after cancel" rule.
  • An input_required result records no mcp:call::response, and the terminal reply is recorded under the retry's request ID.
  • A slow legacy server's late probe error is skipped correctly, and a server that exits on the probe is restarted once with initialize.
  • Root AGENTS.md treats observable protocol additions and temporal-observation semantics as frozen surfaces that need explicit approval. The PR documents both in docs/user/ and docs/design/. Please confirm that approval explicitly when the PR leaves draft.

The tests are thorough on the refusal paths. The gaps above are lifecycle cases that they do not cover yet.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review of d15ee53 against 95a9ea2)

Both lifecycle issues from the previous review are fixed, and each fix has a regression test. I found no new correctness issues in the follow-up commit. All 24 protocol_2026_07_28 tests pass locally.

What I checked and found correct
  • A retry uses up its continuation only after its input IDs match. A forged ID, a reused request ID, or a request that would exceed the pending-request cap is refused without using up the real continuation.
  • At the cap, the oldest continuation is evicted and the connection stays up. A retry for an evicted continuation gets -32602.
  • A late DiscoverResult leads to exactly one restart with a modern tools/list, whether the discovery reply or the initialize error arrives first.
  • A slow legacy server's late -32601 still completes the legacy handshake. I ran this locally.
  • The exit-on-probe restart and the late-modern-discovery restart share one allowance, so discovery cannot restart twice.
  • Still open from last round: approval for the frozen-surface change in root AGENTS.md (the new protocol era, and input_required recording no ::response) should be stated when the PR leaves draft.

A cancelled modern call's late reply was dropped without recording
mcp:call::response, so an agent could cancel each call right after sending
it and keep calls the server ran out of ::response budgets and sequencing
rules. The broker still hides the late reply from the client, but now
records the response leg unless the reply is a valid input_required.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 9b1d373 against d15ee53)

The new commit 1961973 correctly records the response leg for a cancelled call when its late reply arrives. It has an unhandled case: a cancelled request whose late reply never comes. That case fills the modern pending cap (see the inline comment, reproduced locally). This was already true at d15ee53, and I missed it last round.

What I checked and found correct
  • A late complete reply after a cancel is hidden from the client and records mcp:call::response, so cancelling right after sending no longer slips past ::response temporal rules.
  • A late, well-formed input_required reply records no response leg. A malformed late reply counts as a response, which fails closed.
  • Cancelling a tools/list still fails catalog capture and records no call leg.
  • Legacy cancellation is unchanged and still forwarded.
  • The merge's syscall census change (112 → 113 workload entries, 116 rules) matches the merged permit table. permit_filter_has_113_workload_entries_and_one_installer_entry passes on Linux. This fixes a count conflict between two PRs merged to main.
  • Still open: the frozen-surface approval required by root AGENTS.md for the new protocol era and the ::response recording semantics. 1961973 changes those semantics again, so the approval should cover it.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 0eba8c9 against 9b1d373)

The pending-slot exhaustion from last round is fixed. One case is still open: the cancellation bypass that 1961973 targets still works against servers that drop the reply to a cancelled call, which is how the TypeScript SDK behaves (see the inline comment, reproduced locally). All 28 protocol_2026_07_28 tests pass.

What I checked and found correct
  • After 64 or more cancelled calls that the server never answers, ordinary modern calls still complete. Repeating a cancel for the same ID uses no extra capacity.
  • cancelled is always a subset of modern_requests: every removal path removes from both, so the active subtraction cannot underflow.
  • A late reply to a retained cancellation is still hidden. A complete reply records ::response, and an input_required reply records nothing.
  • Reaching the 1,024-ID or 16 MiB cancellation limit closes the connection, and both user docs and design docs describe this.
  • 298d46c changes only macOS tool-grammar test fixtures.
  • Still open: the frozen-surface approval required by root AGENTS.md for the new protocol era and the ::response recording semantics.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of cc4ae8d against 0eba8c9)

The cancellation bypass is closed. I found no new correctness problem in this commit. All 54 mcp::exchange tests pass locally, along with my earlier reproduction that cancels a call the server never answers.

What I checked and found correct
  • Cancelling an admitted modern item call records ::response once, before the retention limits are checked. A repeated cancel or a late reply (including input_required) records nothing more.
  • Closing the connection records each admitted call that has not yet received a reply, for every exit path: client stop, server EOF, error, and box cancellation. The pending list is taken out before recording, so nothing is recorded twice.
  • A terminal reply is now recorded before it is sent to the client. If recording fails, that reply is dropped and the connection closes (fails closed), and the user docs describe this.
  • At EOF, the last unterminated frame is handled before server stdin is closed. Pending client frames are always processed before the next input event is read, so no earlier frame is skipped. Input after EOF is refused.
  • Removing the call text from the retained-bytes count is correct, because cancelled calls no longer stay in decided_calls.
  • dogwood.rs and outcome.rs change only comments.
  • Follow-up outside this PR's scope: legacy cancellation is still only forwarded. On a legacy connection, a send-then-cancel call that the server drops stays unrecorded until the connection closes. This behavior already exists on main, and legacy_parameter_names_and_cancellation_keep_their_existing_behavior locks it in.
  • Still open: the frozen-surface approval required by root AGENTS.md for the new protocol era and the ::response recording semantics. This commit extends those semantics to recording at cancellation, recording at close, and recording before delivery. The PR also notes that the full CI gates for cc4ae8d have not finished yet.

@notowen333
notowen333 merged commit f5dbf31 into strands-agents:main Nov 9, 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.

3 participants