Skip to main content
Glama
omgwtfwow

MCP Server for Crawl4AI

by omgwtfwow

smart_crawl

Automatically detect and crawl web content types including HTML, sitemaps, RSS feeds, and text documents for data extraction and analysis.

Instructions

[STATELESS] Auto-detect and handle different content types (HTML, sitemap, RSS, text). Use when: URL type is unknown, crawling feeds/sitemaps, or want automatic format handling. Adapts strategy based on content. Creates new browser each time. For persistent operations use create_session + crawl.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to crawl intelligently
max_depthNoMaximum crawl depth for sitemaps
follow_linksNoFor sitemaps/RSS: crawl found URLs (max 10). For HTML: no effect
bypass_cacheNoForce fresh crawl

Implementation Reference

  • Core handler function that implements smart_crawl logic: detects content type (HTML, sitemap, RSS, etc.), performs crawl, optionally follows links from sitemaps/RSS, bypasses cache if specified, and returns structured content with metadata.
    async smartCrawl(options: { url: string; max_depth?: number; follow_links?: boolean; bypass_cache?: boolean }) {
      try {
        // First, try to detect the content type from URL or HEAD request
        let contentType = '';
        try {
          const headResponse = await this.axiosClient.head(options.url);
          contentType = headResponse.headers['content-type'] || '';
        } catch {
          // If HEAD request fails, continue anyway - we'll detect from the crawl response
          console.debug('HEAD request failed, will detect content type from response');
        }
    
        let detectedType = 'html';
        if (options.url.includes('sitemap') || options.url.endsWith('.xml')) {
          detectedType = 'sitemap';
        } else if (options.url.includes('rss') || options.url.includes('feed')) {
          detectedType = 'rss';
        } else if (contentType.includes('text/plain') || options.url.endsWith('.txt')) {
          detectedType = 'text';
        } else if (contentType.includes('application/xml') || contentType.includes('text/xml')) {
          detectedType = 'xml';
        } else if (contentType.includes('application/json')) {
          detectedType = 'json';
        }
    
        // Crawl without the unsupported 'strategy' parameter
        const response = await this.axiosClient.post('/crawl', {
          urls: [options.url],
          crawler_config: {
            cache_mode: options.bypass_cache ? 'BYPASS' : 'ENABLED',
          },
          browser_config: {
            headless: true,
            browser_type: 'chromium',
          },
        });
    
        const results = response.data.results || [];
        const result = results[0] || {};
    
        // Handle follow_links for sitemaps and RSS feeds
        if (options.follow_links && (detectedType === 'sitemap' || detectedType === 'rss' || detectedType === 'xml')) {
          // Extract URLs from the content
          const urlPattern = /<loc>(.*?)<\/loc>|<link[^>]*>(.*?)<\/link>|href=["']([^"']+)["']/gi;
          const content = result.markdown || result.html || '';
          const foundUrls: string[] = [];
          let match;
    
          while ((match = urlPattern.exec(content)) !== null) {
            const url = match[1] || match[2] || match[3];
            if (url && url.startsWith('http')) {
              foundUrls.push(url);
            }
          }
    
          if (foundUrls.length > 0) {
            // Limit to first 10 URLs to avoid overwhelming the system
            const urlsToFollow = foundUrls.slice(0, Math.min(10, options.max_depth || 10));
    
            // Crawl the found URLs
            await this.axiosClient.post('/crawl', {
              urls: urlsToFollow,
              max_concurrent: 3,
              bypass_cache: options.bypass_cache,
            });
    
            return {
              content: [
                {
                  type: 'text',
                  text: `Smart crawl detected content type: ${detectedType}\n\nMain content:\n${result.markdown?.raw_markdown || result.html || 'No content extracted'}\n\n---\nFollowed ${urlsToFollow.length} links:\n${urlsToFollow.map((url, i) => `${i + 1}. ${url}`).join('\n')}`,
                },
                ...(result.metadata
                  ? [
                      {
                        type: 'text',
                        text: `\n\n---\nMetadata:\n${JSON.stringify(result.metadata, null, 2)}`,
                      },
                    ]
                  : []),
              ],
            };
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Smart crawl detected content type: ${detectedType}\n\n${result.markdown?.raw_markdown || result.html || 'No content extracted'}`,
            },
            ...(result.metadata
              ? [
                  {
                    type: 'text',
                    text: `\n\n---\nMetadata:\n${JSON.stringify(result.metadata, null, 2)}`,
                  },
                ]
              : []),
          ],
        };
      } catch (error) {
        throw this.formatError(error, 'smart crawl');
      }
    }
  • Zod schema defining input validation for smart_crawl tool: requires URL, optional max_depth, follow_links, bypass_cache.
    export const SmartCrawlSchema = createStatelessSchema(
      z.object({
        url: z.string().url(),
        max_depth: z.number().optional(),
        follow_links: z.boolean().optional(),
        bypass_cache: z.boolean().optional(),
      }),
      'smart_crawl',
    );
  • src/server.ts:852-855 (registration)
    Tool dispatch registration in server request handler: validates arguments using SmartCrawlSchema and delegates to CrawlHandlers.smartCrawl.
    case 'smart_crawl':
      return await this.validateAndExecute('smart_crawl', args, SmartCrawlSchema, async (validatedArgs) =>
        this.crawlHandlers.smartCrawl(validatedArgs),
      );
  • src/server.ts:244-272 (registration)
    Tool metadata registration in listTools response: defines name, description, and inputSchema for smart_crawl.
      name: 'smart_crawl',
      description:
        '[STATELESS] Auto-detect and handle different content types (HTML, sitemap, RSS, text). Use when: URL type is unknown, crawling feeds/sitemaps, or want automatic format handling. Adapts strategy based on content. Creates new browser each time. For persistent operations use create_session + crawl.',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The URL to crawl intelligently',
          },
          max_depth: {
            type: 'number',
            description: 'Maximum crawl depth for sitemaps',
            default: 2,
          },
          follow_links: {
            type: 'boolean',
            description: 'For sitemaps/RSS: crawl found URLs (max 10). For HTML: no effect',
            default: false,
          },
          bypass_cache: {
            type: 'boolean',
            description: 'Force fresh crawl',
            default: false,
          },
        },
        required: ['url'],
      },
    },
  • src/server.ts:30-30 (registration)
    Import of SmartCrawlSchema used for validation.
    SmartCrawlSchema,
Behavior4/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 effectively describes key traits: 'Adapts strategy based on content' (dynamic behavior), 'Creates new browser each time' (stateless operation, implying no session persistence), and '[STATELESS]' tag (explicit statelessness). However, it lacks details on rate limits, error handling, or output format, which are important for a crawl tool.

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 highly concise and well-structured: it starts with a [STATELESS] tag for quick insight, states the purpose, provides usage guidelines, and notes behavioral traits in three clear sentences. Every sentence adds value without redundancy, making it front-loaded and efficient.

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

Completeness4/5

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

Given the tool's complexity (crawling with auto-detection) and no annotations or output schema, the description does a good job covering purpose, usage, and key behaviors. However, it lacks details on output (what is returned, e.g., extracted data or links) and error scenarios, which are critical for a tool with no output schema. This gap prevents a perfect score.

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 parameters well. The description does not add any parameter-specific semantics beyond what's in the schema (e.g., it doesn't explain url formats or max_depth implications further). Baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

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: 'Auto-detect and handle different content types (HTML, sitemap, RSS, text)' with specific verbs ('detect', 'handle') and resources ('content types'). It distinguishes from siblings by mentioning 'automatic format handling' versus more specific tools like parse_sitemap or get_html.

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

Usage Guidelines5/5

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

The description provides explicit usage guidelines: 'Use when: URL type is unknown, crawling feeds/sitemaps, or want automatic format handling.' It also specifies alternatives: 'For persistent operations use create_session + crawl,' though create_session is not listed as a sibling, implying an external or implied tool. This gives clear when-to-use and when-not-to-use scenarios.

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/omgwtfwow/mcp-crawl4ai-ts'

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