direct_test.py•2.68 kB
#!/usr/bin/env python3
"""
Direct test of Exa API functionality (without MCP layer)
"""
import asyncio
import httpx
import json
EXA_API_KEY = "ce182a39-be3e-49b1-bdb2-15986f534790"
EXA_BASE_URL = "https://api.exa.ai"
async def test_search():
"""Test basic Exa search"""
url = f"{EXA_BASE_URL}/search"
headers = {
"x-api-key": EXA_API_KEY,
"Content-Type": "application/json"
}
payload = {
"query": "AI startups in San Francisco",
"numResults": 3,
"type": "neural"
}
async with httpx.AsyncClient() as client:
response = await client.post(url, json=payload, headers=headers)
if response.status_code == 200:
result = response.json()
print("✅ Basic search successful!")
print(f"Found {len(result.get('results', []))} results")
return True
else:
print(f"❌ Search failed: {response.status_code}")
print(response.text)
return False
async def test_websets():
"""Test websets API (might fail if not available)"""
url = f"{EXA_BASE_URL}/websets/v0/websets"
headers = {
"x-api-key": EXA_API_KEY,
"Content-Type": "application/json"
}
payload = {
"search": {
"query": "Tech companies in San Francisco",
"count": 5,
"entity": {"type": "company"}
},
"externalId": "test-webset-direct"
}
async with httpx.AsyncClient() as client:
response = await client.post(url, json=payload, headers=headers)
if response.status_code == 201:
result = response.json()
print("✅ Websets API available and working!")
print(f"Created webset: {result.get('id', 'unknown')}")
return True
else:
print(f"⚠️ Websets API returned: {response.status_code}")
print(f"Message: {response.text}")
return False
async def main():
print("Direct Exa API Tests")
print("=" * 20)
print("\n1. Testing basic search API...")
search_ok = await test_search()
print("\n2. Testing websets API...")
websets_ok = await test_websets()
print("\n" + "=" * 20)
if search_ok:
print("✅ Basic search API works - MCP server will work for search")
if websets_ok:
print("✅ Websets API works - Full websets functionality available")
elif search_ok:
print("ℹ️ Websets API not available, but search API works")
print(" MCP server can provide search functionality")
if __name__ == "__main__":
asyncio.run(main())