import asyncio
import os
import sys

# Add backend folder to path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "backend")))

try:
    from fastmcp import Client
except ImportError:
    print("CRITICAL: fastmcp is not installed in the current python environment!")
    sys.exit(1)

async def test_mcp():
    mcp_url = "http://127.0.0.1:9000/mcp"
    print(f"Connecting to MCP at {mcp_url}...")
    try:
        async with Client(mcp_url) as c:
            print("Successfully connected to client!")
            print("Listing tools...")
            tools = await c.list_tools()
            for tool in tools:
                print(f" - {tool.name}")
    except Exception as e:
        print(f"Failed to connect or list tools: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(test_mcp())
