|
3 | 3 | import os
|
4 | 4 | import sys
|
5 | 5 | import tempfile
|
| 6 | +import traceback |
6 | 7 | import uuid
|
7 | 8 | from typing import Any, Dict, Optional
|
8 | 9 |
|
9 | 10 | import mcp.types as types
|
10 |
| -from mcp import ClientSession, StdioServerParameters |
| 11 | +from mcp import ClientSession, StdioServerParameters, stdio_client |
11 | 12 | from opentelemetry import trace
|
12 | 13 | from pysignalr.client import CompletionMessage, SignalRClient
|
13 | 14 | from uipath import UiPath
|
|
22 | 23 | from ._context import UiPathMcpRuntimeContext, UiPathServerType
|
23 | 24 | from ._exception import UiPathMcpRuntimeError
|
24 | 25 | from ._session import SessionServer
|
25 |
| -from ._stdio_client import stdio_client |
26 | 26 |
|
27 | 27 | logger = logging.getLogger(__name__)
|
28 | 28 | tracer = trace.get_tracer(__name__)
|
@@ -292,7 +292,35 @@ async def _register(self) -> None:
|
292 | 292 | # We don't continue with registration here - we'll do it after the context managers
|
293 | 293 |
|
294 | 294 | except BaseException as e:
|
295 |
| - logger.error(f"Error during server initialization: {e}") |
| 295 | + # In Python 3.10, ExceptionGroup is in the 'exceptiongroup' module |
| 296 | + # and asyncio.TaskGroup wraps exceptions in ExceptionGroup |
| 297 | + if hasattr(e, "__context__") and e.__context__ is not None: |
| 298 | + logger.error("Sub-exception details:") |
| 299 | + logger.error( |
| 300 | + "".join( |
| 301 | + traceback.format_exception( |
| 302 | + type(e.__context__), |
| 303 | + e.__context__, |
| 304 | + e.__context__.__traceback__, |
| 305 | + ) |
| 306 | + ) |
| 307 | + ) |
| 308 | + elif hasattr(e, "exceptions"): # For ExceptionGroup |
| 309 | + for i, sub_exc in enumerate(e.exceptions): |
| 310 | + logger.error(f"Sub-exception {i + 1}:") |
| 311 | + logger.error( |
| 312 | + "".join( |
| 313 | + traceback.format_exception( |
| 314 | + type(sub_exc), sub_exc, sub_exc.__traceback__ |
| 315 | + ) |
| 316 | + ) |
| 317 | + ) |
| 318 | + else: |
| 319 | + # Log the full traceback of the exception itself |
| 320 | + logger.error("Full traceback:") |
| 321 | + logger.error( |
| 322 | + "".join(traceback.format_exception(type(e), e, e.__traceback__)) |
| 323 | + ) |
296 | 324 |
|
297 | 325 | # Now that we're outside the context managers, check if initialization succeeded
|
298 | 326 | if not initialization_successful:
|
|
0 commit comments