Skip to main content
Glama
Sacode

SearxNG MCP Server

by Sacode

web_search

Search the web through a privacy-respecting metasearch engine, returning results in human-readable text or structured JSON format with filtering options.

Instructions

Perform a web search using SearxNG and return formatted results.

Results are returned in either text format (human-readable) or JSON format depending on the result_format parameter selected.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query string to look for on the web
result_countNoMaximum number of results to return
categoriesNoCategories to filter by (e.g., 'general', 'images', 'news', 'videos')
languageNoLanguage code for results (e.g., 'all', 'en', 'ru', 'fr')all
time_rangeNoTime restriction for results
result_formatNoOutput format - 'text' for human-readable, 'json' for structured datatext

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'web_search' tool. Decorated with @mcp.tool() for automatic registration in FastMCP. Handles input parameters (defining the schema), performs the search via SearxNGClient, formats results in text or JSON, and includes error handling.
    @mcp.tool()
    async def web_search(
        query: str = _QUERY_FIELD,
        result_count: int = _RESULT_COUNT_FIELD,
        categories: list[str] | None = _CATEGORIES_FIELD,
        language: str | None = _LANGUAGE_FIELD,
        time_range: Literal["day", "week", "month", "year"] | None = _TIME_RANGE_FIELD,
        result_format: Literal["text", "json"] = _RESULT_FORMAT_FIELD,
        ctx: Context | None = None,
    ) -> str | list[SearxngResult]:
        """
        Perform a web search using SearxNG and return formatted results.
    
        Results are returned in either text format (human-readable) or JSON format
        depending on the result_format parameter selected.
    
        """
        try:
            # Inform about the search operation
            if ctx:
                await ctx.info("Starting web search...")
    
            # Validate inputs
            if result_count <= 0:
                raise ValueError("result_count must be greater than 0")
    
            # Perform the search using SearxNG
            response = await searxng_client.search(
                query=query,
                categories=categories,
                language=language,
                time_range=time_range,
            )
    
            results = response.results[:result_count]
    
            # Format results according to requested format
            if result_format == "json":
                # Return JSON-formatted results
                return results
            else:
                # Return human-readable text
                formatted_results = []
                for i, result in enumerate(results, 1):
                    title = result.title
                    url = result.url
                    content = result.content[:200] + "..."
                    formatted_results.append(f"{i}. [{title}]({url})\n   {content}")
    
                return "\n\n".join(formatted_results)
    
        except Exception as e:
            logger.error(f"Error during web search: {e}")
            if ctx:
                await ctx.info(f"Error during search: {e}")
            raise

Tool Definition Quality

Score is being calculated. Check back soon.

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/Sacode/searxng-simple-mcp'

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