Repository navigation
Description
What happened?
A keep_alive=True stdio transport shared by two clients keeps the first client's session settings. StdioTransport.connect() decides whether to reuse the kept-alive session by comparing TransportOptions only (session_class / forward_incoming_headers / backend_mode); the per-client session kwargs — read_timeout_seconds from Client(timeout=...), plus sampling/roots/elicitation handlers, the message handler and client_info — are not compared. The second client therefore talks to a session built for the first client, so its own timeout is silently ignored.
The guard's comment says this is exactly what it is meant to prevent ("handing it to a client that wants different ones would silently give it the first client's behavior"), but session kwargs are not part of the comparison.
Expected: each client's timeout= applies, or the mismatch guard raises like it does for differing TransportOptions.
Example Code
import asyncio
import pathlib
import tempfile
import textwrap
import time
from fastmcp import Client
from fastmcp.client.transports import PythonStdioTransport
server = pathlib.Path(tempfile.mkdtemp()) / "sleep_server.py"
server.write_text(
textwrap.dedent(
"""
import asyncio
from fastmcp import FastMCP
mcp = FastMCP("sleepy")
@mcp.tool
async def sleep(seconds: float) -> str:
await asyncio.sleep(seconds)
return "done"
if __name__ == "__main__":
mcp.run()
"""
)
)
async def run(first_timeout: float, second_timeout: float) -> None:
transport = PythonStdioTransport(script_path=str(server)) # keep_alive defaults to True
async with Client(transport, timeout=first_timeout) as first:
print("first client tools:", [t.name for t in await first.list_tools()])
async with Client(transport, timeout=second_timeout) as second:
started = time.monotonic()
try:
result = await second.call_tool("sleep", {"seconds": 3})
print(
f"second client ({second_timeout}s timeout): {result.data!r} "
f"after {time.monotonic() - started:.2f}s"
)
except Exception as exc:
print(
f"second client ({second_timeout}s timeout) FAILED after "
f"{time.monotonic() - started:.2f}s: {type(exc).__name__}: {exc}"
)
asyncio.run(run(1, 5))
asyncio.run(run(5, 1))Output on d07877e:
first client tools: ['sleep']
second client (5s timeout) FAILED after 1.00s: MCPError: Request 'tools/call' timed out
first client tools: ['sleep']
second client (1s timeout): 'done' after 3.05s
The second line is the same bug in the other direction: a 1 s timeout is ignored and the call runs for 3 s.
Version Information
FastMCP 4.2.0a2.dev10+d07877e (main, 2026-10-29)
Python 3.12.2
Windows 11
Related but distinct: #4471 (a kept-alive transport cannot be reused across concurrently-alive event loops), #5754 / #5760 (config-entry timeout field was ignored, closed).
Activity
BlueX888 commentedon Oct 29, 2026
@HootRock opened #6156 for this, and I independently verified both directions on
914210bwith the reproduction above (details in the PR). The only failing check ischeck-issue-link: it requires the PR author to be assigned to this issue, so a maintainer needs to assign @HootRock (or advise otherwise) before it can merge.Fix kept-alive stdio transports ignoring client timeouts (#6156)
Fix kept-alive stdio transports ignoring client timeouts (#6156)