Skip to content

M4: multi-round-trip requests and subscriptions/listen - #5

Merged
t11z merged 2 commits into
mainfrom
claude/jolly-johnson-e4bd7k
Sep 23, 2026
Merged

t11z merged 2 commits into
mainfrom
claude/jolly-johnson-e4bd7k

Conversation

@t11z

@t11z t11z commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR implements milestone M4 from ROADMAP.md: multi-round-trip requests (MRTR) and subscriptions/listen, on both the server and the client side.

Server: MRTR

  • New handler commands for asking the client for input:
    • Request-McpElicitation, in form mode (flat primitive schema subset) or URL mode.
    • Request-McpSampling and Request-McpRoot.
  • -Defer together with Wait-McpInput asks for several inputs in a single round.
  • The request is answered with an InputRequiredResult; on the retry the handler runs again from the start and gets the answer.
  • requestState is signed with HMAC-SHA256 and bound to the method, the target, a digest of the arguments and an expiry. It carries the answers of earlier rounds and $Context.State. It is configured with New-McpServer -RequestStateKey and -RequestStateTtlSeconds.
  • The state is checked before any validation of inputResponses. A bad state or malformed answers fail with -32602. An input type the client did not declare fails with -32021 and data.requiredCapabilities.
  • Works for tools/call, prompts/get and resources/read.

Server: subscriptions

  • subscriptions/listen sends the acknowledgement first, tags every notification with the subscription id and applies the filter strictly.
  • resources/updated also covers sub-resources of a subscribed URI.
  • Over HTTP each listen request gets its own SSE stream. A client that closes its stream is detected at the next keep-alive and dropped.
  • Over stdio, notifications/cancelled ends a subscription. When the server stops, every open subscription gets a complete result.
  • New commands to announce changes: Send-McpToolListChanged, Send-McpPromptListChanged, Send-McpResourceListChanged and Send-McpResourceUpdated.
  • Dynamic registration:
    • Register-* on a running server and the new Unregister-McpTool, Unregister-McpResource and Unregister-McpPrompt notify subscribers.
    • Handlers registered after the start can be called at once; the workers define them on first use.
    • listChanged and resources.subscribe are now declared as true.

Client

  • Connect-McpServer gains -OnElicitation, -OnSampling, -OnRoots and -MaxInputRounds.
  • The retry loop sends requestState back unchanged, and leaves it out when the server sent none.
  • Register-McpSubscription, Unregister-McpSubscription and Receive-McpNotification:
    • Notifications are read in the background: a reader runspace feeding an inbox for stdio and in-memory, and one reader per stream for HTTP, with reconnects.
    • Notifications invalidate the session cache.
    • -Action callbacks run in the caller's runspace.
  • Connect-McpServer -Server now fails immediately for a server object that is already running, instead of waiting for the discover timeout.

Conformance (@modelcontextprotocol/conformance@0.2.0-alpha.11, requirement set 2026-07-28, run locally)

  • Server baseline is empty.
    • All 14 input-required-result-* scenarios pass.
    • The five subscriptions/listen checks in server-stateless pass: ack, subscription id, filter, tools and prompts list changes.
    • No warnings.
  • Client: sep-2322-client-request-state passes (5/5). The only remaining baseline entries are the M6 authorization scenarios.
  • Exit-scenario correction: ROADMAP and implementation plan named server-sse-multiple-streams as an M4 exit scenario. That scenario does not test subscriptions/listen (it was already green); the listen checks are in server-stateless. Both documents are corrected.

Deliberate limitations

  • requestState is signed but not encrypted. AES-GCM encryption and binding to the authenticated principal are recorded under M6.
  • Legacy paths (server-initiated requests, resources/subscribe) come with M5.

Docs

  • New docs/concepts/subscriptions.md; rewritten docs/concepts/mrtr.md.
  • Updated ROADMAP, CHANGELOG, README, about help, docs/conformance.md, docs/development.md and docs/concepts/server-primitives.md.
  • New example examples/elicitation-server.ps1.

Checklist

  • ./build.ps1 -Task CI passes locally. Run locally: Analyze (no findings) and the full Pester suite under Set-StrictMode -Latest (495 passed, 0 failed, 5 skipped). Package and PublishLocal were not run locally because the PowerShell Gallery is blocked in the sandbox; CI covers them.
  • New behaviour is covered by tests:
    • Unit: RequestState.Tests.ps1, InputRequest.Tests.ps1.
    • Integration: InputRequests.Tests.ps1 (raw wire, in-memory client, HTTP), Subscriptions.Tests.ps1 (raw wire, in-memory client, HTTP SSE), and stdio tests against the elicitation example.
  • CHANGELOG.md has an entry under [Unreleased]
  • conformance-baseline.yml shrank (the whole M4 block removed on both sides)
  • Documentation updated

🤖 Generated with Claude Code

https://claude.ai/code/session_01ATyZ6eV1KJ8g6koeUnCdcE


Generated by Claude Code

Server:
- Request-McpElicitation (form and URL mode), Request-McpSampling and
  Request-McpRoot answer tools/call, prompts/get and resources/read with an
  InputRequiredResult; -Defer and Wait-McpInput batch several inputs per round.
- requestState signed with HMAC-SHA256 and bound to method, target, argument
  digest and expiry; it accumulates answers of earlier rounds and the handler's
  $Context.State (New-McpServer -RequestStateKey, -RequestStateTtlSeconds).
  State is verified before inputResponses; failures answer -32602. Missing
  client capabilities answer -32021 with data.requiredCapabilities.
- subscriptions/listen: acknowledgement first, subscription id on every
  notification, strict filter, resource updates for sub-resources, SSE stream per
  listen request over HTTP, stdio cancel, graceful close on shutdown.
- Send-McpToolListChanged/-PromptListChanged/-ResourceListChanged,
  Send-McpResourceUpdated; Register-* on a running server and the new
  Unregister-McpTool/-Resource/-Prompt notify subscribers, and late handlers are
  defined in the workers on first use. listChanged/subscribe declared as true.

Client:
- Connect-McpServer -OnElicitation/-OnSampling/-OnRoots/-MaxInputRounds; the
  retry loop echoes requestState verbatim and omits it when none was sent.
- Register-McpSubscription, Unregister-McpSubscription, Receive-McpNotification
  with background readers (stdio/in-memory inbox pump, one reader per HTTP stream
  with reconnect), cache invalidation and -Action callbacks.

Conformance: server baseline empty; client baseline holds only M6 auth.
Docs: MRTR and subscriptions concepts, roadmap (exit scenarios corrected to
server-stateless), changelog, README, about help, examples/elicitation-server.ps1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ATyZ6eV1KJ8g6koeUnCdcE
A worker enqueues its response before its invocation completes, and the
dispatcher removed the in-flight entry only after the worker finished. A client
that reused the id right after the response (as JSON-RPC allows) could hit the
duplicate-id check and get -32600, which made the Mcp-Param header test in the
HTTP suite fail intermittently. An answered or cancelled entry now moves to a
private key when its id arrives again; Update-McpInFlightRequest still disposes
its worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ATyZ6eV1KJ8g6koeUnCdcE
@t11z t11z self-assigned this Sep 23, 2026
@t11z t11z added the enhancement Type: new feature or request label Sep 23, 2026
@t11z
t11z merged commit aa1abfe into main Sep 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Type: new feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants