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 []