Repository navigation
Conversation
With an EventStore configured, every modern listen started a persistence task that never ended on disconnect. The handler was not cancelled and notifications continued to append to the store indefinitely. Bind modern subscriptions/listen to the POST response stream: do not persist or prime it, omit SSE IDs, and cancel the handler on disconnect. Drop correlated server notifications before transport handoff when their request is no longer active. Refs: modelcontextprotocol#1488
|
@baxen is on triage rotation this week and is the reviewer for this one. Labels come from the PR labeler. Please review the change. Automated triage. Labels are a first pass and the assigned maintainer has the final say. |
Dropping an opening listen while the outbound queue was full left its notification route registered without a request handle. The shared send path could also strand a progress-timeout watcher. Reserve queue capacity before registering either route, then enqueue without yielding. Dropping an active listen could silently lose its cancellation notification when the same queue was full, leaving the stdio handler running. Keep the synchronous fast path and retry a full enqueue on the service runtime. A closed queue needs no retry. Refs: modelcontextprotocol#1488
jokemanfire
left a comment
There was a problem hiding this comment.
Verified at a61f464 (not on trust): I ran the two targets your Verification section names, with your feature list minus local:
cargo test -p rmcp --features '<your list>' --test test_streamable_http_event_store --test test_subscriptions
test_streamable_http_event_store: 4 passed
test_subscriptions: 14 passed
Both negative controls reproduce the failures you describe:
- Deleting the fence (
service.rs:1644-1648) makesstdio_fences_inactive_subscriptionsfail in both cases: the stale frame for subscription1arrives where the test expects the uncorrelatednotifications/tools/list_changed, sotest_subscriptions.rs:489sees a non-null_meta.subscriptionId. - Restoring
if let Some(event_store)attower.rs:1654(dropping!long_lived &&) makesmodern_listen_bypasses_event_store_and_cancels_on_disconnectfail on both cases with the priming frame the test forbids:data:/id: event-0/retry: 1000.
I also checked that the sessionful path cannot serve a listen: 2026-07-28 requests are always stateless (tower.rs:228-231) and legacy versions get -32601 for subscriptions/listen, so gating only stateless_sse_response is complete rather than a partial fix.
Two things I would like your read on:
1. The fence drops silently for IDs that are merely not local (service.rs:1644-1648). The predicate is "not in local_ct_pool", not "known-cancelled", and it applies to every protocol version, as the PR says. A downstream bridge that relays an upstream subscription and forwards the notification with the upstream _meta.subscriptionId intact now loses live frames with no diagnostic — from its side the subscription looks quiet rather than broken. Rewriting the id is the bridge's job, so dropping is defensible, but could the drop emit a tracing::debug! (or count it) so a mis-rewriting bridge is diagnosable? Right now responder.send(Ok(())) tells the sender the frame was delivered. Related: the fence keys on request ID only, so the window you describe at 1640-1642 (id reuse after a completed listen) resolves as "a new request with the same id un-fences the stale frame", which is only safe because the response round trip has happened — worth a sentence in the comment if that is the reasoning.
2. spawn_service_queue_task has no depth bound (service.rs:1428, used from try_cancel_request at 1064-1070). Each cancel that meets a full queue spawns a detached task holding a tx clone and one message; nothing caps how many such tasks wait, and nothing logs a give-up. The old code dropped the frame instead, which was also wrong but bounded. Is a single ordered drain task (or a bounded wait plus an explicit drop log) preferable to N detached sends? A second, smaller edge: the handle is captured in Peer::new (service.rs:894), so a Peer that outlives its runtime and is dropped afterwards now calls Handle::spawn on a shut-down runtime where it previously did nothing.
No approve from me on this pass — point 1 is a diagnosability question rather than a defect, so it should not block, but I would like to see your answer first.
Shared seams: server handler discovery and custom dispatch, the core listen filter and client acceptance, custom-message Debug, and Streamable HTTP routing headers. Existing server capabilities and custom dispatch do not change unless events() returns Some; the client opts in explicitly. Refs: modelcontextprotocol#1488
Shared seams: the Events registry, descriptor hooks and one-shot poll dispatch from PR 2a. No extra core or transport seams change. Nothing in existing server dispatch changes unless events() returns Some. Refs: modelcontextprotocol#1488
Add the non-default `events` feature to the crate feature table. Refs: modelcontextprotocol#1488
Keep the synchronous send fast path and drain deferred cancellations in order from the service loop instead of spawning a task per cancellation. Log closed-service drops and identify fenced subscription frames by request ID without changing how their producers are acknowledged. Refs: modelcontextprotocol#1488
|
Thanks for checking both of these. Pushed ec2dd25.
|
Serve events/stream with ordered delivery, replay, and heartbeat checkpoints, and add one managed subscription stream for push and poll. Add webhook delivery behind events-webhook and Standard Webhooks verification behind events-webhook-receiver. Also treat an absent resultType as complete, use the tools rules for Events routing headers, and drop Descriptor::transform and the raw payload validator. Refs: modelcontextprotocol#1488
604f281 to
d6aeeb6
Compare
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Closes #1488.
Motivation and Context
This adds the Events extension (SEP-3415, Beta) for MCP 2026-07-28 and later. A server opts in by returning an
EventsServerfromServerHandler::events(), and a client usesEventsClient. Whileevents()returnsNone(the default), dispatch and advertised capabilities are unchanged, so servers that handleevents/*inon_custom_requestkeep working.It's split across three non-default features, which only use crates rmcp already depends on:
events:server/discoveradvertisement,events/list,eventsListChangedonsubscriptions/listen,events/poll, and push overevents/stream, withMcp-NameandMcp-Param-*headers on Streamable HTTP. An event is backed either by an app-provided check with its own cursors or by an in-memory replay buffer fed throughEmitHandle::emit.EventsClient::subscribereturns one stream for push or poll.events-webhook-receiver:verify_webhookfor Standard Webhooks signatures, andsubscribe_webhook/unsubscribe_webhookon the client.events-webhook: webhook delivery from the server. It requires an authenticated principal, checks consent with a signed challenge before delivering, delivers only over HTTPS and, by default, only to public addresses, and keeps grants in memory with a finite lifetime.Left out, since the spec makes them optional: Ed25519 (
v1a) signatures, the well-known receiver document, durable or non-expiring webhook grants, and suspension.Two core fixes apply without any of these features, and they're in their own commits:
EventStoreconfigured, a 2026-07-28subscriptions/listenwas persisted for replay and kept running after the client disconnected. It's now tied to its response stream and cancelled on disconnect. Other requests are still persisted for replay as in feat: add distributed Streamable HTTP event store #1024.subscriptionIddoesn't match a live request on that connection, including one a proxy forwards with upstream_metaunchanged. A cancellation that hits a full outbound queue is sent once there's room instead of being dropped.I can move these to a separate PR if you'd rather ship them as fixes first.
How Has This Been Tested?
Added unit tests and stdio and Streamable HTTP integration tests, with webhook delivery tested over loopback TLS. The existing conformance suites still pass. There are no Events scenarios to run yet (modelcontextprotocol/conformance#521 and #541 are open).
Breaking Changes
None.
Types of changes
Checklist
I used AI assistance to implement and test this.