Skip to main content
Glama
gianlucamazza

MCP DuckDuckGo Search Plugin

get_page_content

Extract web page content including title, description, and main text from any URL for analysis and information retrieval.

Instructions

Fetch and extract content from a web page.

Returns the page title, description, and main content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to fetch content from

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main asynchronous handler function for the 'get_page_content' tool. It fetches the web page using httpx, parses it with BeautifulSoup, extracts title, meta description, and main content using multiple selectors, and returns structured data including domain extracted via helper.
    @mcp_server.tool()
    async def get_page_content(
        url: str = Field(..., description="URL to fetch content from"),
        ctx: Context = Field(default_factory=Context),
    ) -> Dict[str, Any]:
        """
        Fetch and extract content from a web page.
    
        Returns the page title, description, and main content.
        """
        logger.info("Fetching content from: %s", url)
    
        try:
            # Get HTTP client from context
            http_client = getattr(ctx, "http_client", None)
            if not http_client:
                http_client = httpx.AsyncClient(timeout=15.0)
                close_client = True
            else:
                close_client = False
    
            try:
                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"
                }
    
                response = await http_client.get(url, headers=headers, timeout=15)
                response.raise_for_status()
    
                soup = BeautifulSoup(response.text, "html.parser")
    
                # Extract title
                title = ""
                title_tag = soup.find("title")
                if title_tag:
                    title = title_tag.get_text().strip()
    
                # Extract description from meta tags
                description = ""
                meta_desc = soup.find("meta", attrs={"name": "description"})
                if meta_desc:
                    description = meta_desc.get("content", "").strip()  # type: ignore[union-attr]
    
                # Extract main content (try common content selectors)
                content_text = ""
                content_selectors = [
                    "main article",
                    "article",
                    '[role="main"]',
                    ".content",
                    ".article-content",
                    ".post-content",
                    "#content",
                    "#article",
                    ".entry-content",
                ]
    
                for selector in content_selectors:
                    main_content = soup.select_one(selector)
                    if main_content:
                        content_text = main_content.get_text().strip()
                        break
    
                # If no content found, get all paragraphs
                if not content_text:
                    paragraphs = soup.find_all("p")[:5]  # First 5 paragraphs
                    content_text = "\n\n".join(p.get_text().strip() for p in paragraphs)
    
                # Clean up content (first 500 chars for preview)
                content_preview = (
                    content_text[:500] + "..."
                    if len(content_text) > 500
                    else content_text
                )
    
                return {
                    "url": url,
                    "title": title,
                    "description": description,
                    "content": content_text,
                    "content_preview": content_preview,
                    "domain": extract_domain(url),
                    "status": "success",
                }
    
            finally:
                if close_client:
                    await http_client.aclose()
    
        except Exception as e:
            logger.error("Failed to fetch content from %s: %s", url, e)
            return {
                "url": url,
                "title": "",
                "description": "",
                "content": "",
                "content_preview": f"Error: {str(e)}",
                "domain": extract_domain(url),
                "status": "error",
                "error": str(e),
            }
  • Registration of the tool occurs here in create_mcp_server() by calling register_search_tools(server), which defines and registers the get_page_content handler using the @mcp_server.tool() decorator.
    # Register tools directly with the server instance
    register_search_tools(server)
  • Helper utility function used by get_page_content to extract the domain from the URL for the response dictionary.
    def extract_domain(url: str) -> str:
        """
        Extract domain from URL.
    
        Args:
            url: URL string to extract domain from
    
        Returns:
            Lowercase domain name or empty string if parsing fails
        """
        try:
            parsed = urllib.parse.urlparse(url)
            return parsed.netloc.lower()
        except Exception as e:
            logger.debug("Failed to extract domain from URL %s: %s", url, e)
            return ""
  • Pydantic-based input schema definition using Field for validation and descriptions, output is Dict[str, Any].
    async def get_page_content(
        url: str = Field(..., description="URL to fetch content from"),
        ctx: Context = Field(default_factory=Context),
    ) -> Dict[str, Any]:
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions what the tool returns ('page title, description, and main content'), which is helpful, but lacks critical details like error handling, rate limits, authentication needs, or performance characteristics. For a web-fetching tool, this leaves significant gaps in understanding its behavior.

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 appropriately concise with two sentences that directly address purpose and return values. It's front-loaded with the core functionality. However, the second sentence could be more integrated with the first for better flow, and there's some whitespace formatting that slightly affects structure.

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 the tool has an output schema (which handles return value documentation) and 100% schema coverage for the single parameter, the description provides adequate context for basic understanding. However, for a web content extraction tool with no annotations, it should ideally mention common constraints like URL validation, content type limitations, or network timeout behavior to be more complete.

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 input schema has 100% description coverage, with the 'url' parameter clearly documented. The description adds no additional parameter semantics beyond what's in the schema. According to scoring rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no param info in the description.

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 specific verbs ('fetch and extract content from a web page') and identifies the resource ('web page'). It distinguishes from sibling tools like 'suggest_related_searches' and 'web_search' by focusing on content extraction rather than search or suggestions. However, it doesn't explicitly differentiate itself from potential similar tools not 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 'web_search' or 'suggest_related_searches'. There's no mention of prerequisites, constraints, or typical use cases. The agent must infer usage from the purpose alone, which is insufficient for optimal tool selection.

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/gianlucamazza/mcp-duckduckgo'

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