Skip to main content
Glama
flyanima

Open Search MCP

by flyanima

batch_crawl_urls

Extract content from multiple web pages simultaneously by crawling specified URLs, with options to retrieve main text and links.

Instructions

Crawl and extract content from multiple web pages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlsYesArray of URLs to crawl
extractTextNoExtract main text content
extractLinksNoExtract all links from pages
maxConcurrentNoMaximum concurrent requests
delayNoDelay between batches in milliseconds

Implementation Reference

  • The main handler function for the batch_crawl_urls tool. Validates input URLs, performs batched concurrent crawling using WebCrawlerClient, processes results, and returns structured output with success metrics.
    execute: async (args: any) => {
      const { urls, extractText = true, extractLinks = false, maxConcurrent = 3, delay = 1000 } = args;
    
      try {
        const startTime = Date.now();
        
        // 验证URLs
        for (const url of urls) {
          try {
            new URL(url);
          } catch {
            return {
              success: false,
              error: `Invalid URL format: ${url}`
            };
          }
        }
    
        const results = await client.crawlMultiplePages(urls, {
          extractText,
          extractLinks,
          maxConcurrent,
          delay,
          maxContentLength: 3000 // 减少单页内容长度以处理多页
        });
    
        const crawlTime = Date.now() - startTime;
        const successCount = results.filter(r => r.success).length;
    
        return {
          success: true,
          data: {
            source: 'Web Crawler',
            totalUrls: urls.length,
            successCount,
            failureCount: urls.length - successCount,
            crawlTime,
            results,
            summary: {
              successRate: Math.round((successCount / urls.length) * 100),
              averageTimePerPage: Math.round(crawlTime / urls.length),
              totalContentExtracted: results.filter(r => r.success).length
            },
            timestamp: Date.now()
          }
        };
      } catch (error) {
        return {
          success: false,
          error: `Multiple page crawling failed: ${error instanceof Error ? error.message : String(error)}`
        };
      }
    }
  • Core helper method in WebCrawlerClient that implements batched concurrent page fetching, content extraction, error handling, and rate limiting delays.
      async crawlMultiplePages(urls: string[], options: any = {}) {
        const results = [];
        const maxConcurrent = options.maxConcurrent || 3;
        
        for (let i = 0; i < urls.length; i += maxConcurrent) {
          const batch = urls.slice(i, i + maxConcurrent);
          const batchPromises = batch.map(async (url) => {
            try {
              const pageData = await this.fetchPage(url, options);
              const content = this.extractContent(pageData.html, options);
              return {
                url,
                success: true,
                data: {
                  ...content,
                  status: pageData.status,
                  finalUrl: pageData.url
                }
              };
            } catch (error) {
              return {
                url,
                success: false,
                error: error instanceof Error ? error.message : String(error)
              };
            }
          });
    
          const batchResults = await Promise.all(batchPromises);
          results.push(...batchResults);
    
          // 添加延迟以避免过于频繁的请求
          if (i + maxConcurrent < urls.length) {
            await new Promise(resolve => setTimeout(resolve, options.delay || 1000));
          }
        }
    
        return results;
      }
    }
  • Input schema definition for the batch_crawl_urls tool, specifying parameters like urls array (max 10), extraction options, concurrency limits, and delays.
    inputSchema: {
      type: 'object',
      properties: {
        urls: {
          type: 'array',
          items: { type: 'string' },
          description: 'Array of URLs to crawl',
          maxItems: 10
        },
        extractText: {
          type: 'boolean',
          description: 'Extract main text content',
          default: true
        },
        extractLinks: {
          type: 'boolean',
          description: 'Extract all links from pages',
          default: false
        },
        maxConcurrent: {
          type: 'number',
          description: 'Maximum concurrent requests',
          default: 3,
          minimum: 1,
          maximum: 5
        },
        delay: {
          type: 'number',
          description: 'Delay between batches in milliseconds',
          default: 1000,
          minimum: 500,
          maximum: 5000
        }
      },
      required: ['urls']
    },
  • Local tool registration in registerWebCrawlerTools function, defining name, description, schema, and execute handler for batch_crawl_urls.
    registry.registerTool({
      name: 'batch_crawl_urls',
      description: 'Crawl and extract content from multiple web pages',
      category: 'utility',
      source: 'Web Crawler',
      inputSchema: {
        type: 'object',
        properties: {
          urls: {
            type: 'array',
            items: { type: 'string' },
            description: 'Array of URLs to crawl',
            maxItems: 10
          },
          extractText: {
            type: 'boolean',
            description: 'Extract main text content',
            default: true
          },
          extractLinks: {
            type: 'boolean',
            description: 'Extract all links from pages',
            default: false
          },
          maxConcurrent: {
            type: 'number',
            description: 'Maximum concurrent requests',
            default: 3,
            minimum: 1,
            maximum: 5
          },
          delay: {
            type: 'number',
            description: 'Delay between batches in milliseconds',
            default: 1000,
            minimum: 500,
            maximum: 5000
          }
        },
        required: ['urls']
      },
      execute: async (args: any) => {
        const { urls, extractText = true, extractLinks = false, maxConcurrent = 3, delay = 1000 } = args;
    
        try {
          const startTime = Date.now();
          
          // 验证URLs
          for (const url of urls) {
            try {
              new URL(url);
            } catch {
              return {
                success: false,
                error: `Invalid URL format: ${url}`
              };
            }
          }
    
          const results = await client.crawlMultiplePages(urls, {
            extractText,
            extractLinks,
            maxConcurrent,
            delay,
            maxContentLength: 3000 // 减少单页内容长度以处理多页
          });
    
          const crawlTime = Date.now() - startTime;
          const successCount = results.filter(r => r.success).length;
    
          return {
            success: true,
            data: {
              source: 'Web Crawler',
              totalUrls: urls.length,
              successCount,
              failureCount: urls.length - successCount,
              crawlTime,
              results,
              summary: {
                successRate: Math.round((successCount / urls.length) * 100),
                averageTimePerPage: Math.round(crawlTime / urls.length),
                totalContentExtracted: results.filter(r => r.success).length
              },
              timestamp: Date.now()
            }
          };
        } catch (error) {
          return {
            success: false,
            error: `Multiple page crawling failed: ${error instanceof Error ? error.message : String(error)}`
          };
        }
      }
    });
  • src/index.ts:248-248 (registration)
    Global registration call in OpenSearchMCPServer.registerAllTools(), importing and registering the web crawler tools including batch_crawl_urls.
    registerWebCrawlerTools(this.toolRegistry);         // 2 tools: crawl_url_content, batch_crawl_urls
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 for behavioral disclosure. While 'crawl and extract' implies read-only operations, it doesn't mention rate limiting considerations (implied by 'maxConcurrent' and 'delay' parameters but not explained), potential authentication needs, error handling for invalid URLs, or what 'extract content' specifically entails. The description adds minimal behavioral context beyond the basic operation.

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 that clearly states the core functionality without unnecessary words. It's appropriately sized for the tool's complexity and gets straight to the point with zero wasted text.

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 no annotations and no output schema, the description is incomplete for a tool with 5 parameters performing web crawling operations. It doesn't explain what the output looks like (structured data? raw HTML?), error conditions, performance characteristics, or how results from multiple URLs are returned. For a batch processing tool with 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?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly with descriptions, defaults, and constraints. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain relationships between parameters (e.g., how 'extractText' and 'extractLinks' interact) or provide usage examples. Baseline 3 is appropriate when schema does 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's purpose with a specific verb ('crawl and extract') and resource ('content from multiple web pages'). It distinguishes itself from some siblings like 'crawl_url_content' by explicitly mentioning 'multiple' pages, though it doesn't fully differentiate from all potential batch-processing alternatives in the sibling list.

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 like 'crawl_url_content' (which might handle single URLs) or other research/search tools in the sibling list. There's no mention of prerequisites, typical use cases, or exclusions for this batch crawling operation.

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/flyanima/open-search-mcp'

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