my_client.py•1.49 kB
import asyncio
from fastmcp import Client
client = Client("http://localhost:8000/mcp")
async def call_add_order():
async with client:
result = await client.call_tool(
"add_order",
{
"data": {
"customer_name": "John Doe",
"product_name": "MacBook Pro",
"quantity": 2,
"price_per_unit": 1999,
"notes": "Urgent delivery"
}
}
)
print("Add Order Result:", result)
return result.get("order", {}).get("id") # return order id for testing
async def call_search_orders(query: str):
async with client:
result = await client.call_tool(
"search_orders",
{
"data": {
"query": query
}
}
)
print(f"Search Orders for '{query}':", result)
async def call_get_order(order_id: str):
async with client:
result = await client.call_tool(
"get_order",
{
"data": {
"order_id": order_id
}
}
)
print(f"Get Order {order_id}:", result)
async def main():
# Add a new order
order_id = await call_add_order()
# Search for orders
await call_search_orders("MacBook")
# Get order by ID
if order_id:
await call_get_order(order_id)
asyncio.run(main())