Skip to main content
Glama

web_fetch

Fetch web page content by URL, with configurable timeout, maximum bytes, and custom headers. Returns raw data for analysis.

Instructions

Alias of web.fetch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
timeoutNo
max_bytesNo
headersNo

Implementation Reference

  • The webFetch function that implements the tool's core logic: fetches a URL with size/time limits, determines if the response is text or binary, and returns structured output.
    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()
      };
    }
  • Input schema for the web_fetch tool: defines url (required), timeout, max_bytes, and headers fields.
    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:78-84 (registration)
    Registration of the 'web_fetch' tool (alias of 'web.fetch') via server.tool(), binding the schema to the webFetch handler.
    server.tool('web_fetch', 'Alias of web.fetch',
      webFetchShape, OPEN,
      async ({ url, timeout, max_bytes }) => {
        const res = await webFetch(url);
        return { content: [{ type: 'text', text: JSON.stringify(res) }] };
      }
    );
  • The fetchWithLimits helper: performs HTTP GET with SSRF protection, timeout via AbortController, and max byte limiting.
    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);
      }
    }
  • The assertNotPrivate helper: DNS-resolves and checks if the target IP is in private/reserved ranges (anti-SSRF).
    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)');
        }
      }
    }
Behavior1/5

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

No behavioral traits are disclosed. The description does not mention read-only, destructiveness, permissions, or side effects. The annotation openWorldHint: true is present but the description adds no context beyond it.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very short but lacks essential information. This is under-specification, not conciseness. A single sentence that merely references another tool is insufficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 4 parameters including a nested object and no output schema, the description is completely inadequate. It fails to provide necessary context for the agent to use the tool correctly.

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

Parameters1/5

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

Schema description coverage is 0%, yet the description does not explain any parameter (url, timeout, max_bytes, headers). The description adds no meaning beyond the schema itself.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Alias of web.fetch' is a tautology that does not state what the tool does. It relies entirely on the agent knowing 'web.fetch', which is a separate sibling tool. The name 'web_fetch' suggests fetching web content but the description adds no clarity.

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

Usage Guidelines1/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 versus alternatives like web.fetch or web.read. The description provides no context on the tool's role or selection criteria.

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

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