web_fetch
Retrieve web page data by specifying a URL, with options to set timeout, size limits, and custom headers. Integrates with TOOL4LM server for enhanced local LLM capabilities.
Instructions
Alias of web.fetch
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| headers | No | ||
| max_bytes | No | ||
| timeout | No | ||
| url | Yes |
Implementation Reference
- src/tools/webFetch.ts:4-22 (handler)The core handler function that fetches web content with configurable limits, processes the response based on content type, and returns a structured object with text or base64 body.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() }; }
- src/server.ts:65-70 (schema)Zod schema defining the input parameters for the web.fetch and web_fetch tools.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)MCP server registration for the 'web_fetch' tool, which aliases 'web.fetch' and invokes 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) }] }; } );