modelcontextprotocol / modelcontextprotocol/python-sdk

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

オープン
#1,577 コメント 3 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug P2 ready for work
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

streamablehttp_client エントリーポイントと client.py に示されている ClientSession.call_tool のパスから始め、次にツール呼び出し中に発生する server.py のクラッシュを再現します。サーバーが応答する前に終了した場合、クライアントがいつまでも待機するのではなく接続失敗を報告すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api, networking
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。