mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-19 12:04:18 +02:00
Merge pull request #523 from jlowin/server-hang
Avoid hanging on initializing server session
This commit is contained in:
commit
7e2d4ef0ab
1 changed files with 5 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ from contextlib import AsyncExitStack, asynccontextmanager
|
|||
from pathlib import Path
|
||||
from typing import Any, cast
|
||||
|
||||
import anyio
|
||||
import mcp.types
|
||||
from exceptiongroup import catch
|
||||
from mcp import ClientSession
|
||||
|
|
@ -158,10 +159,12 @@ class Client:
|
|||
) as session:
|
||||
self._session = session
|
||||
# Initialize the session
|
||||
self._initialize_result = await self._session.initialize()
|
||||
|
||||
try:
|
||||
with anyio.fail_after(1):
|
||||
self._initialize_result = await self._session.initialize()
|
||||
yield
|
||||
except TimeoutError:
|
||||
raise RuntimeError("Failed to initialize server session")
|
||||
finally:
|
||||
self._exit_stack = None
|
||||
self._session = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue