Skip to main content
Glama
aigo666

MCP Development Framework

url

Retrieve website content by fetching any URL. Provides the page's raw text for analysis or processing.

Instructions

Fetches a website and returns its content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to fetch

Implementation Reference

  • UrlTool class with execute() method that fetches a URL via HTTP GET and returns the content. This is the core handler for the 'url' tool.
    import httpx
    import mcp.types as types
    from . import BaseTool, ToolRegistry
    
    @ToolRegistry.register
    class UrlTool(BaseTool):
        """URL获取工具,用于获取网站内容"""
        name = "url"
        description = "Fetches a website and returns its content"
        input_schema = {
            "type": "object",
            "required": ["url"],
            "properties": {
                "url": {
                    "type": "string",
                    "description": "URL to fetch",
                }
            },
        }
        
        async def execute(self, arguments: dict) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
            """获取网站内容"""
            if "url" not in arguments:
                return [types.TextContent(
                    type="text",
                    text="Error: Missing required argument 'url'"
                )]
                
            url = arguments["url"]
            headers = {
                "User-Agent": "MCP Test Server (github.com/modelcontextprotocol/python-sdk)"
            }
            try:
                timeout = httpx.Timeout(10.0, connect=5.0)
                async with httpx.AsyncClient(
                    follow_redirects=True, 
                    headers=headers,
                    timeout=timeout
                ) as client:
                    response = await client.get(url)
                    response.raise_for_status()
                    return [types.TextContent(type="text", text=response.text)]
            except httpx.TimeoutException:
                return [types.TextContent(
                    type="text",
                    text="Error: Request timed out while trying to fetch the website."
                )]
            except httpx.HTTPStatusError as e:
                return [types.TextContent(
                    type="text",
                    text=(f"Error: HTTP {e.response.status_code} "
                          "error while fetching the website.")
                )]
            except Exception as e:
                return [types.TextContent(
                    type="text",
                    text=f"Error: Failed to fetch website: {str(e)}"
                )] 
  • Input schema for the 'url' tool, requiring a 'url' string property.
    input_schema = {
        "type": "object",
        "required": ["url"],
        "properties": {
            "url": {
                "type": "string",
                "description": "URL to fetch",
            }
        },
    }
  • The @ToolRegistry.register decorator registers the UrlTool class under the name 'url'.
    @ToolRegistry.register
  • ToolRegistry class that manages tool registration via the @register decorator.
    class ToolRegistry:
        """工具注册器,用于管理所有可用工具"""
        _tools: Dict[str, Type[BaseTool]] = {}
        
        @classmethod
        def register(cls, tool_class: Type[BaseTool]) -> Type[BaseTool]:
            """注册工具"""
            cls._tools[tool_class.name] = tool_class
            return tool_class
        
        @classmethod
        def get_tool(cls, name: str) -> Type[BaseTool]:
            """获取工具类"""
            if name not in cls._tools:
                raise ValueError(f"Unknown tool: {name}")
            return cls._tools[name]
        
        @classmethod
        def list_tools(cls) -> List[types.Tool]:
            """列出所有可用工具"""
            return [tool_class.get_tool_definition() for tool_class in cls._tools.values()]
        
        @classmethod
        def has_tool(cls, name: str) -> bool:
            """检查工具是否存在"""
            return name in cls._tools 
  • call_tool handler that dispatches tool calls by name to the appropriate tool instance (including 'url').
    @app.call_tool()
    async def fetch_tool( # type: ignore[unused-function]
        name: str, arguments: dict
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        if ToolRegistry.has_tool(name):
            tool_instance = tool_instances.get(name)
            if tool_instance:
                try:
                    return await tool_instance.execute(arguments)
                except Exception as e:
                    import traceback
                    error_details = traceback.format_exc()
                    return [types.TextContent(
                        type="text",
                        text=f"Error executing tool {name}: {str(e)}\n{error_details}"
                    )]
            else:
                return [types.TextContent(
                    type="text",
                    text=f"Error: Tool instance for {name} not found"
                )]
        else:
            return [types.TextContent(
                type="text",
                text=f"Error: Unknown tool: {name}"
            )]
Behavior2/5

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

No annotations are provided, so the description must convey behavior. It only states the action without disclosing important details like handling of redirects, timeouts, authentication, or the format of returned content.

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 with no unnecessary words; every part contributes to the purpose.

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 output schema and the tool's potential for varied responses (e.g., HTML, errors), the description omits critical context about content format, error handling, and limitations.

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 coverage is 100% with one parameter clearly described. The description adds no additional meaning beyond the schema, meeting the baseline for high coverage.

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 the tool fetches a website and returns its content, using a specific verb and resource. It distinguishes from sibling tools which are file parsers, not web fetchers.

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?

Description implies the tool is for fetching website content but provides no explicit guidance on when to use it versus alternatives or any exclusions.

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/aigo666/mcp-framework'

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