- **Modern path (2026-07-28).** A request-plane validation ladder (`_validate_modern`; first failure wins, in python-sdk v2's order — the header rungs run BEFORE the unsupported-version rung): required `_meta` → `-32602`; `MCP-Protocol-Version` / `Mcp-Method` / `Mcp-Name` agreement, the last sentinel-decoded via relay's `_decode_mcp_name` → `-32020`; unsupported version → `-32022` with `data.supported`. Notifications are exempt from the ladder entirely (O9). `_dispatch_modern` then serves the request statelessly from a `ModernBackendPool` child, keyed on the **authenticated principal and NOT on a session** (one shared child under no-auth or a static token, one per OAuth user), with the gateway performing the `initialize` + `notifications/initialized` handshake the modern wire omits and caching the result. `server/discover` is synthesised locally and never forwarded (a legacy child would answer `-32601`); every modern result is stamped `resultType: "complete"`, the six cacheable ops additionally get `ttlMs` (`--cache-ttl-ms`, default 60000) / `cacheScope: "private"`, and every result carries the child's `serverInfo` under `_meta`. Client ids are remapped to a minted `mcp-stdio/serve/` id so concurrent stateless clients sharing one child cannot collide. `subscriptions/listen` is SERVED by serve itself, never forwarded: SCOPE is the listChanged trio (`_LISTEN_FILTER_METHODS`, #374) plus `resourceSubscriptions` (#381, detailed below), honor-all on the three booleans, attach-BEFORE-ack, ack as frame 1 with the honored subset at `params.notifications` and the id at `params._meta[subscriptionId]` (both nestings are load-bearing — a top-level echo is silently ignored by a compliant client). Every frame is stamped with the subscription id. `BackendProcess` fans notifications out to attached `_ListenStream`s (filtering on the reader thread, bounded 1024-deep queue per stream, ≤4 streams per pooled child → `-32603`/503 pre-ack). Endings: gateway shutdown → terminal `resultType: "complete"` frame then close (`signal_end(graceful=True)` + a bounded `drain_listeners`); child death or backlog overflow → abrupt close with NO terminal frame; NEVER a server-sent `notifications/cancelled` (the v2 client settles that as LOST). First ending wins. **#381 added the fourth field, `resourceSubscriptions`**: honoring is entirely LOCAL (child's advertised `resources.subscribe` via `_child_supports_resource_subscribe`, then sanitize + dedup + cap at `_LISTEN_MAX_RESOURCE_SUBSCRIPTIONS=256` with truncate-and-honor), so the ack ships BEFORE any `resources/subscribe` is driven — the drive runs on a background daemon thread and can never stall the ack or the pump. `notifications/resources/updated` gets its OWN routing branch (never folded into `_LISTEN_FORWARDED_METHODS`, which would make any non-empty URI list match every URI and leak across streams); matching is exact string equality, no normalization. URIs are refcounted per child in `BackendProcess._resource_refs` under a dedicated `_sub_lock` HELD ACROSS the send (order `_sub_lock` -> `_lock`, never reversed): subscribe on the first reference, unsubscribe on the last, ids from the existing `_mint_modern_id()`. `_ListenStream.torn_down` closes the async-drive-vs-sync-release race. Failure is reply-then-degrade (log once per URI per stream via `_ListenStream.subscribe_failure_logged`, #388 review, keep honored). `_UNDELIVERABLE_NOTIFICATION_FLAGS` still lists `resources.subscribe` as the DEFAULT, lifted per-child by `_synthesize_discover_result`'s `keep=` on the same predicate the ack uses. **O16 is closed by construction, zero production code**: `notifications/message` is never in any listen-forward set, serve's modern face has no other streaming channel to gate, and SEP-2577 deprecated the feature. Pool lifecycle (#376): entries carry a `holds` checkout refcount (taken by `get_or_create`, released in `_dispatch_modern`'s `finally`) which — together with `has_pending` and the PENDING check — forms the single `_reapable_locked` predicate shared by cap-eviction and the `modern-pool-reaper` idle thread (`--modern-idle-ttl`, 0 = off); `holds` is also #374's attach seam. `--modern-only` refuses legacy callers after the auth gate (GET/DELETE 405 + `Allow`, legacy `initialize` → `-32022`).
0 commit comments