Skip to main content
Glama
aigo666

MCP Development Framework

url

Fetch website content from any URL to retrieve and analyze web data directly within your development environment.

Instructions

Fetches a website and returns its content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to fetch

Implementation Reference

  • The async execute method that handles URL fetching using httpx.AsyncClient, with timeout, redirects, custom User-Agent, and error handling for missing args, timeouts, HTTP errors, and exceptions.
    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)}"
            )] 
  • The input_schema defining the tool's input as an object requiring a 'url' string parameter.
    input_schema = {
        "type": "object",
        "required": ["url"],
        "properties": {
            "url": {
                "type": "string",
                "description": "URL to fetch",
            }
        },
    }
  • Registration via @ToolRegistry.register decorator on UrlTool class, setting name='url' and description.
    @ToolRegistry.register
    class UrlTool(BaseTool):
        """URL获取工具,用于获取网站内容"""
        name = "url"
        description = "Fetches a website and returns its content"

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