Skip to main content
Glama

fetch_html

Retrieve HTML content from a specified URL using optional headers for web scraping or content extraction.

Instructions

Fetch a website and return the content as HTML

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
headersNoOptional headers to include in the request
urlYesURL of the website to fetch

Implementation Reference

  • The primary handler function for the 'fetch_html' tool. It fetches the URL, retrieves the HTML content, and returns it in the expected MCP format. Handles errors gracefully.
    static async html(requestPayload: RequestPayload) {
      try {
        const response = await this._fetch(requestPayload);
        const html = await response.text();
        return { content: [{ type: "text", text: html }], isError: false };
      } catch (error) {
        return {
          content: [{ type: "text", text: (error as Error).message }],
          isError: true,
        };
      }
    }
  • src/index.ts:50-68 (registration)
    Registration of the 'fetch_html' tool in the ListTools response, including name, description, and input schema.
    {
      name: "fetch_html",
      description: "Fetch a website and return the content as HTML",
      inputSchema: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "URL of the website to fetch",
          },
          headers: {
            type: "object",
            description: "Optional headers to include in the request",
          },
        },
        required: ["url"],
      },
    },
    {
  • Zod schema for validating the tool input parameters (url and optional headers), used before calling the handler.
    import { z } from "zod";
    
    export const RequestPayloadSchema = z.object({
      url: z.string().url(),
      headers: z.record(z.string()).optional(),
    });
    
    export type RequestPayload = z.infer<typeof RequestPayloadSchema>;
  • Dispatch logic in the CallToolRequest handler that routes 'fetch_html' calls to Fetcher.html.
    if (request.params.name === "fetch_html") {
      const fetchResult = await Fetcher.html(validatedArgs);
      return fetchResult;
    }
  • Shared helper method for performing the HTTP fetch with custom headers and User-Agent, used by all fetch tools including fetch_html.
    export class Fetcher {
      private static async _fetch({
        url,
        headers,
      }: RequestPayload): Promise<Response> {
        try {
          const response = await fetch(url, {
            headers: {
              "User-Agent":
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
              ...headers,
            },
          });
    
          if (!response.ok) {
            throw new Error(`HTTP error: ${response.status}`);
          }
          return response;
        } catch (e: unknown) {
          if (e instanceof Error) {
            throw new Error(`Failed to fetch ${url}: ${e.message}`);
          } else {
            throw new Error(`Failed to fetch ${url}: Unknown error`);
          }
        }
      }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral context. It states the basic operation but doesn't disclose important traits like error handling, timeout behavior, authentication needs, rate limits, or what happens with invalid URLs. For a network tool with zero annotation coverage, this is insufficient.

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?

The description is a single, efficient sentence that communicates the core functionality without unnecessary words. It's appropriately sized and front-loaded with the essential information.

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?

For a network fetch tool with no annotations and no output schema, the description is inadequate. It doesn't explain what gets returned beyond 'HTML' (structure, errors, status codes), doesn't mention network behavior, and provides no guidance on usage versus siblings. The complexity warrants more complete documentation.

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 100%, so the schema already documents both parameters (url and headers). The description doesn't add any parameter-specific information beyond what's in the schema. Baseline 3 is appropriate when the schema does the heavy lifting.

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 clearly states the action ('fetch') and resource ('a website'), specifying the return format ('content as HTML'). It distinguishes from sibling tools by mentioning HTML output, but doesn't explicitly contrast with fetch_json, fetch_markdown, or fetch_txt beyond format differences.

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 is provided on when to use this tool versus the sibling tools (fetch_json, fetch_markdown, fetch_txt). The description implies it's for fetching websites, but doesn't specify scenarios where HTML output is preferred over JSON, Markdown, or plain text alternatives.

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

Related 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/tokenizin-agency/mcp-npx-fetch'

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