Skip to content

Commit 6c3900b

Browse files
authored
Merge pull request #114 from UiPath/fix/update_3_11
fix: proper error handling
2 parents 3f551f7 + a6347fd commit 6c3900b

File tree

5 files changed

+1283
-1335
lines changed

5 files changed

+1283
-1335
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.10
1+
3.11

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[project]
22
name = "uipath-mcp"
3-
version = "0.0.92"
3+
version = "0.0.93"
44
description = "UiPath MCP SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
6-
requires-python = ">=3.10"
6+
requires-python = ">=3.11"
77
dependencies = [
8-
"mcp==1.9.0",
8+
"mcp==1.10.1",
99
"pysignalr==1.3.0",
10-
"uipath>=2.0.71",
10+
"uipath>=2.0.73",
1111
]
1212
classifiers = [
1313
"Development Status :: 3 - Alpha",

src/uipath_mcp/_cli/_runtime/_runtime.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import os
44
import sys
55
import tempfile
6-
import traceback
76
import uuid
87
from typing import Any, Dict, Optional
98

9+
from httpx import HTTPStatusError
1010
from mcp import ClientSession, StdioServerParameters, stdio_client
1111
from mcp.types import JSONRPCResponse
1212
from 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",

src/uipath_mcp/_cli/_runtime/_session.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,16 @@ async def _run_server(self, server_params: StdioServerParameters) -> None:
143143
# Cancel the consumer when we exit the loop
144144
consumer_task.cancel()
145145
try:
146-
await consumer_task
147-
except asyncio.CancelledError:
146+
await asyncio.wait_for(consumer_task, timeout=2.0)
147+
except (asyncio.CancelledError, asyncio.TimeoutError):
148148
pass
149149

150-
except Exception as e:
151-
logger.error(
152-
f"Error in server process for session {self._session_id}: {e}",
153-
exc_info=True,
154-
)
150+
except* Exception as eg:
151+
for e in eg.exceptions:
152+
logger.error(
153+
f"Unexpected error for session {self._session_id}: {e}",
154+
exc_info=True,
155+
)
155156
finally:
156157
stderr_temp.seek(0)
157158
self._server_stderr_output = stderr_temp.read().decode(

0 commit comments

Comments
 (0)