Skip to main content
Glama

web.fetch

Fetch web content from any URL with configurable size and time limits, and built-in anti-SSRF protection for safe retrieval.

Instructions

Fetch a URL with size/time limits and anti-SSRF.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
timeoutNo
max_bytesNo
headersNo

Implementation Reference

  • The core handler function that executes web.fetch logic: fetches a URL with limits, detects content type (text vs binary), and returns finalUrl/status/contentType/bodyText/bytesB64/fetchedAt.
    export async function webFetch(url: string) {
      const res = await fetchWithLimits(url, CONFIG.fetchTimeoutMs, CONFIG.maxFetchBytes);
      if (!res || !res.body) {
        return {
          finalUrl: url, status: res?.status || 0,
          contentType: res?.contentType || 'application/octet-stream',
          bodyText: null, bytesB64: null, fetchedAt: new Date().toISOString()
        };
      }
      const ct = (res.contentType || '').toLowerCase();
      const isText = ct.startsWith('text/') || ct.includes('html') || ct.includes('xml') || ct.includes('json');
      return {
        finalUrl: res.finalUrl || url, status: res.status,
        contentType: res.contentType,
        bodyText: isText ? res.body.toString('utf-8') : null,
        bytesB64: isText ? null : res.body.toString('base64'),
        fetchedAt: new Date().toISOString()
      };
    }
  • Low-level HTTP fetcher with SSRF protection (private IP blocking via DNS lookup + CIDR matching), timeout abort, max byte cap, and redirect support. Used by webFetch handler.
    export async function fetchWithLimits(urlStr: string, timeoutMs = CONFIG.fetchTimeoutMs, maxBytes = CONFIG.maxFetchBytes) {
      const u = new URL(urlStr);
      await assertNotPrivate(u);
    
      const controller = new AbortController();
      const timer = setTimeout(() => controller.abort(), timeoutMs);
      try {
        const res = await request(urlStr, {
          method: 'GET',
          headers: { 'user-agent': 'mcp-multitool/0.2', 'accept': '*/*' },
          signal: controller.signal,
          maxRedirections: 3
        });
    
        const status = res.statusCode;
        const headersRec: Record<string, string> = {};
        for (const [k, v] of Object.entries(res.headers)) {
          headersRec[k] = Array.isArray(v) ? v.join(', ') : String(v ?? '');
        }
    
        if (status >= 400) {
          return { status, headers: headersRec, body: null as any };
        }
    
        const chunks: Buffer[] = [];
        let total = 0;
        for await (const chunk of res.body) {
          const b: Buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as any);
          total += b.length;
          if (total > maxBytes) break;
          chunks.push(b);
        }
        const buf = Buffer.concat(chunks);
        const contentType = headersRec['content-type'] || 'application/octet-stream';
        const finalUrl = headersRec['content-location'] || urlStr;
        return { status, headers: headersRec, body: buf, finalUrl, contentType };
      } finally {
        clearTimeout(timer);
      }
    }
  • SSRF protection: resolves DNS and blocks requests to private/reserved IP ranges (127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, ::1/128, fc00::/7).
    async function assertNotPrivate(url: URL) {
      const host = url.hostname;
      if (net.isIP(host)) {
        if (ipInRanges(host, BLOCKEDv4) || ipInRanges(host, BLOCKEDv6)) {
          throw new Error('Blocked private IP (SSRF)');
        }
        return;
      }
      const addrs = await dns.lookup(host, { all: true });
      for (const a of addrs) {
        if ((a.family === 4 && ipInRanges(a.address, BLOCKEDv4)) ||
            (a.family === 6 && ipInRanges(a.address, BLOCKEDv6))) {
          throw new Error('Blocked private IP (SSRF)');
        }
      }
    }
  • Zod schema (webFetchShape) defining the input parameters for web.fetch: url (required string URL), timeout, max_bytes, and headers (optional).
    const webFetchShape = {
      url: z.string().url(),
      timeout: z.number().int().optional(),
      max_bytes: z.number().int().optional(),
      headers: z.record(z.string()).optional()
    };
  • src/server.ts:71-77 (registration)
    Registration of the 'web.fetch' tool with the McpServer, wiring the schema and the handler.
    server.tool('web.fetch', 'Fetch a URL with size/time limits and anti-SSRF.',
      webFetchShape, OPEN,
      async ({ url, timeout, max_bytes }) => {
        const res = await webFetch(url);
        return { content: [{ type: 'text', text: JSON.stringify(res) }] };
      }
    );

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observed

TDQS

B3/5.0
Behavior3/5

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

The description adds value beyond annotations by stating size/time limits and anti-SSRF protection. However, it omits details on error handling, timeouts, or what happens when limits are exceeded. Annotations provide openWorldHint, which aligns with network fetch behavior.

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, front-loaded with the core action, no redundant words. Efficiently communicates the tool's essence.

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?

Lacks output schema, return format, or error behavior description. For a fetch tool with 4 parameters, the description is too brief to fully inform an agent about expected behavior and edge cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description partially compensates by hinting at 'size/time limits' (mapping to max_bytes and timeout) but does not mention the headers parameter. Parameter names are somewhat self-explanatory, but the description should explicitly list or explain all parameters.

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?

Description uses 'Fetch a URL' as a specific verb+resource and mentions size/time limits and anti-SSRF, clearly distinguishing it from sibling tools like web.read or web.search. However, it could be more explicit about what 'fetch' returns (e.g., page content).

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 on when to use this tool vs alternatives like web.read or web.search. The description does not mention use cases, prerequisites, or exclusion criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/khanhs-234/tool4lm'

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