33import os
44import sys
55import tempfile
6- import traceback
76import uuid
87from typing import Any , Dict , Optional
98
9+ from httpx import HTTPStatusError
1010from mcp import ClientSession , StdioServerParameters , stdio_client
1111from mcp .types import JSONRPCResponse
1212from opentelemetry import trace
@@ -329,35 +329,11 @@ async def _register(self) -> None:
329329 # We'll handle this after exiting the context managers
330330 # We don't continue with registration here - we'll do it after the context managers
331331
332- except BaseException as e :
333- # In Python 3.10, ExceptionGroup is in the 'exceptiongroup' module
334- # and asyncio.TaskGroup wraps exceptions in ExceptionGroup
335- if hasattr (e , "__context__" ) and e .__context__ is not None :
336- logger .error ("Sub-exception details:" )
332+ except* Exception as eg :
333+ for e in eg .exceptions :
337334 logger .error (
338- "" .join (
339- traceback .format_exception (
340- type (e .__context__ ),
341- e .__context__ ,
342- e .__context__ .__traceback__ ,
343- )
344- )
345- )
346- elif hasattr (e , "exceptions" ): # For ExceptionGroup
347- for i , sub_exc in enumerate (e .exceptions ):
348- logger .error (f"Sub-exception { i + 1 } :" )
349- logger .error (
350- "" .join (
351- traceback .format_exception (
352- type (sub_exc ), sub_exc , sub_exc .__traceback__
353- )
354- )
355- )
356- else :
357- # Log the full traceback of the exception itself
358- logger .error ("Full traceback:" )
359- logger .error (
360- "" .join (traceback .format_exception (type (e ), e , e .__traceback__ ))
335+ f"Unexpected error: { e } " ,
336+ exc_info = True ,
361337 )
362338
363339 # Now that we're outside the context managers, check if initialization succeeded
@@ -395,8 +371,6 @@ async def _register(self) -> None:
395371 }
396372 client_info ["tools" ].append (tool_info )
397373
398- logger .info (client_info )
399-
400374 # Register with UiPath MCP Server
401375 await self ._uipath .api_client .request_async (
402376 "POST" ,
@@ -407,8 +381,10 @@ async def _register(self) -> None:
407381 logger .info ("Registered MCP Server type successfully" )
408382 except Exception as e :
409383 logger .error (f"Error during registration: { e } " )
410- if e .status_code == 400 :
411- logger .error (f"Error details: { e .response .text } " )
384+ if isinstance (e , HTTPStatusError ):
385+ logger .error (
386+ f"HTTP error details: { e .response .text } status code: { e .response .status_code } "
387+ )
412388
413389 raise UiPathMcpRuntimeError (
414390 "REGISTRATION_ERROR" ,
0 commit comments