#!/usr/bin/env python3 """ Test script to verify connection to Hugging Face Spaces server """ import asyncio import aiohttp import json HF_SPACE_URL = "https://galcan-mcp-docs-server.hf.space" async def test_connection(): """Test connection to Hugging Face Spaces server""" print("Testing connection to Hugging Face Spaces server...") print(f"URL: {HF_SPACE_URL}") try: async with aiohttp.ClientSession() as session: # Test health endpoint print("\n1. Testing health endpoint...") async with session.get(f"{HF_SPACE_URL}/") as response: if response.status == 200: data = await response.json() print(f"[OK] Health check passed") print(f" Status: {data.get('status', 'unknown')}") print(f" Chunks loaded: {data.get('chunks_loaded', 0)}") print(f" Docs loaded: {data.get('docs_loaded', 0)}") else: print(f"[ERROR] Health check failed: {response.status}") return False # Test search endpoint print("\n2. Testing search endpoint...") search_data = {"query": "MCP architecture", "limit": 3} async with session.post(f"{HF_SPACE_URL}/search", json=search_data) as response: if response.status == 200: data = await response.json() results = data.get('results', []) total = data.get('total', 0) print(f"[OK] Search test passed") print(f" Found {total} results") if results: print(f" First result: {results[0].get('title', 'Unknown')}") else: print(f"[ERROR] Search test failed: {response.status}") return False # Test docs endpoint print("\n3. Testing docs endpoint...") async with session.get(f"{HF_SPACE_URL}/docs") as response: if response.status == 200: data = await response.json() docs = data.get('documents', []) print(f"[OK] Docs endpoint working") print(f" Found {len(docs)} documents") else: print(f"[ERROR] Docs endpoint failed: {response.status}") return False print("\n[SUCCESS] All tests passed! Your Hugging Face Spaces server is working correctly.") return True except Exception as e: print(f"[ERROR] Connection failed: {e}") return False async def main(): print("Hugging Face Spaces Connection Test") print("=" * 50) success = await test_connection() if success: print("\n✅ Your server is ready to use with Cursor!") print("\nNext steps:") print("1. Add the MCP client to your Cursor configuration") print("2. Restart Cursor") print("3. Use the tools: search_docs, get_chunk, list_docs, health_check") else: print("\n❌ Connection failed. Please check your Hugging Face Spaces deployment.") if __name__ == "__main__": asyncio.run(main())