Skip to main content
Glama
Mantraa-Zzz

Web Search MCP Server

by Mantraa-Zzz

web_search

Search the internet using Google Custom Search API to find relevant web pages and summaries based on your query, with options to specify language and result limits.

Instructions

在互联网上搜索信息,返回相关的网页链接和摘要

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNo搜索语言(如:zh-CN, en-US)zh-CN
maxResultsNo最大返回结果数量(默认10)
queryYes搜索查询关键词

Implementation Reference

  • Primary handler function for the 'web_search' tool. Parses input arguments, performs web search (real or mock), formats results as markdown text, and returns as MCP content.
    private async handleWebSearch(args: any) {
      const { query, maxResults = 10, language = 'zh-CN' } = args;
    
      if (!this.searchApiKey || !this.searchEngineId) {
        // 如果没有配置API密钥,使用模拟数据
        return this.getMockSearchResults(query, maxResults);
      }
    
      try {
        const results = await this.performWebSearch(query, maxResults, language);
        
        const formattedResults = results.map((result, index) => 
          `${index + 1}. **${result.title}**\n   URL: ${result.url}\n   摘要: ${result.snippet}\n`
        ).join('\n');
    
        return {
          content: [
            {
              type: 'text',
              text: `搜索 "${query}" 的结果:\n\n${formattedResults}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`搜索失败: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core helper function that performs the actual web search using Google Custom Search API via axios, mapping results to SearchResult interface.
    private async performWebSearch(query: string, maxResults: number, language: string): Promise<SearchResult[]> {
      const url = `https://www.googleapis.com/customsearch/v1`;
      const params = {
        key: this.searchApiKey,
        cx: this.searchEngineId,
        q: query,
        num: Math.min(maxResults, 10),
        lr: `lang_${language}`,
      };
    
      const response = await axios.get(url, {
        params,
        timeout: this.requestTimeout,
      });
    
      const items = response.data.items || [];
      return items.map((item: any, index: number) => ({
        title: item.title,
        url: item.link,
        snippet: item.snippet,
        rank: index + 1,
      }));
    }
  • Input schema definition for the web_search tool, specifying query (required), maxResults, and language parameters.
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: '搜索查询关键词',
        },
        maxResults: {
          type: 'number',
          description: '最大返回结果数量(默认10)',
          default: 10,
        },
        language: {
          type: 'string',
          description: '搜索语言(如:zh-CN, en-US)',
          default: 'zh-CN',
        },
      },
      required: ['query'],
    },
  • src/index.ts:74-97 (registration)
    Registration of the web_search tool in the ListToolsRequestHandler, including name, description, and schema.
    {
      name: 'web_search',
      description: '在互联网上搜索信息,返回相关的网页链接和摘要',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '搜索查询关键词',
          },
          maxResults: {
            type: 'number',
            description: '最大返回结果数量(默认10)',
            default: 10,
          },
          language: {
            type: 'string',
            description: '搜索语言(如:zh-CN, en-US)',
            default: 'zh-CN',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:156-157 (registration)
    Dispatch/registration of web_search handler in the CallToolRequestHandler switch statement.
    case 'web_search':
      return await this.handleWebSearch(args);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions returning '网页链接和摘要' (webpage links and summaries), which is useful behavioral context. However, it doesn't disclose important traits like rate limits, authentication needs, result freshness, or whether this is a read-only operation (though implied by '搜索'). For a search tool with zero annotation coverage, this leaves significant gaps.

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 perfectly concise - a single sentence that states the core function and what it returns. Every word earns its place with no redundancy or unnecessary elaboration. It's front-loaded with the main purpose.

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 this is a search tool with 3 parameters, 100% schema coverage, but no annotations and no output schema, the description provides basic completeness. It covers the core function and return format, but doesn't address behavioral aspects like rate limits or result structure details that would be helpful for an agent. The absence of output schema means the description should ideally say more about return values.

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 all three parameters (query, language, maxResults). The description doesn't add any parameter-specific information beyond what's in the schema. With complete schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't need to.

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: '在互联网上搜索信息' (search for information on the internet) with the verb '搜索' (search) and resource '信息' (information). It distinguishes from sibling 'web_scrape' by focusing on search rather than scraping, but doesn't explicitly differentiate from 'web_search_and_scrape' which combines both functions.

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 implies usage for general internet searching, but provides no explicit guidance on when to use this tool versus the sibling tools 'web_scrape' or 'web_search_and_scrape'. There's no mention of alternatives, prerequisites, or specific contexts where this tool is preferred over others.

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/Mantraa-Zzz/Web_Search'

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