@@ -180,6 +180,7 @@ async def _verify_async() -> bool: # noqa: C901
180180
181181 # Remote servers
182182 if server .is_remote_server ():
183+ connection_timeout = 10.0
183184 remote_url = server .get_remote_url ()
184185 if remote_url :
185186 # If inline headers are specified (e.g., API key), verify via proxy to honor headers
@@ -230,19 +231,25 @@ async def _list_tools_only() -> Any:
230231 if oauth_info .status in (OAuthStatus .NEEDS_AUTH , OAuthStatus .AUTHENTICATED ):
231232 return True
232233 # NOT_REQUIRED: quick unauthenticated ping
233- # print(f"Pinging remote server '{server.name}' without OAuth")
234- async with FastMCPClient (remote_url , auth = None , timeout = 10.0 ) as client : # type: ignore
235- # print(
236- # f"Pinging remote server '{server.name}' without OAuth - Inside client with-statement"
237- # )
238- await asyncio .wait_for (client .ping (), timeout = 10.0 )
239- # print(
240- # f"Pinging remote server '{server.name}' without OAuth - Inside client with-statement but after ping"
241- # )
242- # print(
243- # f"Pinging remote server '{server.name}' without OAuth - After client with-statement"
244- # )
245- return True
234+ log .debug (f"Establishing contact with remote server '{ server .name } '" )
235+ # Async timeout
236+ async with asyncio .timeout (connection_timeout ):
237+ async with FastMCPClient (
238+ remote_url ,
239+ auth = None ,
240+ timeout = connection_timeout ,
241+ init_timeout = connection_timeout ,
242+ ) as client : # type: ignore
243+ log .debug (f"Connection established to '{ server .name } '; pinging..." )
244+ await asyncio .wait_for (client .ping (), timeout = connection_timeout )
245+ log .info (f"Ping received from '{ server .name } '; shutting down client" )
246+ log .debug (f"Client '{ server .name } ' shut down" )
247+ return True
248+ except TimeoutError :
249+ log .error (
250+ f"MCP remote verification timed out (more than { connection_timeout } s) for '{ server .name } '"
251+ )
252+ return False
246253 except Exception as e : # noqa: BLE001
247254 log .error ("MCP remote verification failed for '{}': {}" , server .name , e )
248255 return False
0 commit comments