Skip to content

Commit e6b61f5

Browse files
committed
test: add client logs
1 parent 7b848d2 commit e6b61f5

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

testcases/ground-to-cloud/test.py

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,55 @@ async def call_add_tool():
2828

2929
try:
3030
# 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-
try:
38-
tools_result = await session.list_tools()
39-
available_tools = [tool.name for tool in tools_result.tools]
40-
expected_available_tools = [
41-
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
42-
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
43-
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
44-
]
45-
46-
print (f"Available tools: {available_tools}")
47-
except Exception as e:
48-
print(f"[Tools] Error listing tools: {e}")
49-
raise AssertionError(f"Error listing tools: {e}") from e
50-
51-
if set(available_tools) != set(expected_available_tools):
52-
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
53-
54-
# Call the add tool directly
31+
try:
32+
async with streamablehttp_client(mcp_url, headers={ 'Authorization': f'Bearer {token}' }) as (read_stream, write_stream, _):
5533
try:
56-
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
57-
58-
expected_result = "12.0"
59-
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
34+
async with ClientSession(read_stream, write_stream) as session:
35+
# Initialize the session
36+
try:
37+
await session.initialize()
38+
except Exception as e:
39+
print(f"[Initialize] Error initializing session: {e}")
40+
raise e
41+
42+
# List available tools
43+
try:
44+
tools_result = await session.list_tools()
45+
available_tools = [tool.name for tool in tools_result.tools]
46+
expected_available_tools = [
47+
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
48+
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
49+
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
50+
]
51+
52+
print (f"Available tools: {available_tools}")
53+
except Exception as e:
54+
print(f"[Tools] Error listing tools: {e}")
55+
raise e
56+
57+
if set(available_tools) != set(expected_available_tools):
58+
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
59+
60+
# Call the add tool directly
61+
try:
62+
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
63+
64+
expected_result = "12.0"
65+
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
66+
except Exception as e:
67+
print(f"[Add Tool] Error calling add tool: {e}")
68+
raise e
69+
70+
if actual_result != expected_result:
71+
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
72+
73+
print("Test completed successfully")
6074
except Exception as e:
61-
print(f"[Add Tool] Error calling add tool: {e}")
62-
raise AssertionError(f"Error calling add tool: {e}") from e
63-
64-
if actual_result != expected_result:
65-
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
66-
67-
print("Test completed successfully")
75+
print(f"[Client Session] Error during MCP session: {e}")
76+
raise e
77+
except Exception as e:
78+
print(f"[Streamable HTTP Client] Error connecting to MCP server: {e}")
79+
raise e
6880
except Exception as e:
6981
print(f"Unexpected error connecting to MCP server: {e}")
7082
raise AssertionError(f"Connection error, {e}") from e

0 commit comments

Comments
 (0)