Skip to main content
Glama
Mantraa-Zzz

Web Search MCP Server

by Mantraa-Zzz

web_search_and_scrape

Search the web and extract content from top results using Google Custom Search API to gather comprehensive information for research and analysis.

Instructions

搜索网页并抓取前几个结果的内容

Input Schema

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

Implementation Reference

  • The primary handler function for the 'web_search_and_scrape' tool. It performs a web search using performWebSearch, then scrapes the content of each top result using scrapeWebPage, and compiles a formatted response with titles, URLs, snippets, and content summaries.
    private async handleWebSearchAndScrape(args: any) {
      const { query, maxResults = 3, language = 'zh-CN' } = args;
    
      try {
        // 首先进行搜索
        const searchResults = await this.performWebSearch(query, maxResults, language);
        
        let result = `搜索 "${query}" 并抓取内容:\n\n`;
        
        // 然后抓取每个结果的内容
        for (let i = 0; i < searchResults.length; i++) {
          const searchResult = searchResults[i];
          result += `## ${i + 1}. ${searchResult.title}\n`;
          result += `**URL**: ${searchResult.url}\n`;
          result += `**搜索摘要**: ${searchResult.snippet}\n\n`;
          
          try {
            const scrapedContent = await this.scrapeWebPage(searchResult.url, true, false);
            result += `**抓取内容摘要** (前300字符):\n${scrapedContent.content.substring(0, 300)}${scrapedContent.content.length > 300 ? '...' : ''}\n\n`;
          } catch (scrapeError) {
            result += `**抓取失败**: ${scrapeError instanceof Error ? scrapeError.message : String(scrapeError)}\n\n`;
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: result,
            },
          ],
        };
      } catch (error) {
        throw new Error(`搜索和抓取失败: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • The input schema and metadata for the 'web_search_and_scrape' tool, registered in the ListTools response.
    {
      name: 'web_search_and_scrape',
      description: '搜索网页并抓取前几个结果的内容',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '搜索查询关键词',
          },
          maxResults: {
            type: 'number',
            description: '最大抓取结果数量(默认3)',
            default: 3,
          },
          language: {
            type: 'string',
            description: '搜索语言(如:zh-CN, en-US)',
            default: 'zh-CN',
          },
        },
        required: ['query'],
      },
    },
  • src/index.ts:160-161 (registration)
    The switch case in the CallToolRequest handler that routes calls to 'web_search_and_scrape' to its handler function.
    case 'web_search_and_scrape':
      return await this.handleWebSearchAndScrape(args);
  • Helper function called by the handler to perform the actual web search using Google Custom Search API.
    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,
      }));
    }
  • Helper function called by the handler to scrape web page content using axios and cheerio, extracting title, text, and metadata.
    private async scrapeWebPage(url: string, extractText: boolean, extractMetadata: boolean): Promise<WebPageContent> {
      const response = await axios.get(url, {
        timeout: this.requestTimeout,
        headers: {
          'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
        },
      });
    
      const $ = cheerio.load(response.data);
      
      const title = $('title').text().trim() || '无标题';
      let content = '';
      let metadata: any = {};
    
      if (extractText) {
        // 移除脚本和样式标签
        $('script, style, nav, header, footer, aside').remove();
        content = $('body').text().replace(/\s+/g, ' ').trim();
      }
    
      if (extractMetadata) {
        metadata = {
          description: $('meta[name="description"]').attr('content') || 
                      $('meta[property="og:description"]').attr('content'),
          keywords: $('meta[name="keywords"]').attr('content'),
          author: $('meta[name="author"]').attr('content') || 
                  $('meta[property="article:author"]').attr('content'),
          publishedDate: $('meta[property="article:published_time"]').attr('content') ||
                        $('meta[name="date"]').attr('content'),
        };
      }
    
      return {
        url,
        title,
        content,
        metadata,
      };
    }
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. It mentions scraping '前几个结果的内容' (content of top results), implying a limit based on search ranking, but lacks details on permissions, rate limits, error handling, or output format. This is inadequate for a tool that performs web operations with potential complexities.

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 a single, efficient sentence in Chinese that directly states the tool's function without unnecessary words. It is appropriately sized and front-loaded, making it easy to understand quickly.

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 tool's complexity (web search and scrape), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what '抓取内容' (scrape content) entails (e.g., full text, metadata), potential limitations, or how results are returned, leaving significant gaps for agent understanding.

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 parameters like 'query', 'maxResults', and 'language'. The description adds no additional semantic context beyond implying '前几个结果' relates to 'maxResults', which is already covered. Baseline 3 is appropriate as the schema handles parameter documentation.

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 as '搜索网页并抓取前几个结果的内容' (search web and scrape content of top results), which specifies the verb (search and scrape) and resource (web pages). It distinguishes from 'web_scrape' (scraping only) and 'web_search' (searching only) by combining both functions, though it doesn't explicitly mention this differentiation.

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 its siblings 'web_scrape' or 'web_search'. There are no explicit instructions on alternatives, prerequisites, or context for choosing this combined tool over separate ones, leaving usage decisions ambiguous.

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