Skip to main content
Glama
onion-ai

onion-mcp-server

Official
by onion-ai

web_extract

Extract structured information from any URL, including title, description, body summary, and all links. Optionally retrieve page links.

Instructions

从网页 URL 提取结构化信息:标题、描述、正文摘要、所有链接。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes目标 URL
extract_linksNo是否提取页面链接(默认 false)
timeoutNo

Implementation Reference

  • The core handler function `_web_extract` that executes the web_extract tool logic: fetches a URL, extracts structured info (title, description, body summary, optional links) using httpx and BeautifulSoup.
    async def _web_extract(args: dict) -> list[types.TextContent]:
        url           = args["url"]
        extract_links = bool(args.get("extract_links", False))
        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")
            title       = soup.title.string.strip() if soup.title and soup.title.string else "(无标题)"
            desc_tag    = soup.find("meta", attrs={"name": "description"})
            _content    = desc_tag.get("content") if desc_tag else ""
            _content    = _content[0] if isinstance(_content, list) else _content
            description = _content.strip() if _content else "(无描述)"
            # 正文摘要(取前 500 字)
            for tag in soup(["script", "style", "nav", "footer"]):
                tag.decompose()
            body_text = soup.get_text(separator=" ", strip=True)[:500]
            lines = [
                f"🌐 **{title}**",
                f"URL: {url}",
                f"描述: {description}",
                f"\n**正文摘要:**\n{body_text}...",
            ]
            if extract_links:
                links = []
                for a in soup.find_all("a", href=True)[:20]:
                    href = str(a["href"])
                    text = a.get_text(strip=True)
                    if href.startswith("http") and text:
                        links.append(f"- [{text}]({href})")
                if links:
                    lines.append(f"\n**页面链接(前 {len(links)} 条):**")
                    lines.extend(links)
            return [types.TextContent(type="text", text="\n".join(lines))]
        except ImportError:
            return [types.TextContent(type="text",
                text="❌ 需要安装依赖: pip install httpx beautifulsoup4")]
        except Exception as e:
            return [types.TextContent(type="text", text=f"❌ 提取失败: {e}")]
  • Tool registration definition for 'web_extract' in the WEB_TOOLS list, including inputSchema (url required, optional extract_links and timeout).
    types.Tool(
        name="web_extract",
        description="从网页 URL 提取结构化信息:标题、描述、正文摘要、所有链接。",
        inputSchema={
            "type": "object",
            "properties": {
                "url":          {"type": "string", "description": "目标 URL"},
                "extract_links": {
                    "type": "boolean",
                    "description": "是否提取页面链接(默认 false)",
                    "default": False,
                },
                "timeout":  {"type": "integer", "default": 15},
            },
            "required": ["url"],
        },
    ),
  • The `handle_web` dispatch function that routes 'web_extract' calls to `_web_extract`.
    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}")
    
    
    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:
  • Server-level registration: maps each WEB_TOOLS tool name (including 'web_extract') to the handle_web dispatcher via _HANDLERS dict.
    for _t in WEB_TOOLS:    
        _HANDLERS[_t.name] = handle_web
  • Re-exports WEB_TOOLS and handle_web from the tools package.
    from onion_mcp_server.tools.ai     import AI_TOOLS,     handle_ai
    from onion_mcp_server.tools.code   import CODE_TOOLS,   handle_code
    from onion_mcp_server.tools.text   import TEXT_TOOLS,   handle_text
    from onion_mcp_server.tools.data   import DATA_TOOLS,   handle_data
    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",
    ]
Behavior2/5

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

No annotations provided, so description must disclose behaviors. It describes output fields but does not mention potential issues like rate limits, error handling, or that fetching and parsing may have timeouts (implied by param but not stated). Minimal behavioral context.

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?

Single sentence that conveys the core functionality. Front-loaded with action and outcome. Could be slightly more structured, but efficient overall.

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?

With no output schema, the description does not specify the exact format of return data (e.g., structure of links, encoding). Lacks error handling and edge case details, which is adequate for a simple extraction tool but leaves gaps.

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 67% (url and extract_links have descriptions). The tool description adds meaning by enumerating extracted fields (title, description, summary, links), which is not in schema. However, the timeout parameter lacks description in both schema and tool 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 specifies the tool extracts structured information (title, description, body summary, all links) from a URL. This clearly states the verb and resource, but does not explicitly differentiate it from sibling tools like web_fetch or web_search.

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 on when to use this tool versus alternatives (e.g., web_fetch for raw content, web_search for search). The description does not mention when not to use it or any prerequisites.

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