Module: MCPClient::JsonRpcCommon::InputWaits
- Included in:
- MCPClient::JsonRpcCommon
- Defined in:
- lib/mcp_client/json_rpc_common/input_waits.rb
Overview
The host's hand on a multi round-trip request that waits on an interaction happening out of band (MCP 2026-07-28 client/elicitation "URL Mode": "Clients SHOULD provide manual controls that let the user retry or cancel the original request"): the pause before each retry of a requestState-only answer is the host's to steer, it never runs past the request timeout, and a stopped request resumes from the continuation its error carries. Mixed into MCPClient::JsonRpcCommon.
Defined Under Namespace
Classes: InputRequiredWait
Instance Method Summary collapse
-
#on_input_required_wait {|wait| ... } ⇒ void
Register the host's control over an out-of-band wait (MCP 2026-07-28 client/elicitation "URL Mode": "Clients SHOULD provide manual controls that let the user retry or cancel the original request").
-
#reject_input_required_discover!(result) ⇒ void
An InputRequiredResult is defined only for tools/call, resources/read and prompts/get (MCP 2026-07-28 basic/patterns/mrtr "Supported Requests").
-
#resume_input_required(error, timeout: nil) ⇒ Object
Resume a multi round-trip request from the continuation an Errors::InputRequiredError carries: the original request goes out again as a new request with the server's requestState echoed and no inputResponses, and the round trip continues from there.
Instance Method Details
#on_input_required_wait {|wait| ... } ⇒ void
This method returns an undefined value.
Register the host's control over an out-of-band wait (MCP 2026-07-28
client/elicitation "URL Mode": "Clients SHOULD provide manual controls
that let the user retry or cancel the original request"). The block is
called with an InputRequiredWait before each paced retry of a
continuation that asked for nothing; it returns :retry to retry at
once, :cancel to stop with an Errors::InputRequiredError
the host can hand to #resume_input_required later, or anything else
to wait the pace and retry.
54 55 56 |
# File 'lib/mcp_client/json_rpc_common/input_waits.rb', line 54 def on_input_required_wait(&block) @input_required_wait_callback = block end |
#reject_input_required_discover!(result) ⇒ void
This method returns an undefined value.
An InputRequiredResult is defined only for tools/call, resources/read and prompts/get (MCP 2026-07-28 basic/patterns/mrtr "Supported Requests"). server/discover is not one of them, so an input_required discover answer is invalid and MUST NOT be applied or cached: the probe would otherwise adopt a protocol version out of an unfinished result and hand that result back as the first heartbeat. The rejection is a ModernServerError, not an InvalidResultError, because a server answering server/discover with a 2026-07-28-only discriminator is modern: the era is settled, so it must never be retried with the initialize handshake, and MCPClient.connect must not send it on to the legacy SSE and HTTP+POST transports either.
35 36 37 38 39 40 41 |
# File 'lib/mcp_client/json_rpc_common/input_waits.rb', line 35 def reject_input_required_discover!(result) return unless MCPClient::JsonRpcCommon.result_type(result) == 'input_required' raise MCPClient::Errors::ModernServerError, 'Server answered server/discover with an input_required result; multi round-trip requests are ' \ "only valid for #{MRTR_METHODS.join(', ')}" end |
#resume_input_required(error, timeout: nil) ⇒ Object
Resume a multi round-trip request from the continuation an Errors::InputRequiredError carries: the original request goes out again as a new request with the server's requestState echoed and no inputResponses, and the round trip continues from there.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mcp_client/json_rpc_common/input_waits.rb', line 66 def resume_input_required(error, timeout: nil) unless error.is_a?(MCPClient::Errors::InputRequiredError) && error.resumable? raise ArgumentError, 'the error carries no continuation to resume' end params = error.request_params.is_a?(Hash) ? error.request_params.dup : {} %w[inputResponses requestState].each do |key| params.delete(key) params.delete(key.to_sym) end params['requestState'] = error.request_state unless error.request_state.nil? ensure_initialized if respond_to?(:ensure_initialized, true) rpc_request(error.request_method, params, timeout: timeout) end |