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
Cancelling during an input_required round still runs the remaining input handlers #727
MCP::Client#drive_input_required (lib/mcp/client.rb:822) checks the caller's cancellation: token only when it sends a request. Between requests it does not look at the token:
When an input_required result embeds several requests and the token is cancelled while the first handler runs, fulfill_input_requests (:876) still calls the remaining handlers. These are on_elicitation, on_sampling and on_roots handlers, so a user who cancelled can still be prompted, or a model called.
A requestState-only result is waited out with sleep(backoff) (:852), which cancellation does not interrupt.
CancelledError is raised in both cases, but only once the handlers or the wait are done.
To Reproduce
Save as repro.rb in the repository root and run bundle exec ruby -Ilib repro.rb on main (4962426):
The handler that is running may finish. No further handler is called, and a backoff wait ends as soon as the token is cancelled. docs/_client/cancellation.md says the calling thread is woken with MCP::CancelledError.
Logs
handler: first
handler: second
MCP::CancelledError: user stopped
Ruby 4.0.9.
Additional context
#707 fixed cancellation in the server's legacy input_required shim, which is a separate path.
I have a fix with tests and will open a PR for it.
Activity