Skip to content

Commit 45ad54f

Browse files
committed
fix: runtime error handliing
1 parent b8a1501 commit 45ad54f

File tree

4 files changed

+81
-81
lines changed

4 files changed

+81
-81
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-mcp"
3-
version = "0.0.104"
3+
version = "0.0.105"
44
description = "UiPath MCP SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_mcp/_cli/_runtime/_runtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ async def _register(self) -> None:
402402
# Only proceed if initialization was successful
403403
tools_result = await session.list_tools()
404404
# logger.info(tools_result)
405-
except asyncio.TimeoutError:
405+
except Exception:
406406
logger.error("Initialization timed out")
407407
# Capture stderr output here, after the timeout
408408
stderr_temp.seek(0)
@@ -418,7 +418,7 @@ async def _register(self) -> None:
418418
# Now that we're outside the context managers, check if initialization succeeded
419419
if not initialization_successful:
420420
await self._on_runtime_abort()
421-
error_message = "The server process failed to initialize. Verify environment variables are set correctly."
421+
error_message = "The server process failed to initialize."
422422
if server_stderr_output:
423423
error_message += f"\nServer error output:\n{server_stderr_output}"
424424
raise UiPathMcpRuntimeError(

testcases/ground-to-cloud/test.py

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
1-
import asyncio
2-
import os
3-
import sys
4-
5-
from dotenv import load_dotenv
6-
from mcp.client.session import ClientSession
7-
from mcp.client.streamable_http import streamablehttp_client
8-
from retry import retry
9-
10-
11-
def get_required_env_var(name: str) -> str:
12-
"""Get required environment variable or raise an error if not set."""
13-
value = os.getenv(name)
14-
if not value:
15-
raise ValueError(f"Required environment variable {name} is not set")
16-
return value
17-
18-
@retry(tries=3, delay=2, backoff=2)
19-
async def call_add_tool():
20-
# Load configuration from environment variables
21-
base_url = get_required_env_var("BASE_URL")
22-
folder_key = get_required_env_var("UIPATH_FOLDER_KEY")
23-
token = get_required_env_var("UIPATH_ACCESS_TOKEN")
24-
mcp_server_name = get_required_env_var("MCP_SERVER_NAME")
25-
26-
# Construct the MCP server URL
27-
mcp_url = f"{base_url}/agenthub_/mcp/{folder_key}/{mcp_server_name}"
28-
29-
try:
30-
# Use streamable HTTP client to connect to the MCP server
31-
async with streamablehttp_client(mcp_url, headers={ 'Authorization': f'Bearer {token}' }) as (read_stream, write_stream, _):
32-
async with ClientSession(read_stream, write_stream) as session:
33-
# Initialize the session
34-
await session.initialize()
35-
36-
# List available tools
37-
tools_result = await session.list_tools()
38-
available_tools = [tool.name for tool in tools_result.tools]
39-
expected_available_tools = [
40-
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
41-
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
42-
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
43-
]
44-
45-
print (f"Available tools: {available_tools}")
46-
47-
if set(available_tools) != set(expected_available_tools):
48-
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
49-
50-
# Call the add tool directly
51-
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
52-
53-
expected_result = "12.0"
54-
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
55-
56-
if actual_result != expected_result:
57-
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
58-
59-
print("Test completed successfully")
60-
except Exception as e:
61-
print(f"Unexpected error connecting to MCP server: {e}")
62-
raise AssertionError(f"Connection error, {e}") from e
63-
64-
async def main():
65-
"""Main async function to run the test."""
66-
try:
67-
load_dotenv()
68-
69-
await call_add_tool()
70-
except Exception as e:
71-
print(f"Test failed with error: {e}")
72-
sys.exit(1)
73-
74-
75-
if __name__ == '__main__':
76-
asyncio.run(main())
1+
import asyncio
2+
import os
3+
import sys
4+
5+
from dotenv import load_dotenv
6+
from mcp.client.session import ClientSession
7+
from mcp.client.streamable_http import streamablehttp_client
8+
from retry import retry
9+
10+
11+
def get_required_env_var(name: str) -> str:
12+
"""Get required environment variable or raise an error if not set."""
13+
value = os.getenv(name)
14+
if not value:
15+
raise ValueError(f"Required environment variable {name} is not set")
16+
return value
17+
18+
@retry(tries=3, delay=2, backoff=2)
19+
async def call_add_tool():
20+
# Load configuration from environment variables
21+
base_url = get_required_env_var("BASE_URL")
22+
folder_key = get_required_env_var("UIPATH_FOLDER_KEY")
23+
token = get_required_env_var("UIPATH_ACCESS_TOKEN")
24+
mcp_server_name = get_required_env_var("MCP_SERVER_NAME")
25+
26+
# Construct the MCP server URL
27+
mcp_url = f"{base_url}/agenthub_/mcp/{folder_key}/{mcp_server_name}"
28+
29+
try:
30+
# Use streamable HTTP client to connect to the MCP server
31+
async with streamablehttp_client(mcp_url, headers={ 'Authorization': f'Bearer {token}' }) as (read_stream, write_stream, _):
32+
async with ClientSession(read_stream, write_stream) as session:
33+
# Initialize the session
34+
await session.initialize()
35+
36+
# List available tools
37+
tools_result = await session.list_tools()
38+
available_tools = [tool.name for tool in tools_result.tools]
39+
expected_available_tools = [
40+
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
41+
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
42+
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
43+
]
44+
45+
print (f"Available tools: {available_tools}")
46+
47+
if set(available_tools) != set(expected_available_tools):
48+
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
49+
50+
# Call the add tool directly
51+
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
52+
53+
expected_result = "12.0"
54+
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
55+
56+
if actual_result != expected_result:
57+
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
58+
59+
print("Test completed successfully")
60+
except Exception as e:
61+
print(f"Unexpected error connecting to MCP server: {e}")
62+
raise AssertionError(f"Connection error, {e}") from e
63+
64+
async def main():
65+
"""Main async function to run the test."""
66+
try:
67+
load_dotenv()
68+
69+
await call_add_tool()
70+
except Exception as e:
71+
print(f"Test failed with error: {e}")
72+
sys.exit(1)
73+
74+
75+
if __name__ == '__main__':
76+
asyncio.run(main())

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)