@@ -29,6 +29,8 @@ def __init__(self, name: str) -> None:
2929 self .session = None
3030 self .name = name
3131
32+ logger .debug (f"initializing client class for { name } " )
33+
3234 @abstractmethod
3335 async def _maintain_session (self ):
3436 pass
@@ -39,7 +41,9 @@ async def _session_maintainer(self):
3941 await self ._maintain_session ()
4042 except Exception as e :
4143 logger .trace (f"failed to maintain session for { self .name } : { e } " )
42- await asyncio .sleep (0.5 )
44+
45+ logger .debug (f"restarting session for { self .name } " )
46+ await asyncio .sleep (0.5 )
4347
4448 async def start (self ):
4549 asyncio .create_task (self ._session_maintainer ())
@@ -122,7 +126,7 @@ async def list_prompts(self) -> ListPromptsResult:
122126 logger .error (f"error listing prompts: { e } " )
123127 return ListPromptsResult (prompts = [])
124128
125- async def _wait_for_session (self , timeout : int = 10 , http_error : bool = True ):
129+ async def _wait_for_session (self , timeout : int = 5 , http_error : bool = True ):
126130 try :
127131 async with asyncio .timeout (timeout ):
128132 while self .session is None :
@@ -132,10 +136,10 @@ async def _wait_for_session(self, timeout: int = 10, http_error: bool = True):
132136 except asyncio .TimeoutError :
133137 if http_error :
134138 raise HTTPException (
135- status_code = 500 , detail = "Could not connect to MCP server."
139+ status_code = 500 , detail = f "Could not connect to MCP server \" { self . name } \" ."
136140 )
137141
138- raise TimeoutError ("Session initialization timed out." )
142+ raise TimeoutError (f"Could not connect to MCP server \" { self . name } \" ." )
139143
140144 assert self .session is not None , "Session is None"
141145
0 commit comments