Skip to main content
Glama
zcaceres

Fetch MCP Server

by zcaceres

fetch_txt

Extract plain text content from websites by fetching URLs and converting HTML to readable text with configurable length and starting point.

Instructions

Fetch a website, convert the content to plain text (no HTML)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the website to fetch
headersNoOptional headers to include in the request
max_lengthNoMaximum number of characters to return (default: 5000)
start_indexNoStart content from this character index (default: 0)

Implementation Reference

  • Core handler for 'fetch_txt': fetches HTML, strips scripts/styles using JSDOM, extracts and normalizes plain text, applies length limits.
    static async txt(requestPayload: RequestPayload) {
      try {
        const response = await this._fetch(requestPayload);
        const html = await response.text();
    
        const dom = new JSDOM(html);
        const document = dom.window.document;
    
        const scripts = document.getElementsByTagName("script");
        const styles = document.getElementsByTagName("style");
        Array.from(scripts).forEach((script) => script.remove());
        Array.from(styles).forEach((style) => style.remove());
    
        const text = document.body.textContent || "";
        let normalizedText = text.replace(/\s+/g, " ").trim();
        
        // Apply length limits
        normalizedText = this.applyLengthLimits(
          normalizedText,
          requestPayload.max_length ?? 5000,
          requestPayload.start_index ?? 0
        );
    
        return {
          content: [{ type: "text", text: normalizedText }],
          isError: false,
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: (error as Error).message }],
          isError: true,
        };
      }
    }
  • Zod validation schema for fetch_txt input parameters (shared across fetch tools). Used in index.ts for parsing args.
    export const RequestPayloadSchema = z.object({
      url: z.string().url(),
      headers: z.record(z.string()).optional(),
      max_length: z.number().int().min(0).optional().default(downloadLimit),
      start_index: z.number().int().min(0).optional().default(0),
    });
  • src/index.ts:82-108 (registration)
    Tool registration in ListTools handler: defines name, description, and inputSchema for 'fetch_txt'.
    {
      name: "fetch_txt",
      description:
        "Fetch a website, convert the content to plain text (no 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",
          },
          max_length: {
            type: "number",
            description: `Maximum number of characters to return (default: ${downloadLimit})`,
          },
          start_index: {
            type: "number",
            description: "Start content from this character index (default: 0)",
          },
        },
        required: ["url"],
      },
    },
  • src/index.ts:152-154 (registration)
    Dispatch logic in CallToolRequest handler: routes 'fetch_txt' calls to Fetcher.txt implementation.
    if (request.params.name === "fetch_txt") {
      const fetchResult = await Fetcher.txt(validatedArgs);
      return fetchResult;
  • Shared helper for performing secure HTTP fetches with private IP blocking and custom headers, used by all fetch tools including txt.
    private static async _fetch({
      url,
      headers,
    }: RequestPayload): Promise<Response> {
      try {
        if (is_ip_private(url)) {
          throw new Error(
            `Fetcher blocked an attempt to fetch a private IP ${url}. This is to prevent a security vulnerability where a local MCP could fetch privileged local IPs and exfiltrate data.`,
          );
        }
        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?

No annotations are provided, so the description carries the full burden. It mentions fetching and conversion but lacks details on error handling, rate limits, authentication needs, or what happens with invalid URLs. For a tool with no annotations, this leaves significant behavioral gaps.

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 front-loads the core functionality with zero wasted words, making it easy to understand quickly.

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?

Given no annotations and no output schema, the description covers the basic purpose but lacks details on return values, error cases, or operational constraints. It is minimally adequate but has clear gaps for a tool that interacts with external websites.

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 fully documents all parameters. The description does not add any parameter-specific details beyond what the schema provides, such as examples or usage tips, meeting the baseline for high schema 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?

The description clearly states the specific action ('fetch a website') and transformation ('convert the content to plain text (no HTML)'), distinguishing it from sibling tools like fetch_html, fetch_json, and fetch_markdown which handle different output formats.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implicitly suggests usage for extracting plain text from websites, but does not explicitly state when to use this tool versus alternatives like fetch_html for raw HTML or fetch_markdown for markdown conversion. It provides clear context but lacks explicit exclusions or named 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

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/zcaceres/fetch-mcp'

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