Skip to main content
Glama

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

NameRequiredDescriptionDefault
categoryNoSearch categorygeneral
enginesNoComma-separated engine list
max_resultsNoMaximum results
queryYesSearch query

Input Schema (JSON Schema)

{ "properties": { "category": { "default": "general", "description": "Search category", "enum": [ "general", "news" ], "title": "Category", "type": "string" }, "engines": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Comma-separated engine list", "title": "Engines" }, "max_results": { "default": 10, "description": "Maximum results", "maximum": 50, "minimum": 1, "title": "Max Results", "type": "integer" }, "query": { "description": "Search query", "title": "Query", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • 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)]
  • 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)
  • 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}")
  • 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")

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/netixc/SearxngMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server