Skip to main content
Glama
jankowtf

MCP Server Template for Cursor IDE

by jankowtf

mcp_fetch

Fetch website content from any URL to extract text, code, or data for analysis within Cursor IDE.

Instructions

Fetches a website and returns its content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to fetch

Implementation Reference

  • Core handler function that asynchronously fetches website content using httpx, returns the HTML as TextContent, and handles timeout, HTTP errors, and general exceptions.
    async def fetch_website(
        url: str,
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        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)}"
                )
            ]
  • Dispatch logic within the main tool handler function that validates input and calls the fetch_website implementation for the mcp_fetch tool.
    if name == "mcp_fetch":
        if "url" not in arguments:
            return [
                types.TextContent(
                    type="text", text="Error: Missing required argument 'url'"
                )
            ]
        return await fetch_website(arguments["url"])
  • Tool registration in list_tools() including name, description, and input schema definition.
    types.Tool(
        name="mcp_fetch",
        description="Fetches a website and returns its content",
        inputSchema={
            "type": "object",
            "required": ["url"],
            "properties": {
                "url": {
                    "type": "string",
                    "description": "URL to fetch",
                }
            },
        },
    ),
  • Input schema for the mcp_fetch tool, requiring a 'url' string parameter.
    inputSchema={
        "type": "object",
        "required": ["url"],
        "properties": {
            "url": {
                "type": "string",
                "description": "URL to fetch",
            }
        },
    },

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/jankowtf/mcp-hitchcode'

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