Spaces:
Running
Running
File size: 3,332 Bytes
ec5b689 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
#!/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())
|