Skip to main content
Glama
Jay4242

MCP SearxNG Search

by Jay4242

searxng_search

Perform web searches through a SearxNG instance to retrieve search results with titles, URLs, and content snippets for MCP-compatible applications.

Instructions

Searches the web using a SearxNG instance and returns a list of results.

Args:
    query: The search query.
    max_results: The maximum number of results to return. Defaults to 30.

Returns:
    A list of dictionaries, where each dictionary represents a search result
    and contains the title, URL, and content snippet.  Returns an error
    message in a dictionary if the search fails.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
max_resultsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'searxng_search' tool. It performs a POST request to the SearxNG search endpoint, parses the HTML results using BeautifulSoup, extracts title, URL, and content snippet for up to max_results items, and returns them as a list of dicts. Includes input validation and comprehensive error handling with McpError.
    @mcp.tool()
    def searxng_search(query: str, max_results: int = 30) -> List[Dict[str, str]]:
        """
        Searches the web using a SearxNG instance and returns a list of results.
    
        Args:
            query: The search query.
            max_results: The maximum number of results to return. Defaults to 30.
    
        Returns:
            A list of dictionaries, where each dictionary represents a search result
            and contains the title, URL, and content snippet.  Returns an error
            message in a dictionary if the search fails.
        """
        if max_results <= 0:
            raise McpError(ErrorData(INVALID_PARAMS, "max_results must be greater than 0."))
    
        search_url = f"{SEARXNG_BASE_URL}/search"
        headers = {
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
            'Accept-Language': 'en-US,en;q=0.9',
            'Cache-Control': 'no-cache',
            'Connection': 'keep-alive',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Pragma': 'no-cache',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent': USER_AGENT
        }
        data = f"q={query}&categories=general&language=auto&time_range=&safesearch=0&theme=simple"
    
        try:
            response = requests.post(search_url, headers=headers, data=data, verify=False, timeout=30)
            response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
            html_content = response.text
            soup = BeautifulSoup(html_content, 'html.parser')
            results = []
            for article in soup.find_all('article', class_='result')[:max_results]:
                url_header = article.find('a', class_='url_header')
                if url_header:
                    url = url_header['href']
                    title = article.find('h3').text.strip() if article.find('h3') else "No Title"
                    description = article.find('p', class_='content').text.strip() if article.find('p', class_='content') else "No Description"
                    results.append({
                        'title': title,
                        'url': url,
                        'content': description
                    })
            return results
        except requests.exceptions.RequestException as e:
            raise McpError(ErrorData(INTERNAL_ERROR, f"Error during search: {str(e)}"))
        except Exception as e:
            raise McpError(ErrorData(INTERNAL_ERROR, f"Unexpected error: {str(e)}"))
  • Registers and starts the MCP server instance (imported from server.py), making the 'searxng_search' tool available over the Model Context Protocol.
    mcp.run()
  • Creates the FastMCP server instance named 'searxng' to which the tool is registered via the @mcp.tool() decorator.
    mcp = FastMCP("searxng")
  • The function signature and docstring defining the input schema (query: str, optional max_results: int=30) and output schema (List[Dict[str, str]] with keys 'title', 'url', 'content').
    def searxng_search(query: str, max_results: int = 30) -> List[Dict[str, str]]:
        """
        Searches the web using a SearxNG instance and returns a list of results.
    
        Args:
            query: The search query.
            max_results: The maximum number of results to return. Defaults to 30.
    
        Returns:
            A list of dictionaries, where each dictionary represents a search result
            and contains the title, URL, and content snippet.  Returns an error
            message in a dictionary if the search fails.
        """
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions that the tool 'returns a list of results' and 'returns an error message in a dictionary if the search fails,' which adds some context about success and failure behaviors. However, it lacks details on rate limits, authentication needs, or other operational traits, leaving gaps in transparency for a tool that interacts with external services.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with a clear purpose statement followed by structured sections for 'Args' and 'Returns.' Each sentence earns its place by providing essential information without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is reasonably complete. It covers the purpose, parameters, and return values, and the output schema likely details the result structure, reducing the need for extensive return explanations. However, it could improve by addressing potential errors or usage constraints more explicitly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema. The schema has 0% description coverage, but the description explains that 'query' is 'The search query' and 'max_results' is 'The maximum number of results to return. Defaults to 30.' This clarifies the purpose and default value, compensating well for the low schema coverage. However, it doesn't detail constraints like query length or result range limits.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Searches the web using a SearxNG instance and returns a list of results.' It specifies the verb ('searches'), resource ('the web'), and mechanism ('using a SearxNG instance'), making it easy to understand what the tool does. However, since there are no sibling tools mentioned, it doesn't need to differentiate from alternatives, so it doesn't reach the highest score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through its purpose statement but lacks explicit guidance on when to use this tool versus alternatives. With no sibling tools provided, there's no need to distinguish from them, but it doesn't offer any context on prerequisites, limitations, or best practices. This results in an implied usage scenario without detailed exclusions or recommendations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/Jay4242/mcp_searxng_search'

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