### Install DuckDuckGo Server via Smithery Source: https://github.com/nickclyde/duckduckgo-mcp-server/blob/main/README.md Installs the DuckDuckGo Search Server for Claude Desktop using the Smithery CLI. This command automates the setup process for integrating the server with Claude. ```bash npx -y @smithery/cli install @nickclyde/duckduckgo-mcp-server --client claude ``` -------------------------------- ### Development Setup with MCP CLI Source: https://github.com/nickclyde/duckduckgo-mcp-server/blob/main/README.md Commands for local development and testing of the DuckDuckGo Search MCP Server using the MCP CLI. These commands facilitate running the server in development mode and installing it locally for testing. ```bash # Run with the MCP Inspector mcp dev server.py # Install locally for testing with Claude Desktop mcp install server.py ``` -------------------------------- ### Install DuckDuckGo MCP Server Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Installs the DuckDuckGo MCP Server using package managers like uv or Smithery for Claude Desktop integration. This is the initial setup step for using the server. ```bash # Install via uv uv pip install duckduckgo-mcp-server # Or install via Smithery for Claude Desktop npx -y @smithery/cli install @nickclyde/duckduckgo-mcp-server --client claude ``` -------------------------------- ### Install DuckDuckGo Server via uv Source: https://github.com/nickclyde/duckduckgo-mcp-server/blob/main/README.md Installs the duckduckgo-mcp-server package directly from PyPI using the `uv` package installer. This is a standard Python package installation method. ```bash uv pip install duckduckgo-mcp-server ``` -------------------------------- ### Run DuckDuckGo MCP Server for Development and Testing Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Provides commands for running the DuckDuckGo MCP Server locally using MCP CLI tools. Includes options for debugging with MCP Inspector and installing the server for testing with Claude Desktop. ```bash # Run with MCP Inspector for debugging mcp dev server.py # Install locally for testing with Claude Desktop mcp install server.py ``` -------------------------------- ### Initialize Searcher and Fetcher with Rate Limiting Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Demonstrates the initialization of the DuckDuckGoSearcher and WebContentFetcher classes, each configured with specific request rate limits per minute. These are essential for managing API usage and preventing overload. ```python searcher = DuckDuckGoSearcher() # Uses RateLimiter(requests_per_minute=30) fetcher = WebContentFetcher() # Uses RateLimiter(requests_per_minute=20) ``` -------------------------------- ### Run DuckDuckGo MCP Server Directly with Python Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Shows how to execute the DuckDuckGo MCP Server directly using the Python interpreter. This method is useful for running the server as a standalone process. ```bash python -m duckduckgo_mcp_server.server ``` -------------------------------- ### Fetch Webpage Content with Python MCP Tool Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Defines the `fetch_content` tool for the MCP server using Python. It retrieves and parses content from a given URL, cleans the text, handles redirects and timeouts, and truncates long content. The function accepts a URL and an MCP context. ```python # MCP Tool Definition @mcp.tool() async def fetch_content(url: str, ctx: Context) -> str: """ Fetch and parse content from a webpage URL. Args: url: The webpage URL to fetch content from ctx: MCP context for logging """ # Successful response: Clean text content from the webpage (max 8000 chars) # Content longer than 8000 characters ends with: "... [content truncated]" # Error responses: # - Timeout: "Error: The request timed out while trying to fetch the webpage." # - HTTP Error: "Error: Could not access the webpage (404 Not Found)" # - Other: "Error: An unexpected error occurred while fetching the webpage (details)" ``` -------------------------------- ### Configure Claude Desktop to use DuckDuckGo Server Source: https://github.com/nickclyde/duckduckgo-mcp-server/blob/main/README.md Adds the DuckDuckGo Search MCP server configuration to Claude Desktop's settings. This allows Claude to utilize the server's search and content fetching capabilities. ```json { "mcpServers": { "ddg-search": { "command": "uvx", "args": ["duckduckgo-mcp-server"] } } } ``` -------------------------------- ### RateLimiter Class Implementation in Python Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Implements a `RateLimiter` class in Python to manage request rates within a sliding 1-minute window. It automatically queues requests when the limit is reached and waits for available slots, ensuring adherence to specified request limits per minute. ```python class RateLimiter: def __init__(self, requests_per_minute: int = 30): self.requests_per_minute = requests_per_minute self.requests = [] async def acquire(self): now = datetime.now() # Remove requests older than 1 minute self.requests = [ req for req in self.requests if now - req < timedelta(minutes=1) ] if len(self.requests) >= self.requests_per_minute: # Wait until we can make another request wait_time = 60 - (now - self.requests[0]).total_seconds() if wait_time > 0: await asyncio.sleep(wait_time) self.requests.append(now) # Usage within the searcher/fetcher: ``` -------------------------------- ### Python Content Fetching Tool Signature Source: https://github.com/nickclyde/duckduckgo-mcp-server/blob/main/README.md Defines the asynchronous function signature for the content fetching tool. It takes a URL string and returns the cleaned and formatted text content from the webpage as a string. ```python async def fetch_content(url: str) -> str ``` -------------------------------- ### Search DuckDuckGo with Python MCP Tool Source: https://context7.com/nickclyde/duckduckgo-mcp-server/llms.txt Defines the `search` tool for the MCP server using Python. It performs a DuckDuckGo search, handles rate limiting, filters ads, and formats results for LLM consumption. The function accepts a query, an optional `max_results` parameter, and an MCP context. ```python # MCP Tool Definition @mcp.tool() async def search(query: str, ctx: Context, max_results: int = 10) -> str: """ Search DuckDuckGo and return formatted results. Args: query: The search query string max_results: Maximum number of results to return (default: 10) ctx: MCP context for logging """ # Example output format: """ Found 10 search results: 1. Python Official Website URL: https://www.python.org/ Summary: The official home of the Python Programming Language... 2. Python Tutorial - W3Schools URL: https://www.w3schools.com/python/ Summary: Learn Python programming with examples and exercises... 3. Python (programming language) - Wikipedia URL: https://en.wikipedia.org/wiki/Python_(programming_language) Summary: Python is a high-level, general-purpose programming language... """ # When no results are found: """ No results were found for your search query. This could be due to DuckDuckGo's bot detection or the query returned no matches. Please try rephrasing your search or try again in a few minutes. """ ``` -------------------------------- ### Python Search Tool Signature Source: https://github.com/nickclyde/duckduckgo-mcp-server/blob/main/README.md Defines the asynchronous function signature for the search tool. It takes a query string and an optional maximum number of results, returning formatted search results as a string. ```python async def search(query: str, max_results: int = 10) -> str ```