Skip to content

Client tool call hangs forever if server crashes or connection dies when using streamable-http #1577

Description

@gyang-xai

Initial Checks

Description

If the server dies during a tool call before it sends a response the client will get stuck forever.

Example Code

# server.pyfrommcp.server.fastmcpimportFastMCPimportsysmcp=FastMCP("StatefulServer")
@mcp.tool()defgreet(name: str="World") ->str:
"""Greet someone by name."""sys.exit(0)
returnf"Hello, {name}!"if__name__=="__main__":
mcp.run(transport="streamable-http")
# client.pyimportasynciofrommcpimportClientSessionfrommcp.client.streamable_httpimportstreamablehttp_clientasyncdefmain():
# Connect to a streamable HTTP serverasyncwithstreamablehttp_client("http://localhost:8000/mcp") as (
read_stream,
write_stream,
_,
):
# Create a session using the client streamsasyncwithClientSession(read_stream, write_stream) assession:
# Initialize the connectionawaitsession.initialize()
res=awaitsession.call_tool("greet", {"name": "World"})
print(res)
if__name__=="__main__":
asyncio.run(main())
# Run server.py then client.py# client.py will hang forever in the tool call and never complete. I would expect it to throw an error since the connection died and it will never get a response.

Python & MCP Python SDK

Python 3.13.7
mcp 1.20.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions