Skip to main content
Glama

web.fetch

Fetch web content from URLs with configurable size and timeout limits while preventing SSRF attacks. Retrieve data safely for local LLM processing.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
timeoutNo
max_bytesNo
headersNo

Implementation Reference

  • Core implementation of the web.fetch tool logic: fetches URL with limits, handles response, extracts text or base64 body based on content type, anti-SSRF implied via fetchWithLimits.
    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() }; }
  • Zod input schema for web.fetch tool parameters.
    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 on the MCP server, providing schema, access control (OPEN), and thin wrapper 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) }] }; } );
  • src/server.ts:78-84 (registration)
    Registration of the 'web_fetch' alias for web.fetch tool.
    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) }] }; } );

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