Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

web_fetch

Fetch web content from a URL and extract plain text by removing HTML tags. Specify maximum characters and timeout to control output.

Instructions

抓取指定 URL 的网页内容,返回纯文本(自动去除 HTML 标签)。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes要抓取的网页 URL
max_lenNo最大返回字符数(默认 5000)
timeoutNo超时秒数(默认 15)

Implementation Reference

  • Core handler for web_fetch tool: fetches URL content using httpx, strips HTML via BeautifulSoup, removes script/style/nav/footer/header tags, and returns plain text truncated to max_len.
    async def _web_fetch(args: dict) -> list[types.TextContent]:
        url     = args["url"]
        max_len = int(args.get("max_len", 5000))
        timeout = int(args.get("timeout", 15))
        try:
            import httpx
            from bs4 import BeautifulSoup
            async with httpx.AsyncClient(timeout=timeout, follow_redirects=True) as client:
                resp = await client.get(url, headers={"User-Agent": "Mozilla/5.0"})
                resp.raise_for_status()
            soup  = BeautifulSoup(resp.text, "html.parser")
            for tag in soup(["script", "style", "nav", "footer", "header"]):
                tag.decompose()
            text  = soup.get_text(separator="\n", strip=True)
            text  = "\n".join(line for line in text.splitlines() if line.strip())
            if len(text) > max_len:
                text = text[:max_len] + f"\n\n... [已截断,共 {len(text)} 字符]"
            return [types.TextContent(type="text", text=f"🌐 {url}\n\n{text}")]
        except ImportError:
            return [types.TextContent(type="text",
                text="❌ 需要安装依赖: pip install httpx beautifulsoup4")]
        except Exception as e:
            return [types.TextContent(type="text", text=f"❌ 抓取失败: {e}")]
  • Schema/registration definition for web_fetch tool. Defines name, description, inputSchema with url (required), max_len (default 5000), and timeout (default 15).
    types.Tool(
        name="web_fetch",
        description="抓取指定 URL 的网页内容,返回纯文本(自动去除 HTML 标签)。",
        inputSchema={
            "type": "object",
            "properties": {
                "url":      {"type": "string", "description": "要抓取的网页 URL"},
                "max_len":  {
                    "type": "integer",
                    "description": "最大返回字符数(默认 5000)",
                    "default": 5000,
                },
                "timeout":  {
                    "type": "integer",
                    "description": "超时秒数(默认 15)",
                    "default": 15,
                },
            },
            "required": ["url"],
        },
    ),
  • Registration in server.py: maps web_fetch tool name to handle_web via the routing table _HANDLERS.
    for _t in WEB_TOOLS:    
        _HANDLERS[_t.name] = handle_web
  • Re-exports WEB_TOOLS and handle_web from tools/__init__.py for use by server.py.
    from onion_mcp_server.tools.web    import WEB_TOOLS,    handle_web
    from onion_mcp_server.tools.system import SYSTEM_TOOLS, handle_system
    
    __all__ = [
        "AI_TOOLS",     "handle_ai",
        "CODE_TOOLS",   "handle_code",
        "TEXT_TOOLS",   "handle_text",
        "DATA_TOOLS",   "handle_data",
        "WEB_TOOLS",    "handle_web",
        "SYSTEM_TOOLS", "handle_system",
    ]
  • Dispatcher helper that routes web_fetch calls to the actual _web_fetch implementation.
    async def handle_web(name: str, arguments: dict) -> list[types.TextContent]:
        if name == "web_fetch":
            return await _web_fetch(arguments)
        elif name == "web_search":
            return await _web_search(arguments)
        elif name == "web_extract":
            return await _web_extract(arguments)
        raise ValueError(f"未知 web 工具: {name}")
Behavior3/5

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

With no annotations, description bears full burden. It mentions auto-removal of HTML tags but does not disclose limitations like handling of dynamic content, rate limits, or error behavior. Adequate but not thorough.

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?

Single sentence, front-loaded with purpose, no wasted words. Perfectly concise.

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?

No output schema, 3 params, no annotations. Description is minimal but covers core behavior. Lacks details on return format, errors, or edge cases, making it slightly incomplete for a tool with no output schema.

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 has 100% coverage; description adds no extra meaning beyond parameter names and defaults. Baseline 3 applies as description does not compensate.

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?

Description clearly states it fetches webpage content from a URL and returns plain text after removing HTML tags. Verb '抓取' and resource '网页内容' are specific. Differentiates from siblings like web_search and web_extract.

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

Usage Guidelines3/5

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

No explicit when-to-use or alternatives mentioned. Usage implied by purpose but no guidance on when to choose this over web_search or web_extract.

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/onion-ai/mcp-server'

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