Repository navigation
Conversation
| end | ||
|
|
||
| if @session_idle_timeout | ||
| unless @session_idle_timeout.nil? |
There was a problem hiding this comment.
session_idle_timeout: false disabled the timeout until now, since the old check tested truthiness. With this change it raises, and together with stateless: true the error is "session_idle_timeout is not supported in stateless mode.", which does not describe the problem. Is refusing false intended? If so, the message for it should say that nil disables the timeout.
There was a problem hiding this comment.
Yes, refusing false is intended: the documented type is [Numeric, nil], and the other duration options of this transport already refuse it. You are right about the message. The value is now checked before the mode, so false raises "session_idle_timeout must be a positive finite number, or nil to disable the timeout." with and without stateless: true, and a test covers both. I also changed the other duration messages to say "positive finite number", since "positive number" does not explain why Float::INFINITY is refused.
| DEFAULT_MAX_STREAM_LIFETIME = DEFAULT_SESSION_IDLE_TIMEOUT | ||
|
|
||
| # Creates a Streamable HTTP transport that can be mounted as a Rack app. | ||
| # Timeouts and keepalive intervals take positive, finite durations in seconds. Optional bounds accept nil. |
There was a problem hiding this comment.
The commit message says that non-finite timeouts are rejected. It does not say that some values that work today stop working: Float::INFINITY for session_idle_timeout and max_stream_lifetime meant "never expire" (the issue notes this), false for session_idle_timeout disabled it, and input_required_max_rounds accepted a Float such as 10.0. Please state these in the commit message, with nil as the way to ask for no limit, so that the release notes can carry it.
There was a problem hiding this comment.
Done, the commit message now has a Breaking Changes section. Checking each value on main showed that my list, and the "two infinite values" in #735, were incomplete. stream_write_timeout: Float::INFINITY and session_idle_timeout: Float::NAN also meant no limit, and nil replaces both.
nil is not the replacement in two cases. input_required_max_rounds does not accept it, so Float::INFINITY there becomes a large Integer. listen_keepalive_interval: Float::INFINITY closed an authenticated stream at its deadline, which nil does not do while the stream is quiet, so the message suggests a large finite number. I corrected #735 and the PR description too.
## Motivation and Context Durations that are not finite were accepted by the transport constructors, and most of them raised `RangeError` later, in the wait that used them. The constructors now require a positive finite number, or `nil` where the option documents it. `input_required_max_rounds` must be a non-negative Integer; `0` still leaves the input to the caller. ## Breaking Changes These values had an effect and now raise `ArgumentError`: - `session_idle_timeout`: `Float::INFINITY`, `Float::NAN` and `false` disabled expiry. Pass `nil`. - `max_stream_lifetime` and `stream_write_timeout`: `Float::INFINITY` meant no limit. Pass `nil`. - `read_timeout` of `MCP::Client::Stdio`: `false` meant no timeout. Pass `nil`. - `listen_keepalive_interval`: `Float::INFINITY` worked on streams with a deadline. Pass a large finite number; `nil` would also stop closing a quiet stream at its deadline. - `input_required_max_rounds`: a Float or Rational was rounded down; pass an Integer. `Float::INFINITY` and `Float::NAN` meant no cap; pass a large Integer, as `nil` is not accepted. A negative number acted as `0`; pass `0`. Fixes modelcontextprotocol#735.
02f6142 to
bcc5ea4
Compare
Transport constructors refuse durations that are not positive and finite, and
MCP::Client.newrefuses aninput_required_max_roundsthat is not a non-negative Integer.Fixes #735
Motivation and Context
Float::INFINITYpasses the checks of the Streamable HTTP server options and ofmax_reconnection_wait, andsession_idle_timeoutalso takesNaN.read_timeoutofMCP::Client::Stdioandinput_required_max_roundsare not checked. Most of the waits these values feed raiseRangeErrorlater, away from the configuration mistake.A private
Duration.positive_finite?now backs all seven duration options. It also refusesComplex, on whichpositive?is not defined.nilstays valid where it is documented.input_required_max_rounds: 0stays valid: no handler runs, andInputRequiredErroris raised for manual driving.How Has This Been Tested?
Automated unit / integration tests
Tested manually
Tested in a real application
test/mcp/server/transports/streamable_http_transport_test.rb: each of the five server options refuses infinite,NaN, complex,falseand string values.The same file: an invalid
session_idle_timeout,falseincluded, is reported as such with and withoutstateless: true.test/mcp/client/http_test.rbandtest/mcp/client/stdio_test.rb:max_reconnection_waitandread_timeoutrefuse infinite,NaN, complex, string and non-positive values, andread_timeoutkeepsnil.test/mcp/client_test.rb:input_required_max_roundsrefusesnil, negative, fractional and infinite values, and0raisesInputRequiredErrorwithout running a handler.Nine of these ten tests fail on
main; the one for0guards existing behavior. Reverting any one check, dropping a documentednil, or dropping any one condition of the predicate fails a test.bundle exec rake test(2,838 tests, 10,447 assertions),bundle exec rake rubocop,bundle exec yard --no-outputandbundle exec rake conformance:test(baseline) pass locally on Ruby 4.0.9.Breaking Changes
Invalid values now raise
ArgumentErrorfrom the constructor. Some of them have an effect today and need a replacement:session_idle_timeout:Float::INFINITY,Float::NANandfalsedisable expiry. Passnil.falsewas also accepted withstateless: true.max_stream_lifetimeandstream_write_timeout:Float::INFINITYmeans no limit. Passnil.read_timeoutofMCP::Client::Stdio:falsemeans no timeout. Passnil, the default.listen_keepalive_interval:Float::INFINITYworks on streams with a deadline, which every authenticated stream has by default. Pass a large finite number.nilwould also stop closing a quiet stream at its deadline.input_required_max_rounds: a Float or Rational is rounded down. Pass an Integer.Float::INFINITYandFloat::NANmean no cap. Pass a large Integer, asnilis not accepted. A negative number behaves like0. Pass0.The messages of the duration options now say "positive finite number", and that of
session_idle_timeoutsays thatnildisables the timeout. An invalidsession_idle_timeoutis reported ahead of stateless mode not supporting the option.Types of changes
Checklist
docs/_client/mrtr.md,docs/_client/transports.md)