Skip to main content
Glama
gianlucamazza

MCP DuckDuckGo Search Plugin

suggest_related_searches

Expand search queries with related suggestions from DuckDuckGo's autocomplete API to discover alternative search terms and explore topics more thoroughly.

Instructions

Get search suggestions from DuckDuckGo autocomplete API.

Returns suggestions based on what people actually search for.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesOriginal search query
max_suggestionsNoMaximum number of related suggestions to return

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that implements the core logic of the 'suggest_related_searches' tool. It fetches autocomplete suggestions using a helper function and returns formatted results. Includes input schema via Pydantic Field validators.
    @mcp_server.tool()
    async def suggest_related_searches(
        query: str = Field(..., description="Original search query"),
        max_suggestions: int = Field(
            5,
            ge=1,
            le=10,
            description="Maximum number of related suggestions to return",
        ),
        ctx: Context = Field(default_factory=Context),
    ) -> Dict[str, Any]:
        """
        Get search suggestions from DuckDuckGo autocomplete API.
    
        Returns suggestions based on what people actually search for.
        """
        logger.info(
            "Getting autocomplete suggestions for: '%s' (max %d suggestions)",
            query,
            max_suggestions,
        )
    
        # Get HTTP client from context
        http_client = None
        close_client = False
    
        try:
            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:
                logger.info("Creating new HTTP client")
                http_client = httpx.AsyncClient(timeout=10.0)
                close_client = True
    
            # Get autocomplete suggestions from DuckDuckGo
            suggestions = await get_autocomplete_suggestions(query, http_client)
    
            return {
                "original_query": query,
                "related_searches": suggestions[:max_suggestions],
                "count": len(suggestions[:max_suggestions]),
            }
    
        except (httpx.RequestError, httpx.HTTPError, ValueError) as e:
            logger.error("Failed to get autocomplete suggestions: %s", e)
            return {
                "original_query": query,
                "related_searches": [],
                "count": 0,
                "error": str(e),
            }
        finally:
            if close_client and http_client:
                await http_client.aclose()
  • Supporting utility function that performs the HTTP request to DuckDuckGo's autocomplete API to retrieve related search suggestions. Called directly by the handler.
    async def get_autocomplete_suggestions(
        query: str, http_client: httpx.AsyncClient
    ) -> List[str]:
        """Get search suggestions from DuckDuckGo autocomplete API."""
        try:
            url = "https://duckduckgo.com/ac/"
            params = {"q": query, "type": "list"}
    
            response = await http_client.get(url, params=params, timeout=10)
            response.raise_for_status()
    
            data = response.json()
            # Response format: ["query", ["suggestion1", "suggestion2", ...]]
            suggestions = data[1] if len(data) > 1 and isinstance(data[1], list) else []
    
            logger.info("Found %d autocomplete suggestions", len(suggestions))
            return suggestions
    
        except (httpx.RequestError, httpx.HTTPError, ValueError) as e:
            logger.error("Failed to get autocomplete suggestions: %s", e)
            return []
  • Invocation of register_search_tools(server), which executes the nested function definitions and @tool() decorators to register the 'suggest_related_searches' handler (and other tools) with the MCP server instance.
    register_search_tools(server)
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the API source (DuckDuckGo autocomplete) and that suggestions are based on real search data, but lacks critical details: authentication requirements, rate limits, error handling, response format (though output schema exists), or whether this is a read-only operation. For a tool with no annotation coverage, this leaves significant gaps.

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

Conciseness4/5

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

The description is appropriately concise with two clear sentences. The first sentence states the core purpose, and the second adds valuable context about the data source. There's no unnecessary repetition or fluff. It could be slightly improved with more structured guidance, but it's efficiently written.

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 that an output schema exists (which handles return values), the description doesn't need to explain return values. However, for a tool with no annotations and two parameters, the description should provide more behavioral context about API limitations, error cases, or typical use patterns. The current description is minimally adequate but leaves room for improvement in completeness.

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 already fully documents both parameters ('query' and 'max_suggestions'). The description adds no additional parameter semantics beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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: 'Get search suggestions from DuckDuckGo autocomplete API' specifies both the verb ('Get') and resource ('search suggestions'), and 'Returns suggestions based on what people actually search for' adds useful context about the data source. However, it doesn't explicitly differentiate from sibling tools like 'web_search' or 'get_page_content', which would require a 5.

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 like 'web_search' or 'get_page_content'. There's no mention of use cases, prerequisites, or exclusions. The only implied usage is for obtaining search suggestions, but this is too vague for effective tool selection.

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