Skip to main content
Glama
zhsama

DuckDuckGo MCP Server

by zhsama

duckduckgo_web_search

Perform web searches using DuckDuckGo to gather diverse information, news, articles, and online content with support for filtering, region-specific results, and SafeSearch controls.

Instructions

Performs a web search using the DuckDuckGo, ideal for general queries, news, articles, and online content. Use this for broad information gathering, recent events, or when you need diverse web sources. Supports content filtering and region-specific searches. Maximum 20 results per request.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of results (1-20, default 10)
queryYesSearch query (max 400 chars)
safeSearchNoSafeSearch level (strict, moderate, off)moderate

Implementation Reference

  • Core handler function that performs the DuckDuckGo web search. Calls DDG.search, handles rate limiting via checkRateLimit, processes results, and returns formatted Markdown output.
    async function performWebSearch(
      query: string,
      count: number = CONFIG.search.defaultResults,
      safeSearch: "strict" | "moderate" | "off" = CONFIG.search.defaultSafeSearch
    ): Promise<string> {
      console.error(
        `[DEBUG] Performing search - Query: "${query}", Count: ${count}, SafeSearch: ${safeSearch}`
      );
    
      try {
        checkRateLimit();
    
        const safeSearchMap = {
          strict: DDG.SafeSearchType.STRICT,
          moderate: DDG.SafeSearchType.MODERATE,
          off: DDG.SafeSearchType.OFF,
        };
    
        const searchResults = await DDG.search(query, {
          safeSearch: safeSearchMap[safeSearch],
        });
    
        if (searchResults.noResults) {
          console.error(`[INFO] No results found for query: "${query}"`);
          return `# DuckDuckGo 搜索结果\n没有找到与 "${query}" 相关的结果。`;
        }
    
        const results: SearchResult[] = searchResults.results
          .slice(0, count)
          .map((result: DDG.SearchResult) => ({
            title: result.title,
            description: result.description || result.title,
            url: result.url,
          }));
    
        console.error(
          `[INFO] Found ${results.length} results for query: "${query}"`
        );
    
        // 格式化结果
        return formatSearchResults(query, results);
      } catch (error) {
        console.error(`[ERROR] Search failed - Query: "${query}"`, error);
        throw error;
      }
    }
  • JSON Schema definition for the tool's input parameters, including query, count, and safeSearch with constraints and defaults.
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: `Search query (max ${CONFIG.search.maxQueryLength} chars)`,
            maxLength: CONFIG.search.maxQueryLength,
          },
          count: {
            type: "number",
            description: `Number of results (1-${CONFIG.search.maxResults}, default ${CONFIG.search.defaultResults})`,
            minimum: 1,
            maximum: CONFIG.search.maxResults,
            default: CONFIG.search.defaultResults,
          },
          safeSearch: {
            type: "string",
            description: "SafeSearch level (strict, moderate, off)",
            enum: ["strict", "moderate", "off"],
            default: CONFIG.search.defaultSafeSearch,
          },
        },
        required: ["query"],
      },
    };
  • src/index.ts:225-227 (registration)
    Registers the tool by including it in the list returned for ListTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [WEB_SEARCH_TOOL],
    }));
  • Tool dispatcher case in the CallToolRequest handler that validates arguments and invokes the performWebSearch function.
    case "duckduckgo_web_search": {
      if (!isDuckDuckGoWebSearchArgs(args)) {
        throw new Error("Invalid arguments for duckduckgo_web_search");
      }
    
      const {
        query,
        count = CONFIG.search.defaultResults,
        safeSearch = CONFIG.search.defaultSafeSearch,
      } = args;
      const results = await performWebSearch(query, count, safeSearch);
    
      return {
        content: [{ type: "text", text: results }],
        isError: false,
      };
    }
  • Helper function to format search results into a structured Markdown response.
    function formatSearchResults(query: string, results: SearchResult[]): string {
      const formattedResults = results
        .map((r: SearchResult) => {
          return `### ${r.title}
    ${r.description}
    
    🔗 [阅读更多](${r.url})
    `;
        })
        .join("\n\n");
    
      return `# DuckDuckGo 搜索结果
    ${query} 的搜索结果(${results.length}件)
    
    ---
    
    ${formattedResults}
    `;
    }
Behavior3/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 adds useful context like 'maximum 20 results per request' and mentions content filtering and region-specific searches, but does not cover aspects like rate limits, authentication needs, or error handling, leaving gaps in behavioral understanding.

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 sized with three sentences that efficiently cover purpose, usage, and constraints. It is front-loaded with the core function and avoids unnecessary repetition, though minor improvements in flow could elevate it to a 5.

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 (3 parameters, no output schema, no annotations), the description provides a basic overview but lacks details on return values, error cases, or advanced usage. It is adequate for a simple search tool but incomplete for robust agent interaction.

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 all parameters. The description does not add any parameter-specific details beyond what the schema provides, such as explaining the impact of 'safeSearch' levels or query formatting. Baseline 3 is appropriate as the schema handles the heavy lifting.

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 'performs a web search using DuckDuckGo' with specific use cases like 'general queries, news, articles, and online content.' It distinguishes itself as a general-purpose search tool, though without sibling tools to differentiate from, it cannot achieve a perfect 5.

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 provides implied usage guidance with phrases like 'ideal for general queries' and 'use this for broad information gathering,' but lacks explicit when-not-to-use scenarios or alternatives. Without sibling tools, it cannot offer comparative guidance, limiting its score.

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

Related 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/zhsama/duckduckgo-mcp-server'

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