Skip to main content
Glama

webSearch

Perform web searches via DuckDuckGo to retrieve relevant content for your queries, integrated into Apple MCP Tools for intelligent assistant workflows.

Instructions

Search the web using DuckDuckGo and retrieve content from search results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query to look up

Implementation Reference

  • The handleWebSearch function executes the tool logic: loads the webSearch module, calls its webSearch method with the query, formats the results into a text response, handles errors.
    export async function handleWebSearch(
      args: WebSearchArgs,
      loadModule: LoadModuleFunction
    ): Promise<ToolResult> {
      try {
        const webSearchModule = await loadModule('webSearch');
        const result = await webSearchModule.webSearch(args.query);
        
        return {
          content: [{
            type: "text",
            text: result.results.length > 0 ? 
              `Found ${result.results.length} results for "${args.query}". ${result.results.map(r => `[${r.displayUrl}] ${r.title} - ${r.snippet} \n content: ${r.content}`).join("\n")}` : 
              `No results found for "${args.query}".`
          }],
          isError: false
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error performing web search: ${error instanceof Error ? error.message : String(error)}`
          }],
          isError: true
        };
      }
    }
  • The core webSearch function in the module that performs DuckDuckGo search, extracts results, fetches and extracts content from top 5 results using parallel requests.
    export async function webSearch(query: string): Promise<ContentResponse> {
      try {
        // Step 1: Get search results from DuckDuckGo
        const searchResults = await searchDuckDuckGo(query);
    
        if (searchResults.error || searchResults.results.length === 0) {
          return {
            query,
            error: searchResults.error || "No search results found",
            results: [],
          };
        }
    
        // Step 2: Fetch content for each result (limit to 5 results to improve performance)
        const resultsToProcess = searchResults.results.slice(0, 5);
        
        // Use Promise.allSettled to ensure all requests complete, even if some fail
        const settledPromises = await Promise.allSettled(
          resultsToProcess.map(result => fetchPageContent(result.url))
        );
    
        // Process results
        const fullResults = resultsToProcess.map((result, index) => {
          const promise = settledPromises[index];
          
          if (promise.status === "fulfilled") {
            return {
              ...result,
              content: promise.value.content,
              error: promise.value.error
            };
          } else {
            // For rejected promises, return the result with an error
            return {
              ...result,
              content: null,
              error: `Failed to fetch content: ${promise.reason}`
            };
          }
        });
    
        return {
          query,
          results: fullResults,
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        console.error("Web search failed:", errorMessage);
        return {
          query,
          error: errorMessage,
          results: [],
        };
      }
    }
  • Zod schema for validating webSearch tool input arguments (query string).
    export const WebSearchArgsSchema = z.object({
      query: z.string().min(1),
    });
  • index.ts:136-139 (registration)
    Registration in the main switch statement: parses args with schema and calls handleWebSearch.
    case "webSearch": {
      const validatedArgs = WebSearchArgsSchema.parse(args);
      return await handleWebSearch(validatedArgs, loadModule);
    }
  • tools.ts:180-193 (registration)
    Tool specification/registration for listTools: defines name, description, and JSON input schema for webSearch.
    const WEB_SEARCH_TOOL: Tool = {
      name: "webSearch",
      description: "Search the web using DuckDuckGo and retrieve content from search results",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query to look up"
          }
        },
        required: ["query"]
      }
    };
Behavior2/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. While it mentions using DuckDuckGo and retrieving content from search results, it doesn't disclose important behavioral traits like rate limits, authentication requirements, result format, pagination behavior, or whether this is a read-only operation. The description is insufficient for a tool that interacts with external web services.

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 a single sentence that efficiently communicates the core functionality. It's front-loaded with the main action ('Search the web') followed by implementation details. There's no wasted verbiage, though it could potentially benefit from slightly more detail given the lack of annotations.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of web search operations and the complete lack of annotations and output schema, the description is insufficiently complete. It doesn't explain what kind of content is retrieved, how results are formatted, whether there are limitations on search scope, or what happens with no results. For a tool that interacts with external services and has no structured output documentation, this leaves significant gaps.

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?

The schema description coverage is 100%, with the single parameter 'query' clearly documented in the schema. The description adds no additional parameter semantics beyond what's already in the schema. According to the scoring guidelines, when schema coverage is high (>80%), the baseline is 3 even with no parameter information 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 with specific verbs ('Search the web', 'retrieve content') and identifies the resource (web via DuckDuckGo). It distinguishes itself from sibling tools like calendar or mail by focusing on web search functionality. However, it doesn't explicitly differentiate from potential similar search tools that might exist in other contexts.

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. It doesn't mention any prerequisites, limitations, or specific scenarios where web search is preferred over other information retrieval methods. With sibling tools like notes and reminders available, there's no indication of when web search is the appropriate choice.

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/wearesage/mcp-apple'

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