Skip to content

Commit c501226

Browse files
committed
fix: timeout 0 means no timeout in ServerSession.send_request
BaseSession applied the timeout with `request_read_timeout_seconds or session_read_timeout_seconds`, so 0 fell through to "no timeout" - ClientSession still reads it that way. The `is not None` check here made the two session classes interpret 0 oppositely.
1 parent 5d59eeb commit c501226

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/mcp/server/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def send_request(
7171
"""
7272
data = request.model_dump(by_alias=True, mode="json", exclude_none=True)
7373
opts: CallOptions = {}
74-
if request_read_timeout_seconds is not None:
74+
if request_read_timeout_seconds:
7575
opts["timeout"] = request_read_timeout_seconds
7676
if progress_callback is not None:
7777
opts["on_progress"] = progress_callback

tests/server/test_session.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ async def test_send_request_omits_call_options_when_none_given():
9999
assert related is None
100100

101101

102+
@pytest.mark.anyio
103+
async def test_send_request_timeout_zero_means_no_timeout():
104+
"""0 falls through BaseSession's `or`-fallback, so it has always meant
105+
"no timeout"; ClientSession still reads it that way."""
106+
dispatcher = StubDispatcher(result={})
107+
session = _make_session(dispatcher)
108+
await session.send_request(types.PingRequest(), types.EmptyResult, request_read_timeout_seconds=0)
109+
assert dispatcher.requests[0][2] is None
110+
111+
102112
@pytest.mark.anyio
103113
async def test_send_request_without_back_channel_or_related_id_fails_fast():
104114
"""No standalone channel and no related request to ride on: raise instead

0 commit comments

Comments
 (0)