import sys
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def run():
# Define server parameters
# launching the server.py we just created
server_params = StdioServerParameters(
command=sys.executable,
args=["server.py"],
env=None
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize connection
await session.initialize()
# List available tools
tools = await session.list_tools()
print("\n=== Available Tools ===")
for tool in tools.tools:
print(f"- {tool.name}: {tool.description}")
# Test 1: Search for Nutella
print("\n=== Testing Tool: search_products ===")
search_args = {"query": "nutella", "page_size": 2}
print(f"Calling search_products with {search_args}")
result = await session.call_tool("search_products", arguments=search_args)
if result.content:
print(f"Result:\n{result.content[0].text}")
else:
print("No content returned.")
# Test 2: Get specific product (Nutella barcode from search or known)
# Nutella 400g barcode usually starts with 3017620422003
barcode = "3017620422003"
print(f"\n=== Testing Tool: get_product_by_barcode ===")
print(f"Calling get_product_by_barcode with {barcode}")
product_result = await session.call_tool("get_product_by_barcode", arguments={"barcode": barcode})
if product_result.content:
print(f"Result:\n{product_result.content[0].text}")
else:
print("No content returned.")
print("\n=== Validation Complete ===")
if __name__ == "__main__":
asyncio.run(run())