fetch_url
Retrieve content from any URL using an HTTP GET request. Ideal for extracting data or integrating web resources into workflows.
Instructions
Fetch content from a URL via HTTP GET request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to fetch |
Implementation Reference
- src/examples/single-node-server.ts:67-97 (handler)The handler for the fetch_url tool. It performs an HTTP GET request to the specified URL, captures the response status, headers, and body, and returns formatted text content. Handles errors by returning an error message.case "fetch_url": { const url = request.params.arguments?.url as string; if (!url) { throw new Error("URL is required"); } try { const response = await fetch(url); const content = await response.text(); const headers = Object.fromEntries(response.headers.entries()); return { content: [ { type: "text", text: `HTTP ${response.status} ${response.statusText}\n\nHeaders:\n${JSON.stringify(headers, null, 2)}\n\nBody:\n${content}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching URL: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- src/examples/single-node-server.ts:29-42 (registration)Tool registration in ListToolsRequestHandler, defining the name, description, and input schema requiring a 'url' string.{ name: "fetch_url", description: "Fetch content from a URL via HTTP GET request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to fetch", }, }, required: ["url"], }, },
- Input schema for fetch_url tool, specifying an object with a required 'url' string property.inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to fetch", }, }, required: ["url"], },