11import asyncio
22import os
33import sys
4+ import httpx
45
56from dotenv import load_dotenv
67from mcp .client .session import ClientSession
@@ -22,24 +23,50 @@ async def call_add_tool():
2223 folder_key = get_required_env_var ("UIPATH_FOLDER_KEY" )
2324 token = get_required_env_var ("UIPATH_ACCESS_TOKEN" )
2425 mcp_server_name = get_required_env_var ("MCP_SERVER_NAME" )
25-
26+
2627 # Construct the MCP server URL
2728 mcp_url = f"{ base_url } /agenthub_/mcp/{ folder_key } /{ mcp_server_name } "
28-
29+
30+ print (f"\n === Diagnostic Information ===" )
31+ print (f"BASE_URL: { base_url } " )
32+ print (f"Folder Key: { folder_key } " )
33+ print (f"MCP Server Name: { mcp_server_name } " )
34+ print (f"Full MCP URL: { mcp_url } " )
35+ print (f"Token (first 30 chars): { token [:30 ]} ..." )
36+
37+ # Test the URL directly before attempting MCP connection
38+ print (f"\n === Testing HTTP endpoint directly ===" )
39+ try :
40+ async with httpx .AsyncClient () as client :
41+ response = await client .get (
42+ mcp_url ,
43+ headers = {'Authorization' : f'Bearer { token } ' },
44+ follow_redirects = True ,
45+ timeout = 10.0
46+ )
47+ print (f"HTTP Status: { response .status_code } " )
48+ print (f"Content-Type: { response .headers .get ('content-type' , 'N/A' )} " )
49+ print (f"Response headers: { dict (response .headers )} " )
50+ print (f"Response body (first 500 chars):\n { response .text [:500 ]} " )
51+ except Exception as http_error :
52+ print (f"HTTP test failed: { http_error } " )
53+
54+ print (f"=== End of diagnostics ===\n " )
55+
2956 try :
3057 # Use streamable HTTP client to connect to the MCP server
3158 async with streamablehttp_client (mcp_url , headers = { 'Authorization' : f'Bearer { token } ' }) as (read_stream , write_stream , _ ):
3259 async with ClientSession (read_stream , write_stream ) as session :
3360 # Initialize the session
3461 await session .initialize ()
35-
62+
3663 # List available tools
3764 tools_result = await session .list_tools ()
3865 available_tools = [tool .name for tool in tools_result .tools ]
3966 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"
67+ "add" , "subtract" , "multiply" , "divide" , "power" , "square_root" , "nth_root" ,
68+ "sin" , "cos" , "tan" , "log10" , "natural_log" , "log_base" , "mean" , "median" , "standard_deviation" ,
69+ "complex_add" , "complex_multiply" , "convert_temperature" , "solve_quadratic" , "get_constants"
4370 ]
4471
4572 print (f"Available tools: { available_tools } " )
@@ -73,4 +100,4 @@ async def main():
73100
74101
75102if __name__ == '__main__' :
76- asyncio .run (main ())
103+ asyncio .run (main ())
0 commit comments