modelcontextprotocol / modelcontextprotocol/python-sdk
Client tool call hangs forever if server crashes or connection dies when using streamable-http
Ouverte
Personne n'a encore pris cette issue.
bug
P2
ready for work
- Langage dominant
- Python
- Étoiles
- 24.3k
- Forks
- 4k
- Merge moyen
- 1 j 1 h
- PR mergées (30 j)
- 31
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le point d’entrée streamablehttp_client et le chemin ClientSession.call_tool présenté dans client.py, puis reproduisez le plantage de server.py lors d’un appel d’outil. C’est terminé lorsque le client signale un échec de connexion au lieu d’attendre indéfiniment si le serveur se termine avant de répondre.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- api, networking
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 55/100