modelcontextprotocol / modelcontextprotocol/python-sdk

Lazy HTTP connections seem to make error handling difficult.

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

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

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

説明

Question

When using streamablehttp_client, since HTTP connections are initialized with anyio.create_task_group, if the server is unreachable, an error will occur unexpectedly at some point later. Is this the intended behavior? If the connection is impossible, I want to wait and handle the error. However, the current behavior executes the code after the initialization and then throws an error at some point. If the error had occurred earlier, the code below it wouldn't have needed to execute. I consider this excessive optimization. Is there a reason for this design?

Additional Context
import asyncio
from langchain_mcp_adapters.tools import load_mcp_tools
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

async def _init_and_load(session: ClientSession):
    try:
        async with asyncio.timeout(10): # << I cannot access the server and will time out.
            await session.initialize()
            return await load_mcp_tools(session)
    except Exception as e:
        return []

async def main():
    async with streamablehttp_client(url="https://some.unreachable.domain") as client:
        async with ClientSession(client[0], client[1]) as session:
            tools = await _init_and_load(session)
            await asyncio.sleep(100) # << A httpx.ConnectTimeout exception occurred while performing the following operation!!
import asyncio
from langchain_mcp_adapters.tools import load_mcp_tools
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

async def _init_and_load(session: ClientSession):
    try:
        await session.initialize()
        return await load_mcp_tools(session)
    except Exception as e: # << Since the error is caused by tg, this cannot handle the error too!!
        return []

async def main():
    async with streamablehttp_client(url="https://some.unreachable.domain", timeout=10) as client:
        async with ClientSession(client[0], client[1]) as session:
            tools = await _init_and_load(session)
            await asyncio.sleep(100)

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

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

はじめの一歩

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

調査の方向性

streamablehttp_client エントリーポイントとその anyio.create_task_group のセットアップから開始し、asyncio.timeout と timeout=10 を使って到達不能なドメインの例を再現します。httpx.ConnectTimeout が session.initialize() および周囲のコンテキストマネージャーに対していつ表面化するかを追跡し、示されたケースについて、修正済みまたは文書化済みのエラー発生時点を完了の定義とします。

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

評価

技術スタック
python
領域
networking
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

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

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