Repository navigation
[P28] server: warn about server requests outside a client request (SEP-2260) - #343
Merged
jeanmatthieu merged 4 commits intoNov 25, 2026
Merged
Conversation
SEP-2260 requires sampling/createMessage, elicitation/create and roots/list to belong to a client request. 2026-07-28 meets it: it has no server-to-client requests. 2025-11-25 and earlier still allow such requests (their transports say SHOULD, and the 2025-11-25 roots page asks for roots after notifications/roots/list_changed), and 0.12 sent them, so the behavior follows the negotiated revision: the request is sent. A sampling or elicitation request sent while the server handles no client request, or after the handler returned, logs one warning for each method that names the SEP and the remedy. roots/list is not checked. The client answers such requests as before. The server guide shows the requests in a handler and roots fetched lazily (RootsCache: stale after list_changed, fetched in the next handler). rough_edges lists the warning. Tests: one warning for each method outside a handler and after the handler returned; none in a handler, for the multi round-trip bridge, for 2025-11-25 task input on tasks/result, and for roots/list.
- RootsCache keeps no roots fetched while it was invalidated. - The late-request test checks the client's answer, not only that the task ran.
The server logs one warning for each method of a request it sends while it handles no client request (SEP-2260). The set of methods already logged survived Server.stop(), so after a restart a new client's first unassociated sampling/createMessage or elicitation/create was silent. stop() now clears it with the other per-connection state, so each connection gets its own warnings. The new RequestAssociationTests test sends a request outside a handler, restarts the server with a new handshake client, sends it again and expects a second warning; it fails without the fix. It relies on "ci: reset the handshake state when the server stops" (p21-stability) for the second `initialize`.
- At 2026-07-28 a request to the client throws -32600 also outside a handler. Only a handler's context was checked, so a request from a detached task or a task body was sent with the handshake-era warning; a stateless transport drops it, and the call waited for an answer that never came. Outside a handler the connection decides: a negotiated handshake revision sends it, a connection that served a stateless request or a server with no handshake revision throws. - Behind StatelessHTTPServerTransport a request outside a handler throws: there is no stream to send it on. - The guides, troubleshooting, ROADMAP and CHANGELOG say so.
This was referenced Nov 25, 2026
varun06
previously approved these changes
Nov 25, 2026
varun06
left a comment
Contributor
There was a problem hiding this comment.
Already reviewed and still looking good.
varun06
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rel/1.0.0in order (previous: P27 (#344) · next: P29 (#342))conformance/p28-request-association-warningconformance/p27-sampling-tools(stacked: GitHub retargets this PR torel/1.0.0when the previous part merges)31a5243server: warn about server requests outside a client request (SEP-2260)a6e309bserver: second-pass review fixes (SEP-2260)fa41939server: reset the SEP-2260 warnings when the server stops9d9a873server: third-pass review fixes (SEP-2260)Summary
SEP-2260 requires
sampling/createMessage,elicitation/createandroots/listto belong to a client request. At 2026-07-28 the SDK meets it, because that revision has no server-to-client requests. At 2025-11-25 and earlier the server still sends such a request, but a sampling or elicitation request sent while the server handles no client request logs one warning for each method. The warning names the SEP and the remedy.Motivation
2025-11-25 and earlier allow these requests outside a client request: their transports say SHOULD, and the 2025-11-25 roots page asks for roots after
notifications/roots/list_changed. Version 0.12 sent them, and its README showed that pattern for roots. Refusing them would break those applications on the revisions that allow them, so the behavior follows the negotiated revision, and the warning points at the change.Changes
Sources/MCP/Server/Server.swift:Server.sendchecks a sampling or elicitation request. When the server handles no client request (no handler context), or the handler of that request has returned, it logs a warning, once for each method. The request is sent.roots/listis not checked. The server has no publicping, so no other request needs an exemption.server-requests(Examples/Snippets/Server/MultiRoundTrip.swift) hasregisterCleanTool, aRootsCachethat is stale afterlist_changed, andwatchRoots(cache:), which fetches the roots in the next handler.rough_edges.mdlists the warning. CHANGELOG. ROADMAP: SEP-2260 Implemented.WireExchange(server:logger:)andHandshakeTaskServer(logger:).API changes
None.
Behavior changes
At 2025-11-25 and earlier, a sampling or elicitation request that the server sends outside a client request logs one warning for each method. The request is still sent.
Conformance
Baselines unchanged (empty on every leg). Tier scores 100% at both revisions.
Tests
Tests/MCPTests/RequestAssociationTests.swift: one warning for each method outside a handler and after the handler returned; no warning in a handler, for the multi round-trip bridge, for 2025-11-25 task input ontasks/result, and forroots/list. At31a5243,swift testpasses 1032 swift-testing tests inMCPTestsand 108 snippet tests on macOS, and 1124 tests on Linux (scripts/ci-linux.sh build-test).Review notes
Verification
swift test; DocC with warnings as errors; doc coverage;swift scripts/weave.swift --check.scripts/run-interop.sh --check; Linuxscripts/ci-linux.sh build-test.AI usage disclosure: the changes, the tests, the commit messages and this description were written with Claude Opus 5.5 and reviewed by the authors.