web_search
Perform targeted web searches for cricket-related information, retrieve relevant links with titles and snippets, and filter results by specific sites for focused queries.
Instructions
General web search for cricket-related queries. Returns links with titles and snippets.
Args: query (str): Search query num_results (int): Number of results to return (max ~10 typical) site_filter (str, optional): If provided, prefixes the query with e.g. "site:cricbuzz.com"
Returns: list[dict]: [{"title": str, "url": str, "snippet": str}]
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| num_results | No | ||
| query | Yes | ||
| site_filter | No |
Implementation Reference
- cricket_server.py:681-723 (handler)The main handler function for the 'web_search' MCP tool. It performs a general web search (using the googlesearch library), optionally restricted to a site, and enriches results with page titles and meta descriptions by fetching each page.@mcp.tool() def web_search(query: str, num_results: int = 5, site_filter: str | None = None) -> list: """ General web search for cricket-related queries. Returns links with titles and snippets. Args: query (str): Search query num_results (int): Number of results to return (max ~10 typical) site_filter (str, optional): If provided, prefixes the query with e.g. "site:cricbuzz.com" Returns: list[dict]: [{"title": str, "url": str, "snippet": str}] """ if not query: return [{"error": "query is required"}] q = query.strip() if site_filter: q = f"site:{site_filter} " + q results = [] try: links = search(q, num_results=max(1, min(num_results, 10))) except Exception as e: return [{"error": f"Search failed: {str(e)}"}] for url in links: item = {"url": url} try: resp = requests.get(url, headers=HEADERS, timeout=8) resp.raise_for_status() page = BeautifulSoup(resp.text, "lxml") title = page.find("title") desc = page.find("meta", attrs={"name": "description"}) item["title"] = title.text.strip() if title and title.text else url item["snippet"] = desc["content"].strip() if desc and desc.get("content") else "" except Exception: item["title"] = url item["snippet"] = "" results.append(item) return results