Skip to content

Commit b6e14fb

Browse files
authored
Merge pull request #152 from UiPath/feat/error_code
feat(error_code): add error code to McpRUntimeError
2 parents 591654f + ad3109c commit b6e14fb

File tree

4 files changed

+1323
-1181
lines changed

4 files changed

+1323
-1181
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[project]
22
name = "uipath-mcp"
3-
version = "0.0.103"
3+
version = "0.0.104"
44
description = "UiPath MCP SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"
77
dependencies = [
88
"mcp==1.11.0",
99
"pysignalr==1.3.0",
10-
"uipath>=2.1.54, <2.2.0",
10+
"uipath>=2.1.108, <2.2.0",
1111
]
1212
classifiers = [
1313
"Development Status :: 3 - Alpha",
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
from typing import Optional
1+
from enum import Enum
2+
from typing import Optional, Union
23

3-
from uipath._cli._runtime._contracts import UiPathErrorCategory, UiPathRuntimeError
4+
from uipath._cli._runtime._contracts import (
5+
UiPathBaseRuntimeError,
6+
UiPathErrorCategory,
7+
UiPathErrorCode,
8+
)
49

510

6-
class UiPathMcpRuntimeError(UiPathRuntimeError):
11+
class McpErrorCode(Enum):
12+
CONFIGURATION_ERROR = "CONFIGURATION_ERROR"
13+
SERVER_NOT_FOUND = "SERVER_NOT_FOUND"
14+
REGISTRATION_ERROR = "REGISTRATION_ERROR"
15+
INITIALIZATION_ERROR = "INITIALIZATION_ERROR"
16+
17+
18+
class UiPathMcpRuntimeError(UiPathBaseRuntimeError):
719
"""Custom exception for MCP runtime errors with structured error information."""
820

921
def __init__(
1022
self,
11-
code: str,
23+
code: Union[McpErrorCode, UiPathErrorCode],
1224
title: str,
1325
detail: str,
1426
category: UiPathErrorCategory = UiPathErrorCategory.UNKNOWN,
1527
status: Optional[int] = None,
1628
):
17-
super().__init__(code, title, detail, category, status, prefix="MCP")
29+
super().__init__(
30+
code.value, title, detail, category, status, prefix="LlamaIndex"
31+
)

src/uipath_mcp/_cli/_runtime/_runtime.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
from uipath._cli._runtime._contracts import (
2121
UiPathBaseRuntime,
2222
UiPathErrorCategory,
23+
UiPathErrorCode,
2324
UiPathRuntimeResult,
2425
)
2526
from uipath.tracing import LlmOpsHttpExporter
2627

2728
from .._utils._config import McpServer
2829
from ._context import UiPathMcpRuntimeContext, UiPathServerType
29-
from ._exception import UiPathMcpRuntimeError
30+
from ._exception import McpErrorCode, UiPathMcpRuntimeError
3031
from ._session import SessionServer
3132

3233
logger = logging.getLogger(__name__)
@@ -56,15 +57,15 @@ async def validate(self) -> None:
5657
"""Validate runtime inputs and load MCP server configuration."""
5758
if self.context.config is None:
5859
raise UiPathMcpRuntimeError(
59-
"CONFIGURATION_ERROR",
60+
McpErrorCode.CONFIGURATION_ERROR,
6061
"Missing configuration",
6162
"Configuration is required.",
6263
UiPathErrorCategory.SYSTEM,
6364
)
6465

6566
if self.context.entrypoint is None:
6667
raise UiPathMcpRuntimeError(
67-
"CONFIGURATION_ERROR",
68+
McpErrorCode.CONFIGURATION_ERROR,
6869
"Missing entrypoint",
6970
"Entrypoint is required.",
7071
UiPathErrorCategory.SYSTEM,
@@ -73,7 +74,7 @@ async def validate(self) -> None:
7374
self._server = self.context.config.get_server(self.context.entrypoint)
7475
if not self._server:
7576
raise UiPathMcpRuntimeError(
76-
"SERVER_NOT_FOUND",
77+
McpErrorCode.SERVER_NOT_FOUND,
7778
"MCP server not found",
7879
f"Server '{self.context.entrypoint}' not found in configuration",
7980
UiPathErrorCategory.DEPLOYMENT,
@@ -88,31 +89,31 @@ def _validate_auth(self) -> None:
8889
uipath_url = os.environ.get("UIPATH_URL")
8990
if not uipath_url:
9091
raise UiPathMcpRuntimeError(
91-
"CONFIGURATION_ERROR",
92+
McpErrorCode.CONFIGURATION_ERROR,
9293
"Missing UIPATH_URL environment variable",
9394
"Please run 'uipath auth'.",
9495
UiPathErrorCategory.USER,
9596
)
9697

9798
if not self.context.trace_context:
9899
raise UiPathMcpRuntimeError(
99-
"CONFIGURATION_ERROR",
100+
McpErrorCode.CONFIGURATION_ERROR,
100101
"Missing trace context",
101102
"Trace context is required for SignalR connection.",
102103
UiPathErrorCategory.SYSTEM,
103104
)
104105

105106
if not self.context.trace_context.tenant_id:
106107
raise UiPathMcpRuntimeError(
107-
"CONFIGURATION_ERROR",
108+
McpErrorCode.CONFIGURATION_ERROR,
108109
"Missing tenant ID",
109110
"Please run 'uipath auth'.",
110111
UiPathErrorCategory.SYSTEM,
111112
)
112113

113114
if not self.context.trace_context.org_id:
114115
raise UiPathMcpRuntimeError(
115-
"CONFIGURATION_ERROR",
116+
McpErrorCode.CONFIGURATION_ERROR,
116117
"Missing organization ID",
117118
"Please run 'uipath auth'.",
118119
UiPathErrorCategory.SYSTEM,
@@ -152,7 +153,7 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
152153
folder_path = os.environ.get("UIPATH_FOLDER_PATH")
153154
if not folder_path:
154155
raise UiPathMcpRuntimeError(
155-
"REGISTRATION_ERROR",
156+
McpErrorCode.REGISTRATION_ERROR,
156157
"No UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable set.",
157158
"Please set the UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable.",
158159
UiPathErrorCategory.USER,
@@ -162,7 +163,7 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
162163
)
163164
if not self.context.folder_key:
164165
raise UiPathMcpRuntimeError(
165-
"REGISTRATION_ERROR",
166+
McpErrorCode.REGISTRATION_ERROR,
166167
"Folder NOT FOUND. Invalid UIPATH_FOLDER_PATH environment variable.",
167168
"Please set the UIPATH_FOLDER_PATH or UIPATH_FOLDER_KEY environment variable.",
168169
UiPathErrorCategory.USER,
@@ -235,7 +236,7 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
235236
raise
236237
detail = f"Error: {str(e)}"
237238
raise UiPathMcpRuntimeError(
238-
"EXECUTION_ERROR",
239+
UiPathErrorCode.EXECUTION_ERROR,
239240
"MCP Runtime execution failed",
240241
detail,
241242
UiPathErrorCategory.USER,
@@ -421,7 +422,7 @@ async def _register(self) -> None:
421422
if server_stderr_output:
422423
error_message += f"\nServer error output:\n{server_stderr_output}"
423424
raise UiPathMcpRuntimeError(
424-
"INITIALIZATION_ERROR",
425+
McpErrorCode.INITIALIZATION_ERROR,
425426
"Server initialization failed",
426427
error_message,
427428
UiPathErrorCategory.DEPLOYMENT,
@@ -433,7 +434,7 @@ async def _register(self) -> None:
433434
try:
434435
if not tools_result:
435436
raise UiPathMcpRuntimeError(
436-
"INITIALIZATION_ERROR",
437+
McpErrorCode.INITIALIZATION_ERROR,
437438
"Server initialization failed",
438439
"Failed to get tools list from server",
439440
UiPathErrorCategory.DEPLOYMENT,
@@ -478,7 +479,7 @@ async def _register(self) -> None:
478479
)
479480

480481
raise UiPathMcpRuntimeError(
481-
"REGISTRATION_ERROR",
482+
McpErrorCode.REGISTRATION_ERROR,
482483
"Failed to register MCP Server",
483484
str(e),
484485
UiPathErrorCategory.SYSTEM,

0 commit comments

Comments
 (0)