#!/usr/bin/env python3
"""
Tools Demo
Demonstrates all available MCP tools.
"""
import asyncio
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from mcp_maf.tools import AVAILABLE_TOOLS, call_tool
import json
async def main():
"""Main function"""
print("=" * 60)
print(" MCP-MAF Tools Demo")
print("=" * 60)
print()
# List all tools
print(f"📋 Available Tools: {len(AVAILABLE_TOOLS)}")
print()
for i, tool in enumerate(AVAILABLE_TOOLS, 1):
print(f"{i}. {tool.name}")
print(f" Description: {tool.description}")
print(f" Input Schema: {json.dumps(tool.input_schema, indent=6)}")
print()
# Demo each tool
print("=" * 60)
print("🎯 Tool Demonstrations")
print("=" * 60)
print()
# 1. Weather Tool
print("1️⃣ Weather Tool Demo")
print("-" * 60)
for location in ["Taipei", "Tokyo", "New York"]:
print(f"\n Query: get_weather(location='{location}')")
result = await call_tool("get_weather", {"location": location})
print(f" Result: {json.dumps(result, indent=3)}")
await asyncio.sleep(0.5)
print("\n" + "=" * 60)
# 2. Calculator Tool
print("\n2️⃣ Calculator Tool Demo")
print("-" * 60)
expressions = ["2 + 2", "123 * 456", "(10 + 5) * 3", "100 / 4"]
for expr in expressions:
print(f"\n Query: calculate(expression='{expr}')")
result = await call_tool("calculate", {"expression": expr})
print(f" Result: {json.dumps(result, indent=3)}")
await asyncio.sleep(0.5)
print("\n" + "=" * 60)
# 3. Stock Price Tool
print("\n3️⃣ Stock Price Tool Demo")
print("-" * 60)
stock_codes = ["2330", "2454", "2317"]
for code in stock_codes:
print(f"\n Query: get_stock_price(stock_code='{code}')")
result = await call_tool("get_stock_price", {"stock_code": code})
print(f" Result: {json.dumps(result, indent=3)}")
await asyncio.sleep(1) # Rate limiting for API
print("\n" + "=" * 60)
print("\n✅ Tools Demo Complete!")
print("=" * 60)
if __name__ == "__main__":
asyncio.run(main())