Spaces:
Sleeping
Sleeping
File size: 933 Bytes
c16e1c9 |
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 |
import os
import httpx
from dotenv import load_dotenv
load_dotenv()
class WebClient:
"""
Communicates with the Web Search MCP server.
"""
def __init__(self):
self.base_url = os.getenv("WEB_MCP_URL")
self.search_endpoint = f"{self.base_url}/search"
async def search(self, query: str):
"""
Sends the query to the Web Search server and returns search results.
"""
try:
async with httpx.AsyncClient() as client:
response = await client.post(
self.search_endpoint,
json={
"query": query
}
)
if response.status_code != 200:
return []
data = response.json()
return data.get("results", [])
except Exception as e:
print("Web Client Error:", e)
return []
|