search
Perform web or news searches to find quick information and relevant articles using a privacy-focused metasearch engine.
Instructions
Quick search for web or news content.
Use this when:
User asks for a simple web search or lookup
Need quick information, not comprehensive research
Looking for news articles on a topic
This runs a SINGLE search and returns up to max_results (default 10). For comprehensive research with multiple sources, use research_topic instead.
Parameters: query* - What to search for category - "general" for web search, "news" for news articles (default: general) engines - Optional: Specific engines (e.g., "google,bing") max_results - Number of results (default: 10, max: 50)
Returns: Search results with titles, URLs, and snippets
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Search category | general |
| engines | No | Comma-separated engine list | |
| max_results | No | Maximum results | |
| query | Yes | Search query |
Input Schema (JSON Schema)
Implementation Reference
- src/searxng_mcp/tools/search.py:89-128 (handler)Core handler function implementing the search tool logic: performs search via _search, formats and truncates results, returns as TextContent.def search( self, query: str, category: Literal["general", "news"] = "general", engines: Optional[str] = None, max_results: int = 10 ) -> List[TextContent]: """Quick search for web or news. Args: query: Search query category: "general" for web search, "news" for news engines: Comma-separated engine list (e.g., "google,bing,brave") max_results: Maximum results to return Returns: Formatted search results """ results = self._search(query, category=category, engines=engines) if category == "news": output = f"π° News Results for: {query}\n\n" else: output = f"π Search Results for: {query}\n\n" for i, result in enumerate(results.get("results", [])[:max_results], 1): output += f"{i}. **{result.get('title', 'No title')}**\n" output += f" {result.get('url', '')}\n" if result.get('content'): content = result['content'][:200] + "..." if len(result['content']) > 200 else result['content'] output += f" {content}\n" if category == "news" and result.get('publishedDate'): output += f" π {result['publishedDate']}\n" output += "\n" if not results.get("results"): output += "No results found.\n" return [TextContent(type="text", text=output)]
- src/searxng_mcp/server.py:140-147 (registration)Registers the 'search' tool with the MCP server, defines input schema using Pydantic Annotated types, and delegates execution to SearchTools.search@self.mcp.tool(description=SEARCH_DESC) def search( query: Annotated[str, Field(description="Search query")], category: Annotated[Literal["general", "news"], Field(description="Search category")] = "general", engines: Annotated[Optional[str], Field(description="Comma-separated engine list")] = None, max_results: Annotated[int, Field(description="Maximum results", ge=1, le=50)] = 10 ): return self.search_tools.search(query, category, engines, max_results)
- src/searxng_mcp/server.py:14-30 (schema)Detailed schema description for the 'search' tool, including usage guidelines, parameters, and return format.SEARCH_DESC = """Quick search for web or news content. Use this when: - User asks for a simple web search or lookup - Need quick information, not comprehensive research - Looking for news articles on a topic This runs a SINGLE search and returns up to max_results (default 10). For comprehensive research with multiple sources, use research_topic instead. Parameters: query* - What to search for category - "general" for web search, "news" for news articles (default: general) engines - Optional: Specific engines (e.g., "google,bing") max_results - Number of results (default: 10, max: 50) Returns: Search results with titles, URLs, and snippets"""
- Helper function that performs the actual HTTP request to SearXNG API, handles parameters and error logging.def _search( self, query: str, category: Optional[str] = None, engines: Optional[str] = None, language: str = "en", page: int = 1 ) -> Dict[str, Any]: """Internal search method. Args: query: Search query category: Search category (general, images, videos, news, etc.) engines: Comma-separated list of engines language: Search language page: Page number Returns: Search results from SearXNG """ params = { "q": query, "format": "json", "language": language, "pageno": page } if category: params["categories"] = category if engines: params["engines"] = engines try: self.logger.info(f"Searching: {query} (category: {category})") response = requests.get( f"{self.searxng_url}/search", params=params, timeout=self.timeout ) response.raise_for_status() return response.json() except Exception as e: self.logger.error(f"Search failed: {e}") raise RuntimeError(f"Search failed: {e}")
- src/searxng_mcp/tools/search.py:9-22 (helper)SearchTools class initialization, configures SearXNG URL and logger used by all search methods.class SearchTools: """Tools for searching via SearXNG.""" def __init__(self, searxng_url: str, timeout: int = 10): """Initialize search tools. Args: searxng_url: SearXNG instance URL timeout: Request timeout in seconds """ self.searxng_url = searxng_url.rstrip("/") self.timeout = timeout self.logger = logging.getLogger("searxng-mcp.search")