Skip to main content
Glama
varlabz

DuckDuckGo MCP Server

by varlabz

search

Perform web searches to find information, images, videos, or news with customizable parameters like region, safe search, and time limits. Returns structured results with titles, URLs, and snippets for comprehensive research.

Instructions

Search the web using DuckDuckGo.

This tool performs a web search using DuckDuckGo and returns structured results
including titles, URLs, and body snippets.

Args:
    query: The search query string
    max_results: Maximum number of results to return (1-50)
    region: Region code for localized results (optional)
    safesearch: Safe search filtering level
    timelimit: Time limit for results (day, week, month, year)

Returns:
    SearchResponse with query, results, and total count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
max_resultsNoMaximum number of results to return (1-50)
categoriesNoResult type to search: text (default), images, videos, or newstext
regionNoRegion code (e.g., 'us-en', 'uk-en', 'de-de')
safesearchNoSafe search leveloff
timelimitNoTime limit for results

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query that was executed
resultsYesList of search results
total_resultsYesTotal number of results returned

Implementation Reference

  • The handler function that executes the 'search' tool logic, performing DuckDuckGo web searches (text, news, images, videos) using the ddgs library and returning structured SearchResponse.
    def search_tool(
        query: str,
        max_results: Annotated[
            int,
            Field(ge=1, le=50, description="Maximum number of results to return (1-50)"),
        ] = 10,
        categories: Annotated[
            Literal["text", "images", "videos", "news"],
            Field(description="Result type to search: text (default), images, videos, or news"),
        ] = "text",
        region: Annotated[
            str | None,
            Field(description="Region code (e.g., 'us-en', 'uk-en', 'de-de')"),
        ] = None,
        safesearch: Annotated[
            Literal["on", "moderate", "off"],
            Field(description="Safe search level"),
        ] = "off",
        timelimit: Annotated[
            Literal["day", "week", "month", "year"] | None,
            Field(description="Time limit for results"),
        ] = None,
    ) -> SearchResponse:
        """Search the web using DuckDuckGo.
    
        This tool performs a web search using DuckDuckGo and returns structured results
        including titles, URLs, and body snippets.
    
        Args:
            query: The search query string
            max_results: Maximum number of results to return (1-50)
            region: Region code for localized results (optional)
            safesearch: Safe search filtering level
            timelimit: Time limit for results (day, week, month, year)
    
        Returns:
            SearchResponse with query, results, and total count
        """
        # map timelimit values to ddgs parameters
        tl = (
            {
                "day": "d",
                "week": "w",
                "month": "m",
                "year": "y",
            }.get(timelimit.strip().lower(), None)
            if timelimit
            else None
        )
        client = DDGS()
        region_param = region or "us-en"
        if categories == "text":
            raw_results = client.text(
                query,
                max_results=max_results,
                region=region_param,
                safesearch=safesearch,
                timelimit=tl,
            )
        elif categories == "news":
            raw_results = client.news(
                query,
                max_results=max_results,
                region=region_param,
                safesearch=safesearch,
                timelimit=tl,
            )
        elif categories == "images":
            raw_results = client.images(
                query,
                max_results=max_results,
                region=region_param,
                safesearch=safesearch,
                timelimit=tl,
            )
            
        elif categories == "videos":
            raw_results = client.videos(
                query,
                max_results=max_results,
                region=region_param,
                safesearch=safesearch,
                timelimit=tl,
            )
        else:
            # Fallback to text in case of unexpected value
            raw_results = client.text(
                query,
                max_results=max_results,
                region=region_param,
                safesearch=safesearch,
                timelimit=tl,
            )
    
        # Convert to structured results
        results: list[SearchResult] = []
        for result in raw_results:
            title = result.get("title", "No title")
            # Prefer common link keys across result types
            url = (
                result.get("href")
                or result.get("url")
                or result.get("content")  # videos
                or result.get("image")  # images direct link
                or "No URL"
            )
            body = (
                result.get("body")
                or result.get("description")  # videos
                or "No body"
            )
            results.append(SearchResult(title=title, url=url, body=body))
    
        return SearchResponse(query=query, results=results, total_results=len(results))
  • Pydantic model defining the output schema of the search tool response.
    class SearchResponse(BaseModel):
        """Response containing search results."""
    
        query: str = Field(description="The search query that was executed")
        results: list[SearchResult] = Field(description="List of search results")
        total_results: int = Field(description="Total number of results returned")
  • Pydantic model defining the schema for individual search results used in the tool output.
    class SearchResult(BaseModel):
        """A single search result from DuckDuckGo."""
    
        title: str = Field(description="The title of the search result")
        url: str = Field(description="The URL of the search result")
        body: str = Field(description="The body/snippet of the search result")
  • FastMCP decorator that registers the search_tool function as the MCP tool named 'search'.
    @mcp.tool(name="search")
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it specifies the search engine (DuckDuckGo), describes the structured format of results (titles, URLs, snippets), and mentions the return type (SearchResponse). However, it doesn't cover potential limitations like rate limits, authentication needs, or error conditions.

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 well-structured with clear sections (purpose, behavior, args, returns) and appropriately sized. Every sentence adds value, though the parameter explanations could be more concise since they largely duplicate schema information. The front-loaded purpose statement is excellent.

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 (6 parameters, 1 required), no annotations, but with an output schema (SearchResponse), the description is reasonably complete. It covers purpose, behavior, parameters, and return type. The main gap is lack of operational constraints (rate limits, errors) which would be helpful despite the output schema.

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 high at 83%, so the baseline is 3. The description adds some value by listing all parameters with brief explanations, but doesn't provide significant additional semantic context beyond what's already in the schema descriptions. The parameter explanations in the description are largely redundant with the schema.

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

Purpose5/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' with specific verb ('search') and resource ('web'). It distinguishes itself by specifying the search engine (DuckDuckGo) and the structured nature of results. With no sibling tools, this level of specificity is excellent.

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 context through parameter explanations (e.g., region for localization, safesearch for filtering), but provides no explicit guidance on when to use this tool versus alternatives. Since there are no sibling tools mentioned, the lack of comparative guidance is less critical, but still represents a gap in proactive usage direction.

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

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