Skip to main content
Glama

get_url_content_direct

Fetch webpage content and metadata directly from any URL using HTTP requests to retrieve information for analysis or processing.

Instructions

Get webpage content directly using HTTP request

Args:
    url (str): The URL to fetch content from
    
Returns:
    str: The webpage content and metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • The MCP tool handler for get_url_content_direct, decorated with @mcp.tool(). It defines the input schema via type hints and docstring, and delegates the core logic to the internal _get_url_content_direct helper.
    @mcp.tool()
    def get_url_content_direct(url: str) -> str:
        """Get webpage content directly using HTTP request
        
        Args:
            url (str): The URL to fetch content from
            
        Returns:
            str: The webpage content and metadata
        """
        return _get_url_content_direct(url)
  • The core implementation of the tool logic: fetches the URL content via requests, parses HTML with BeautifulSoup, extracts main text content, cleans it (removes short lines, limits to 1000 chars), adds metadata, and returns formatted string.
    def _get_url_content_direct(url: str) -> str:
        """Internal function to get content directly using requests"""
        try:
            logger.debug(f"Directly fetching content from URL: {url}")
            response = requests.get(url, timeout=10, 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.raise_for_status()
            
            # 尝试检测编码
            if 'charset' in response.headers.get('content-type', '').lower():
                response.encoding = response.apparent_encoding
                
            try:
                from bs4 import BeautifulSoup
                soup = BeautifulSoup(response.text, 'html.parser')
                
                # 移除不需要的元素
                for element in soup(['script', 'style', 'header', 'footer', 'nav', 'aside', 'iframe', 'ad', '.advertisement']):
                    element.decompose()
                
                # 尝试找到主要内容区域
                main_content = None
                possible_content_elements = [
                    soup.find('article'),
                    soup.find('main'),
                    soup.find(class_='content'),
                    soup.find(id='content'),
                    soup.find(class_='post-content'),
                    soup.find(class_='article-content'),
                    soup.find(class_='entry-content'),
                    soup.find(class_='main-content'),
                    soup.select_one('div[class*="content"]'),  # 包含 "content" 的任何 class
                ]
                
                for element in possible_content_elements:
                    if element:
                        main_content = element
                        break
                
                if not main_content:
                    main_content = soup
                
                text = main_content.get_text(separator='\n')
                
                lines = []
                for line in text.split('\n'):
                    line = line.strip()
                    if line and len(line) > 30:
                        lines.append(line)
                
                cleaned_text = ' '.join(lines)
                if len(cleaned_text) > 1000:
                    end_pos = cleaned_text.rfind('. ', 0, 1000)
                    if end_pos > 0:
                        cleaned_text = cleaned_text[:end_pos + 1]
                    else:
                        cleaned_text = cleaned_text[:1000]
                
                metadata = f"URL: {url}\n"
                metadata += f"Content Length: {len(response.text)} characters\n"
                metadata += f"Content Type: {response.headers.get('content-type', 'Unknown')}\n"
                metadata += "---\n\n"
                
                return f"{metadata}{cleaned_text}"
                
            except Exception as e:
                logger.error(f"Error extracting text from HTML: {str(e)}")
                return f"Error extracting text: {str(e)}"
            
        except Exception as e:
            logger.error(f"Error fetching URL content directly: {str(e)}")
            return f"Error getting content: {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 mentions 'HTTP request' but does not specify details like authentication needs, rate limits, error handling, or whether it's read-only or destructive. For a tool that fetches web content, this lack of behavioral context is a significant gap.

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 sized and front-loaded, with a clear purpose statement followed by structured 'Args' and 'Returns' sections. Every sentence adds value, though it could be more concise by integrating the sections into a single paragraph without losing clarity.

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 (HTTP request with potential behavioral nuances), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It does not explain return values in detail (e.g., what 'metadata' includes), error cases, or usage constraints, leaving gaps for the agent to infer behavior.

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 beyond the input schema. It documents the 'url' parameter as 'The URL to fetch content from', which matches the schema's 'title: Url' and 'type: string'. With 0% schema description coverage, the description compensates slightly by explaining the parameter's purpose, but it does not provide format details (e.g., required protocols) or constraints.

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 'Get webpage content directly using HTTP request', which specifies the verb ('get'), resource ('webpage content'), and method ('HTTP request'). It distinguishes from siblings like 'url_content' by emphasizing 'directly', though the distinction could be more explicit. This is clear but lacks detailed sibling 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 alternatives. With siblings like 'url_content' and search tools (e.g., 'brave_search_summary'), there is no mention of use cases, prerequisites, or exclusions. This leaves the agent without context for 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/mcp2everything/mcp2brave'

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