modelcontextprotocol / modelcontextprotocol/python-sdk

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

Đang mở
#1,577 3 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P2 ready for work
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
31

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với entry point streamablehttp_client và đường dẫn ClientSession.call_tool được hiển thị trong client.py, sau đó tái hiện sự cố crash của server.py trong khi gọi công cụ. Hoàn thành khi client báo lỗi kết nối thay vì chờ vô thời hạn nếu server thoát trước khi phản hồi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, networking
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.