fetch_url
Retrieve content from any web URL using HTTP GET requests to access online data and resources.
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 function for the 'fetch_url' tool. It extracts the URL from arguments, performs an HTTP GET request using the fetch API, retrieves the response status, headers, and body content, and returns it formatted as 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)Registration of the 'fetch_url' tool in the ListTools response. Includes the tool name, description, and input schema defining a required 'url' string property.{ 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"], }, },
- The input schema for the 'fetch_url' tool, specifying an object with a single required 'url' property of type string.inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to fetch", }, }, required: ["url"], },