modelcontextprotocol / modelcontextprotocol/python-sdk
Lazy HTTP connections seem to make error handling difficult.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 1 Std.
- Gemergte PRs (30 T.)
- 31
Beschreibung
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)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne beim streamablehttp_client-Einstiegspunkt und seiner Einrichtung von anyio.create_task_group; reproduziere die Beispiele für nicht erreichbare Domains mit asyncio.timeout und timeout=10. Verfolge, wann httpx.ConnectTimeout im Verhältnis zu session.initialize() und dem umgebenden Kontextmanager sichtbar wird, und definiere den Abschluss als korrigierten oder dokumentierten Fehlerzeitpunkt für die gezeigten Fälle.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- networking
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100