fetch_url
Fetch content from any web URL to extract text and data for analysis, processing, or integration with other tools.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| maxBytes | No |
Implementation Reference
- src/server.js:101-132 (handler)Handler function that fetches the URL content using undici fetch, respects maxBytes limit by reading stream in chunks, extracts content-type and body as text, returns structured content with summary and body.async (input) => { const maxBytes = Math.min(input.maxBytes ?? MAX_FETCH_BYTES, 16 * 1024 * 1024); const res = await fetch(input.url, { headers: { "User-Agent": "Mozilla/5.0 (compatible; MCP-Web-Tools/0.1; +https://example.com)", Accept: "*/*", }, }); const contentType = res.headers.get("content-type") || ""; const reader = res.body.getReader(); let received = 0; const chunks = []; while (true) { const { done, value } = await reader.read(); if (done) break; received += value.byteLength; if (received > maxBytes) { chunks.push(value.subarray(0, value.byteLength - (received - maxBytes))); break; } chunks.push(value); } const body = Buffer.concat(chunks.map((u) => Buffer.from(u))).toString("utf8"); const summary = `contentType: ${contentType}\nbytes: ${Math.min(received, maxBytes)}`; return { content: [ { type: "text", text: summary }, { type: "text", text: body }, ], }; }
- src/server.js:97-100 (schema)Input schema using Zod: requires a valid URL, optional maxBytes between 1KB and 16MB.{ url: z.string().url(), maxBytes: z.number().int().min(1024).max(16 * 1024 * 1024).optional(), },
- src/server.js:95-96 (registration)Tool registration call: server.tool("fetch_url", schema, handler) registering the fetch_url tool with MCP server.server.tool( "fetch_url",