You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A legacy input_required request cancelled during its replay still gets its result #706
With input_required_legacy_shim, a handler that returns input_required to a pre-2026 client is fulfilled by run_legacy_input_required_shim (lib/mcp/server.rb:1090): it sends each embedded request to the client, re-runs the handler with the answers, and returns the result (:1127). handle_request checks the request's cancellation only before the shim starts (:884), so a cancellation that arrives after the client answered a leg, or while the handler re-runs, is not honored: the handler runs again, remaining legs are still sent, and the final result is sent to the client after its notifications/cancelled. A request the shim is not involved in is suppressed in the same situation (#697).
To Reproduce
On main (00868f7), over StreamableHTTPTransport in SSE mode: a tool returns input_required with one elicitation; the client answers it; while the re-run handler is held, the client sends notifications/cancelled for the request; the handler is released.
The re-run handler sees server_context.cancelled? true, and its result is still written to the stream.
Expected behavior
Once the request is cancelled, the shim sends no further leg, does not re-run the handler, and sends no response, as for any cancelled request.
Logs
See above.
Additional context
A cancellation that arrives while the shim waits for a leg's answer is already honored through the nested-request cancellation hook of the bundled transports; the gaps are the points between legs and around the re-run.
I have a fix with tests and will open a PR for it.
Activity
fix: honor cancellation throughout the legacy input_required shim