Skip to main content
Glama

scrape_webpage

Extract content and metadata from any webpage by providing its URL, returning results in JSON format for structured data analysis and integration.

Instructions

Scrape content and metadata from a single webpage using Crawl4AI.

Args: url: The URL of the webpage to scrape

Returns: List containing TextContent with the result as JSON.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • main.py:10-24 (handler)
    The MCP tool handler for 'scrape_webpage', decorated with @mcp.tool(). It accepts a URL parameter and delegates execution to the scrape_url helper function from tools/scrape.py, returning scraped content as typed MCP content.
    @mcp.tool()
    async def scrape_webpage(
        url: str,
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """
        Scrape content and metadata from a single webpage using Crawl4AI.
    
        Args:
            url: The URL of the webpage to scrape
    
        Returns:
            List containing TextContent with the result as JSON.
        """
        return await scrape_url(url)
  • Supporting helper function scrape_url that performs the actual webpage scraping using Crawl4AI's AsyncWebCrawler. Handles URL validation, browser configuration, crawling, error handling, and formats output as MCP TextContent.
    async def scrape_url(url: str) -> List[Any]:
        """Scrape a webpage using crawl4ai with simple implementation.
    
        Args:
            url: The URL to scrape
    
        Returns:
            A list containing TextContent object with the result as JSON
        """
    
        try:
            # Simple validation for domains/subdomains with http(s)
            url_pattern = re.compile(
                r"^(?:https?://)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}(?:/[^/\s]*)*$"
            )
    
            if not url_pattern.match(url):
                return [
                    types.TextContent(
                        type="text",
                        text=json.dumps(
                            {
                                "success": False,
                                "url": url,
                                "error": "Invalid URL format",
                            }
                        ),
                    )
                ]
    
            # Add https:// if missing
            if not url.startswith("http://") and not url.startswith("https://"):
                url = f"https://{url}"
    
            # Use default configurations with minimal customization
            browser_config = BrowserConfig(
                browser_type="chromium",
                headless=True,
                ignore_https_errors=True,
                verbose=False,
                extra_args=[
                    "--no-sandbox",
                    "--disable-setuid-sandbox",
                    "--disable-dev-shm-usage",
                ],
            )
            run_config = CrawlerRunConfig(
                cache_mode=CacheMode.BYPASS,
                verbose=False,
                page_timeout=30 * 1000,  # Convert to milliseconds
            )
    
            async with AsyncWebCrawler(config=browser_config) as crawler:
                result = await asyncio.wait_for(
                    crawler.arun(
                        url=url,
                        config=run_config,
                    ),
                    timeout=30,
                )
    
                # Create response in the format requested
                return [
                    types.TextContent(
                        type="text", text=json.dumps({"markdown": result.markdown})
                    )
                ]
    
        except Exception as e:
            return [
                types.TextContent(
                    type="text",
                    text=json.dumps({"success": False, "url": url, "error": str(e)}),
                )
            ]
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool scrapes content and metadata, but lacks details on permissions, rate limits, error handling, or what 'Crawl4AI' entails (e.g., if it's a library or service). This leaves significant gaps for a web scraping tool.

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

Conciseness4/5

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

The description is concise and well-structured with a clear purpose statement followed by Args and Returns sections. However, the 'Returns' section is vague ('List containing TextContent with the result as JSON'), which slightly reduces efficiency.

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, no output schema, and low schema coverage, the description is incomplete. It lacks details on behavioral traits, error cases, and the structure of returned data, making it inadequate for a tool that interacts with external web resources.

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?

The description adds minimal semantics: it defines 'url' as 'The URL of the webpage to scrape'. With 0% schema description coverage and only one parameter, this provides basic meaning, but doesn't elaborate on URL format constraints or validation, leaving room for improvement.

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: 'Scrape content and metadata from a single webpage using Crawl4AI.' It specifies the verb ('scrape'), resource ('content and metadata'), and scope ('single webpage'), though it doesn't explicitly differentiate from its sibling 'crawl_website' beyond implying single vs. multi-page operations.

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?

No guidance is provided on when to use this tool versus alternatives. The description mentions 'single webpage' and the sibling is named 'crawl_website', which might imply this is for single pages while the sibling is for entire sites, but this is not explicitly stated, leaving usage context unclear.

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

Related 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/ritvij14/crawl4ai-mcp'

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