client.py•946 B
import asyncio
from fastmcp import Client
async def test_server():
client = Client("server.py")
async with client:
# Test greeting tool
result = await client.call_tool("greet", {"name": "World"})
print("Greet result:", result)
# Test math tools
add_result = await client.call_tool("add", {"a": 5, "b": 3})
print("Add result:", add_result)
multiply_result = await client.call_tool("multiply", {"a": 4, "b": 7})
print("Multiply result:", multiply_result)
# Test user info tool
user_result = await client.call_tool("get_user_info", {"user_id": 1})
print("User info result:", user_result)
# Test non-existent user
missing_user = await client.call_tool("get_user_info", {"user_id": 99})
print("Missing user result:", missing_user)
if __name__ == "__main__":
asyncio.run(test_server())