Skip to main content
Glama

Web Search

web-search

Search the web using DuckDuckGo to find current information, articles, documentation, and web content. Returns titles, URLs, and snippets for research and fact-finding.

Instructions

Search the web for information using DuckDuckGo. Returns titles, URLs, and snippets of search results. Useful for finding current information, articles, documentation, and general web content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query to look up on the web
max_resultsNoMaximum number of results to return (1-10, default: 5)

Implementation Reference

  • The main execution handler for the 'web-search' tool. It calls performWebSearch, formats the results, and returns them as text content or an error message.
    async ({ query, max_results = 5 }) => {
    	try {
    		const results = await performWebSearch(query, max_results);
    		const formattedResults = formatSearchResults(query, results);
    
    		return {
    			content: [
    				{
    					type: "text" as const,
    					text: formattedResults,
    				},
    			],
    		};
    	} catch (error) {
    		return {
    			content: [
    				{
    					type: "text" as const,
    					text: `Error performing web search: ${error instanceof Error ? error.message : "Unknown error"}`,
    				},
    			],
    			isError: true,
    		};
    	}
    },
  • Zod-based input schema for the web-search tool, defining 'query' (required string) and optional 'max_results' (1-10).
    inputSchema: {
    	query: z.string().min(1).describe("The search query to look up on the web"),
    	max_results: z
    		.number()
    		.int()
    		.min(1)
    		.max(10)
    		.optional()
    		.describe("Maximum number of results to return (1-10, default: 5)"),
    },
  • The server.registerTool call within registerWebSearchTool that defines and registers the 'web-search' tool including name, metadata, schema, and handler.
    server.registerTool(
    	"web-search",
    	{
    		title: "Web Search",
    		description:
    			"Search the web for information using DuckDuckGo. Returns titles, URLs, and snippets of search results. Useful for finding current information, articles, documentation, and general web content.",
    		inputSchema: {
    			query: z.string().min(1).describe("The search query to look up on the web"),
    			max_results: z
    				.number()
    				.int()
    				.min(1)
    				.max(10)
    				.optional()
    				.describe("Maximum number of results to return (1-10, default: 5)"),
    		},
    	},
    	async ({ query, max_results = 5 }) => {
    		try {
    			const results = await performWebSearch(query, max_results);
    			const formattedResults = formatSearchResults(query, results);
    
    			return {
    				content: [
    					{
    						type: "text" as const,
    						text: formattedResults,
    					},
    				],
    			};
    		} catch (error) {
    			return {
    				content: [
    					{
    						type: "text" as const,
    						text: `Error performing web search: ${error instanceof Error ? error.message : "Unknown error"}`,
    					},
    				],
    				isError: true,
    			};
    		}
    	},
    );
  • Invocation of registerWebSearchTool in the central tools registration function, followed by logging.
    registerWebSearchTool(server);
    logger.tool("web-search", "registered");
  • Helper function that performs the web search by fetching DuckDuckGo HTML results and parsing up to maxResults.
    async function performWebSearch(query: string, maxResults = 5): Promise<SearchResult[]> {
    	try {
    		// Use DuckDuckGo HTML endpoint
    		const searchUrl = new URL("https://html.duckduckgo.com/html/");
    		searchUrl.searchParams.append("q", query);
    		searchUrl.searchParams.append("kl", "us-en");
    
    		const response = await fetch(searchUrl.toString(), {
    			headers: {
    				"User-Agent": "Mozilla/5.0 (compatible; DuyetMCP/0.1; +https://duyet.net/)",
    			},
    		});
    
    		if (!response.ok) {
    			throw new Error(`Search request failed with status: ${response.status}`);
    		}
    
    		const html = await response.text();
    		const results = parseDuckDuckGoResults(html);
    
    		return results.slice(0, maxResults);
    	} catch (error) {
    		console.error("Web search error:", error);
    		throw new Error("Failed to perform web search");
    	}
    }
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 adequately describes the core behavior (searching via DuckDuckGo and returning results) but lacks details about rate limits, authentication needs, error handling, or whether it's read-only/destructive. The mention of 'current information' hints at real-time capabilities but isn't explicit about freshness or limitations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in two sentences: the first states the action and output, the second provides usage context. Every sentence adds value without redundancy, and it's front-loaded with the core functionality.

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 (2 parameters, no annotations, no output schema), the description is minimally adequate. It covers the purpose and usage but lacks details on output format beyond high-level types, error cases, or operational constraints. Without annotations or output schema, more behavioral context would be helpful for an agent.

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 already fully documents both parameters ('query' and 'max_results'). The description doesn't add any parameter-specific semantics beyond what's in the schema, such as query formatting tips or result ordering. This meets the baseline of 3 when schema coverage is high.

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 with specific verbs ('Search the web') and resources ('using DuckDuckGo'), and distinguishes it from siblings by specifying it's for web search rather than analytics, blog content, GitHub activity, or other functions. It explicitly mentions what it returns ('titles, URLs, and snippets of search results').

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('Useful for finding current information, articles, documentation, and general web content'), which helps differentiate it from siblings like 'web-fetch' (likely for fetching specific URLs) or content-specific tools. However, it doesn't explicitly state when NOT to use it or name specific alternatives.

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/duyet/duyet-mcp-server'

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