Skip to main content
Glama
gianlucamazza

MCP DuckDuckGo Search Plugin

web_search

Search the web using DuckDuckGo to find relevant information, websites, and resources with detailed results including titles, URLs, and descriptions.

Instructions

Search the web using DuckDuckGo.

Returns a list of search results with titles, URLs, descriptions, and domains.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
max_resultsNoMaximum number of results to return (1-20)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function for the 'web_search' tool. Includes input schema via Pydantic Field annotations and executes the search logic using DuckDuckGo via the search_web helper.
    async def web_search(
        query: str = Field(..., description="Search query", max_length=400),
        max_results: int = Field(
            10, description="Maximum number of results to return (1-20)", ge=1, le=20
        ),
        ctx: Context = Field(default_factory=Context),
    ) -> Dict[str, Any]:
        """
        Search the web using DuckDuckGo.
    
        Returns a list of search results with titles, URLs, descriptions, and domains.
        """
        logger.info("Searching for: '%s' (max %d results)", query, max_results)
    
        try:
            # Get HTTP client from context
            http_client = None
            close_client = False
    
            # Try to get HTTP client from lifespan context
            if (
                hasattr(ctx, "lifespan_context")
                and ctx.lifespan_context
                and "http_client" in ctx.lifespan_context
            ):
                logger.info("Using HTTP client from lifespan context")
                http_client = ctx.lifespan_context["http_client"]
            else:
                # Create a new HTTP client
                logger.info("Creating new HTTP client")
                http_client = httpx.AsyncClient(timeout=10.0)
                close_client = True
    
            try:
                # Perform the search
                results = await search_web(query, http_client, max_results)
    
                # Convert to dict format
                search_results = [
                    {
                        "title": result.title,
                        "url": result.url,
                        "description": result.description,
                        "domain": result.domain,
                    }
                    for result in results
                ]
    
                return {
                    "query": query,
                    "results": search_results,
                    "total_results": len(search_results),
                    "status": "success",
                }
    
            finally:
                if close_client:
                    await http_client.aclose()
    
        except (httpx.RequestError, httpx.HTTPError, ValueError) as e:
            logger.error("Search failed: %s", e)
            return {
                "query": query,
                "results": [],
                "total_results": 0,
                "status": "error",
                "error": str(e),
            }
  • Registers the search tools (including web_search) by calling register_search_tools on the FastMCP server instance during server creation.
    def create_mcp_server() -> FastMCP:
        """Create and return a FastMCP server instance with proper tool registration."""
        server = FastMCP("DuckDuckGo Search", lifespan=app_lifespan)
    
        # Register tools directly with the server instance
        register_search_tools(server)
    
        return server
  • Core helper function that implements the DuckDuckGo web search logic, querying both the instant API and HTML search page, parsing results, and deduplicating them. Called by the web_search handler.
    async def search_web(
        query: str, http_client: httpx.AsyncClient, count: int = 10
    ) -> List[SearchResult]:
        """
        Main search function that tries multiple methods.
    
        Args:
            query: Search query string
            http_client: HTTP client to use for requests
            count: Maximum number of results to return
    
        Returns:
            List of unique SearchResult objects from both instant answers and HTML search
        """
        logger.info("Searching for: '%s' (max %d results)", query, count)
    
        # Try instant answers first
        instant_results = await search_duckduckgo_instant(query, http_client)
        logger.info("Instant answers found %d results", len(instant_results))
    
        # Always try HTML search for more comprehensive results
        html_results = await search_duckduckgo_html(query, http_client, count)
        logger.info("HTML search found %d results", len(html_results))
    
        # Combine and deduplicate
        all_results = instant_results + html_results
    
        # Remove duplicates based on URL
        seen_urls = set()
        unique_results = []
        for result in all_results:
            if result.url and result.url not in seen_urls and result.url.startswith("http"):
                seen_urls.add(result.url)
                unique_results.append(result)
                if len(unique_results) >= count:
                    break
    
        logger.info("Returning %d unique valid results", len(unique_results))
        return unique_results
  • Dataclass defining the structure of individual search results used in the output of web_search.
    @dataclass
    class SearchResult:
        title: str
        url: str
        description: str
        domain: str = ""
  • Utility function to extract the domain from a URL, used in search result processing.
    def extract_domain(url: str) -> str:
        """
        Extract domain from URL.
    
        Args:
            url: URL string to extract domain from
    
        Returns:
            Lowercase domain name or empty string if parsing fails
        """
        try:
            parsed = urllib.parse.urlparse(url)
            return parsed.netloc.lower()
        except Exception as e:
            logger.debug("Failed to extract domain from URL %s: %s", url, e)
            return ""
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the search engine (DuckDuckGo) and return format, but lacks critical details like rate limits, authentication needs, privacy implications, or error handling. For a tool with no annotation coverage, this leaves significant gaps in understanding its operational behavior.

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 extremely concise and front-loaded: two sentences that directly state the tool's function and output. Every sentence earns its place with no wasted words, making it easy to parse quickly.

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

Completeness3/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 (web search with two parameters), no annotations, and an output schema (implied by context signals), the description is minimally adequate. It covers the basic purpose and output format, but lacks usage guidelines and behavioral details that would be helpful for an AI agent, especially without annotations.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents both parameters (query and max_results). The description adds no additional parameter semantics beyond what's in the schema, such as query formatting tips or result ordering. This meets the baseline for high schema coverage but doesn't enhance understanding.

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: 'Search the web using DuckDuckGo' specifies the action (search) and resource (web via DuckDuckGo). It distinguishes from sibling tools like 'get_page_content' (which fetches specific page content) and 'suggest_related_searches' (which suggests queries), but could be more explicit about this differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose web_search over get_page_content (e.g., for broad queries vs. specific URLs) or suggest_related_searches (e.g., for refining searches). There's no context about use cases or exclusions.

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/gianlucamazza/mcp-duckduckgo'

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