Skip to content

A legacy input_required request cancelled during its replay still gets its result #706

Done

Description

@yorzi

Describe the bug

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.

runs=[:first, :rerun, [:rerun_saw_cancelled, true]] cancel_status=202
stream after cancel: ["data: {\"jsonrpc\":\"2.0\",\"id\":5,\"result\":{\"content\":[{\"type\":\"text\",\"text\":\"Hello, Koichi!\"}],\"isError\":false}}\n"]

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

  1. added
    bug
    on Nov 22, 2026
  2. added a commit that references this issue on Nov 25, 2026
    f0b252a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions