Skip to content

[P28] server: warn about server requests outside a client request (SEP-2260) - #343

Merged
jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p28-request-association-warning
Nov 25, 2026
Merged

jeanmatthieu merged 4 commits into
rel/1.0.0from
conformance/p28-request-association-warning

Conversation

@jeanmatthieu

@jeanmatthieu jeanmatthieu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Part P28 of P0–P35, merged into rel/1.0.0 in order (previous: P27 (#344) · next: P29 (#342))
Branch conformance/p28-request-association-warning
Base conformance/p27-sampling-tools (stacked: GitHub retargets this PR to rel/1.0.0 when the previous part merges)
Commits 31a5243 server: warn about server requests outside a client request (SEP-2260)
a6e309b server: second-pass review fixes (SEP-2260)
fa41939 server: reset the SEP-2260 warnings when the server stops
9d9a873 server: third-pass review fixes (SEP-2260)
Size 14 files, +475 / -45

Summary

SEP-2260 requires sampling/createMessage, elicitation/create and roots/list to 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.send checks 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/list is not checked. The server has no public ping, so no other request needs an exemption.
  • The client answers such requests as before.
  • Server guide, "Requests to the client": the requests in a handler, and roots fetched lazily. The snippet server-requests (Examples/Snippets/Server/MultiRoundTrip.swift) has registerCleanTool, a RootsCache that is stale after list_changed, and watchRoots(cache:), which fetches the roots in the next handler.
  • rough_edges.md lists the warning. CHANGELOG. ROADMAP: SEP-2260 Implemented.
  • Test helpers take a logger: WireExchange(server:logger:) and HandshakeTaskServer(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 on tasks/result, and for roots/list. At 31a5243, swift test passes 1032 swift-testing tests in MCPTests and 108 snippet tests on macOS, and 1124 tests on Linux (scripts/ci-linux.sh build-test).

Review notes

  • Batched requests register their handler tasks like single requests, so a request from a batched handler counts as associated.
  • The warning is logged from the send task, because the server's logger is an async getter.

Verification

  • swift test; DocC with warnings as errors; doc coverage; swift scripts/weave.swift --check.
  • Every conformance leg for client and server; both tier scores.
  • scripts/run-interop.sh --check; Linux scripts/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.

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.
varun06
varun06 previously approved these changes Nov 25, 2026

@varun06 varun06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reviewed and still looking good.

Base automatically changed from conformance/p27-sampling-tools to rel/1.0.0 November 25, 2026 12:52
@jeanmatthieu
jeanmatthieu dismissed varun06’s stale review November 25, 2026 12:52

The base branch was changed.

@jeanmatthieu
jeanmatthieu merged commit 8feeeaa into rel/1.0.0 Nov 25, 2026
@jeanmatthieu
jeanmatthieu deleted the conformance/p28-request-association-warning branch November 25, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants