modelcontextprotocol / modelcontextprotocol/python-sdk

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

Open
#1,577 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 ready for work
Dominant language
Python
Stars
24.3k
Forks
4k
Avg merge
1d 1h
Merged PRs (30d)
31

Description

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.py

from mcp.server.fastmcp import FastMCP
import sys

mcp = FastMCP("StatefulServer")

@mcp.tool()
def greet(name: str = "World") -> str:
    """Greet someone by name."""
    sys.exit(0)
    return f"Hello, {name}!"


if __name__ == "__main__":
    mcp.run(transport="streamable-http")


# client.py

import asyncio

from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client


async def main():
    # Connect to a streamable HTTP server
    async with streamablehttp_client("http://localhost:8000/mcp") as (
        read_stream,
        write_stream,
        _,
    ):
        # Create a session using the client streams
        async with ClientSession(read_stream, write_stream) as session:
            # Initialize the connection
            await session.initialize()

            res = await session.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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the streamablehttp_client entry point and the ClientSession.call_tool path shown in client.py, then reproduce the server.py crash during a tool call. Done means the client reports a connection failure instead of waiting forever when the server exits before responding.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.