@@ -642,7 +642,7 @@ async def _list_server_tools(
642642 async with streamable_http_client (url , http_client = http_client ) as (
643643 read ,
644644 write ,
645- _ ,
645+ * _ ,
646646 ):
647647 async with ClientSession (read , write ) as session :
648648 init_result = await session .initialize ()
@@ -672,6 +672,25 @@ async def _list_server_tools(
672672 ]
673673
674674
675+ def _log_mcp_server_error (ord_id : str , exc : BaseException ) -> None :
676+ # Unwrap ExceptionGroup from anyio to surface the real HTTP error body
677+ if isinstance (exc , BaseExceptionGroup ):
678+ for inner in exc .exceptions :
679+ _log_mcp_server_error (ord_id , inner )
680+ return
681+ if isinstance (exc , httpx .HTTPStatusError ):
682+ logger .error (
683+ "Failed to load tools from %s (HTTP %d): %s" ,
684+ ord_id ,
685+ exc .response .status_code ,
686+ exc .response .text [:500 ],
687+ )
688+ else :
689+ logger .exception (
690+ "Failed to load tools from %s — skipping" , ord_id , exc_info = exc
691+ )
692+
693+
675694async def get_mcp_tools_customer (
676695 credentials : CustomerCredentials ,
677696 system_token : str ,
@@ -689,16 +708,14 @@ async def get_mcp_tools_customer(
689708
690709 Returns:
691710 List of MCPTool objects from all servers.
692-
693- Raises:
694- AgentGatewaySDKError: If integrationDependencies is empty.
695711 """
696712 dependencies = credentials .integration_dependencies
697713
698714 if not dependencies :
699- raise AgentGatewaySDKError (
715+ logger . warning (
700716 "integrationDependencies is empty in credentials — no MCP servers configured."
701717 )
718+ return []
702719
703720 logger .info ("Discovering tools from %d MCP server(s)" , len (dependencies ))
704721
@@ -717,8 +734,8 @@ async def get_mcp_tools_customer(
717734 server_tools = await _list_server_tools (url , system_token , timeout )
718735 tools .extend (server_tools )
719736 logger .debug ("Loaded %d tool(s) from %s" , len (server_tools ), dep .ord_id )
720- except Exception :
721- logger . exception ( "Failed to load tools from %s — skipping" , dep .ord_id )
737+ except Exception as exc :
738+ _log_mcp_server_error ( dep .ord_id , exc )
722739
723740 logger .info (
724741 "Loaded %d MCP tool(s) from %d server(s)" , len (tools ), len (dependencies )
@@ -758,7 +775,7 @@ async def call_mcp_tool_customer(
758775 async with streamable_http_client (tool .url , http_client = http_client ) as (
759776 read ,
760777 write ,
761- _ ,
778+ * _ ,
762779 ):
763780 async with ClientSession (read , write ) as session :
764781 await session .initialize ()
@@ -769,4 +786,9 @@ async def call_mcp_tool_customer(
769786 return ""
770787
771788 first = result .content [0 ]
772- return str (getattr (first , "text" , "" ))
789+ text = str (getattr (first , "text" , "" ))
790+
791+ if result .isError :
792+ logger .error ("Tool '%s' returned an error: %s" , tool .name , text )
793+
794+ return text
0 commit comments