@@ -17,7 +17,6 @@ def get_required_env_var(name: str) -> str:
1717
1818@retry (tries = 3 , delay = 2 , backoff = 2 )
1919async def call_add_tool ():
20- load_dotenv ()
2120 # Load configuration from environment variables
2221 base_url = get_required_env_var ("BASE_URL" )
2322 folder_key = get_required_env_var ("UIPATH_FOLDER_KEY" )
@@ -27,37 +26,42 @@ async def call_add_tool():
2726 # Construct the MCP server URL
2827 mcp_url = f"{ base_url } /agenthub_/mcp/{ folder_key } /{ mcp_server_name } "
2928
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 = [ "add" , "subtract" , "multiply" , "divide" , "power" , "square_root" , "nth_root" , "sin" , "cos" , "tan" , "log10" , "natural_log" , "log_base" , "mean" , "median" , "standard_deviation" , "complex_add" , "complex_multiply" , "convert_temperature" , "solve_quadratic" , "get_constants" ]
40-
41- print (f"Available tools: { available_tools } " )
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 = [ "add" , "subtract" , "multiply" , "divide" , "power" , "square_root" , "nth_root" , "sin" , "cos" , "tan" , "log10" , "natural_log" , "log_base" , "mean" , "median" , "standard_deviation" , "complex_add" , "complex_multiply" , "convert_temperature" , "solve_quadratic" , "get_constants" ]
4240
43- if set (available_tools ) != set (expected_available_tools ):
44- raise AssertionError (f"Tool sets don't match. Expected: { set (expected_available_tools )} , Got: { set (available_tools )} " )
41+ print (f"Available tools: { available_tools } " )
4542
46- # Call the add tool directly
47- call_tool_result = await session . call_tool ( name = "add" , arguments = { "a" : 7 , "b" : 5 } )
43+ if set ( available_tools ) != set ( expected_available_tools ):
44+ raise AssertionError ( f"Tool sets don't match. Expected: { set ( expected_available_tools ) } , Got: { set ( available_tools ) } " )
4845
49- expected_result = "12.0"
50- actual_result = call_tool_result . content [ 0 ]. text if call_tool_result . content else None
46+ # Call the add tool directly
47+ call_tool_result = await session . call_tool ( name = "add" , arguments = { "a" : 7 , "b" : 5 })
5148
52- if actual_result != expected_result :
53- raise AssertionError ( f"Expected { expected_result } , got { actual_result } " )
49+ expected_result = "12.0"
50+ actual_result = call_tool_result . content [ 0 ]. text if call_tool_result . content else None
5451
55- print ("Test completed successfully" )
52+ if actual_result != expected_result :
53+ raise AssertionError (f"Expected { expected_result } , got { actual_result } " )
5654
55+ print ("Test completed successfully" )
56+ except Exception as e :
57+ print (f"Unexpected error connecting to MCP server: { e } " )
58+ raise AssertionError (f"Connection error, { e } " ) from e
5759
5860async def main ():
5961 """Main async function to run the test."""
6062 try :
63+ load_dotenv ()
64+
6165 await call_add_tool ()
6266 except Exception as e :
6367 print (f"Test failed with error: { e } " )
0 commit comments