DuckDuckGo MCP Server

repository·main·Indexed 20 days ago

https://github.com/nickclyde/duckduckgo-mcp-server

A Model Context Protocol (MCP) server providing web search capabilities via DuckDuckGo, including tools for searching and fetching/parsing webpage content. Version 0.6.1 supports multiple HTTP backends (httpx, curl, auto) to bypass bot detection, configurable SafeSearch levels, and region localization. It can be run via stdio, SSE, or streamable-http transports and includes an SSRF guard for private URL restrictions.

Tokens
3K
Snippets
4
Records
17
Agent score
30%

What's inside duckduckgo-mcp-server

  1. Configure HTTP Backends (httpx vs curl)

    main

    To bypass bot detection (like Cloudflare), you can use the curl backend, which requires the [browser] extra installation.

    Available Backends:

    • httpx: Lightweight async HTTP. Default. Works on most sites.
    • curl: Uses curl_cffi with Chrome 131 TLS impersonation. Passes TLS-fingerprint-based filters. (Requires [browser] extra).
    • auto: Tries httpx first; retries with curl on 403 or Cloudflare challenge responses. (Requires [browser] extra).

    Server-wide configuration via CLI flags:

    • --fetch-backend <value>: Sets the default backend for fetch_content calls.
    • --search-backend <value>: Sets the default backend for search calls.

    Example: Using the auto backend for fetching:

    uvx --with "duckduckgo-mcp-server[browser]" duckduckgo-mcp-server --fetch-backend auto
    uvx --with "duckduckgo-mcp-server[browser]" duckduckgo-mcp-server --fetch-backend auto
  2. Understand rate limits and result processing

    main

    The server implements automatic queue management and wait times to handle the following rate limits:

    • Search: 30 requests per minute
    • Content Fetching: 20 requests per minute

    To optimize results for LLM consumption, the server automatically:

    • Removes ads and irrelevant content
    • Cleans up DuckDuckGo redirect URLs
    • Formats results for LLMs
    • Truncates long content appropriately
  3. Install the DuckDuckGo MCP Server

    main

    You can install the server using uv from PyPI.

    For the standard installation (uses httpx backend):

    uv pip install duckduckgo-mcp-server

    For the installation with the optional browser backend (required for curl and auto backends to bypass bot detection):

    uv pip install "duckduckgo-mcp-server[browser]"
    uv pip install "duckduckgo-mcp-server[browser]"
  4. Configure DuckDuckGo MCP Server for Claude Desktop

    main

    To use the server with Claude Desktop, add it to your claude_desktop_config.json file.

    Locations:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json

    Basic Configuration:

    {
        "mcpServers": {
            "ddg-search": {
                "command": "uvx",
                "args": ["duckduckgo-mcp-server"]
            }
        }
    }

    Advanced Configuration (SafeSearch and Region): Use environment variables to control filtering and localization.

    {
        "mcpServers": {
            "ddg-search": {
                "command": "uvx",
                "args": ["duckduckgo-mcp-server"],
                "env": {
                    "DDG_SAFE_SEARCH": "STRICT",
                    "DDG_REGION": "cn-zh"
                }
            }
        }
    }
    {
        "mcpServers": {
            "ddg-search": {
                "command": "uvx",
                "args": ["duckduckgo-mcp-server"],
                "env": {
                    "DDG_SAFE_SEARCH": "STRICT",
                    "DDG_REGION": "cn-zh"
                }
            }
        }
    }
  5. Configure DuckDuckGo Search Environment Variables

    main

    The following environment variables can be used to configure the server behavior:

    • DDG_SAFE_SEARCH: SafeSearch filtering level.
      • STRICT: Maximum content filtering (kp=1).
      • MODERATE: Balanced filtering (kp=-1, default).
      • OFF: No content filtering (kp=-2).
    • DDG_REGION: Default region/language code (e.g., us-en, cn-zh, jp-ja, wt-wt).
    • DDG_CA_CERTS: Path to a PEM CA bundle for TLS verification (useful behind TLS-intercepting proxies).
    • DDG_ALLOWED_HOSTS: Comma-separated list of allowed hosts for DNS-rebinding protection.
    • DDG_ALLOWED_ORIGINS: Comma-separated list of allowed origins for DNS-rebinding protection.
    • DDG_DISABLE_DNS_REBINDING_PROTECTION: Set to 1 to disable DNS-rebinding protection (not recommended).
    • DDG_ALLOW_PRIVATE_URLS: Set to 1 to allow fetch_content to access private/loopback URLs.
    • DDG_SEARCH_BACKEND: Sets the default backend for the search tool (auto, httpx, or curl).
  6. Understand the SSRF guard and private URL restrictions

    main

    To prevent Server-Side Request Forgery (SSRF), the fetch_content tool includes a security guard that rejects URLs resolving to loopback, private (RFC1918), link-local, reserved, multicast, or unspecified addresses.

    If you need to fetch from internal/private hosts in a trusted environment, you must:

    1. Set the environment variable DDG_ALLOW_PRIVATE_URLS=1.
    2. Or, if using the underlying API, set allow_private_urls=True in the WebContentFetcher constructor.
  7. Configure search and fetch backends

    main

    The server supports different HTTP backends to handle bot detection and TLS fingerprinting:

    • httpx: The default lightweight async HTTP client.
    • curl: Uses curl_cffi for Chrome TLS impersonation. This is highly effective at bypassing Cloudflare and other bot filters. Requires installation via pip install 'duckduckgo-mcp-server[browser]'.
    • auto: The recommended setting. It tries httpx first and transparently falls back to curl if it detects a fingerprint-based block (HTTP 202 or 403) or a Cloudflare challenge.
  8. Configure Region Localization

    main
    You can set a default geographic region for search results using the DDG_REGION environment variable. While the server has a default region, AI assistants can override this setting on a per-search-request basis to improve relevance for specific locations.
  9. Configure SafeSearch filtering

    main
    The server supports SafeSearch filtering to prevent inappropriate content from being returned to the LLM. This is configured at server startup using the DDG_SAFE_SEARCH environment variable. Note that this setting is controlled by the administrator and cannot be modified by the AI assistant during a session.
  10. Use the fetch_content tool

    main

    Fetches and parses content from a webpage.

    Signature: async def fetch_content(url: str, start_index: int = 0, max_length: int = 8000, backend: Optional[str] = None) -> str

    Parameters:

    • url: The webpage URL to fetch.
    • start_index: Character offset to start reading from (for pagination).
    • max_length: Maximum number of characters to return.
    • backend: (Optional) Per-call override of the default fetch backend ("httpx", "curl", or "auto").

    Returns: Cleaned and formatted text content from the webpage.

    Security Note: By default, fetch_content refuses URLs that resolve to loopback, private (RFC1918), link-local, or reserved addresses. To allow these, use DDG_ALLOW_PRIVATE_URLS=1 or the --allow-private-urls flag.

  11. Use the search tool

    main

    Performs a web search on DuckDuckGo and returns formatted results.

    Signature: async def search(query: str, max_results: int = 10, region: str = "") -> str

    Parameters:

    • query: Search query string.
    • max_results: Maximum number of results to return (default: 10).
    • region: (Optional) Region/language code to override the default (e.g., us-en, jp-ja).

    Returns: Formatted string containing search results with titles, URLs, and snippets.

  12. Configure the server via environment variables

    main

    The DuckDuckGo MCP Server can be customized using several environment variables:

    VariableDescription
    DDG_SAFE_SEARCHSafeSearch mode: STRICT, MODERATE (default), or OFF.
    DDG_REGIONDefault region code (e.g., us-en).
    DDG_SEARCH_BACKENDSearch backend: httpx, curl, or auto (default).
    DDG_ALLOW_PRIVATE_URLSSet to 1, true, yes, or on to allow fetching from private/internal addresses (disables SSRF guard).
    DDG_CA_CERTSPath to a CA bundle for TLS verification.
    DDG_SSL_VERIFYEnable/disable TLS verification (1/true to enable, 0/false to disable).
    DDG_ALLOWED_HOSTSComma-separated list of allowed hosts for HTTP transport security.
    DDG_ALLOWED_ORIGINSComma-separated list of allowed origins for HTTP transport security.
    DDG_DISABLE_DNS_REBINDING_PROTECTIONSet to 1, true, etc., to disable DNS rebinding protection.