test_api.py•2.03 kB
#!/usr/bin/env python3
"""
Direct API test for Exa Websets (without MCP server layer)
"""
import asyncio
import httpx
import json
import os
EXA_API_KEY = "ce182a39-be3e-49b1-bdb2-15986f534790"
EXA_BASE_URL = "https://api.exa.ai/websets"
async def test_exa_api():
"""Test direct connection to Exa API"""
print("Testing direct Exa API connection...")
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-direct-api",
"metadata": {
"test": "direct_api_call"
}
}
try:
async with httpx.AsyncClient() as client:
response = await client.post(EXA_BASE_URL, json=payload, headers=headers)
print(f"Status Code: {response.status_code}")
print(f"Response Headers: {dict(response.headers)}")
if response.status_code == 201:
result = response.json()
print("✅ Webset created successfully!")
print(json.dumps(result, indent=2))
return result
else:
print(f"❌ API call failed with status {response.status_code}")
print(f"Response: {response.text}")
return None
except Exception as e:
print(f"❌ Exception occurred: {e}")
return None
async def main():
"""Run the direct API test"""
print("Exa Websets Direct API Test")
print("=" * 40)
result = await test_exa_api()
if result:
print("\n🎉 Direct API test successful!")
print("The MCP server should work correctly with this API.")
else:
print("\n⚠️ Direct API test failed.")
print("Check your API key and network connection.")
if __name__ == "__main__":
asyncio.run(main())