fetch_url
Retrieve content from any URL using HTTP methods and custom headers to access web data for processing and integration.
Instructions
Fetch content from a URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| headers | No | HTTP headers to include | |
| method | No | HTTP method (GET, POST, etc.) | GET |
| url | Yes | The URL to fetch |
Implementation Reference
- server.js:313-341 (handler)Handler function that fetches URL content using node-fetch and returns structured response including status, headers, and content.async fetchUrl(url, method = 'GET', headers = {}) { const fetch = require('node-fetch'); try { const response = await fetch(url, { method, headers, }); const content = await response.text(); const responseInfo = { status: response.status, statusText: response.statusText, headers: Object.fromEntries(response.headers), content, }; return { content: [ { type: 'text', text: JSON.stringify(responseInfo, null, 2), }, ], }; } catch (error) { throw new Error(`Failed to fetch URL: ${error.message}`); } }
- server.py:268-290 (handler)Handler method that uses the requests library to perform HTTP requests and returns a JSON-structured response with status, headers, and content.async def fetch_url( self, url: str, method: str = "GET", headers: Optional[dict] = None ) -> list[types.TextContent]: """Fetch content from URL""" try: response = requests.request( method=method, url=url, headers=headers or {}, timeout=30, ) response_info = { "status": response.status_code, "statusText": response.reason, "headers": dict(response.headers), "content": response.text, } return [types.TextContent(type="text", text=json.dumps(response_info, indent=2))] except Exception as error: raise Exception(f"Failed to fetch URL: {str(error)}")
- server.js:116-138 (schema)Input schema definition for the fetch_url tool, specifying parameters url (required), method, and headers.{ name: 'fetch_url', description: 'Fetch content from a URL', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'The URL to fetch', }, method: { type: 'string', description: 'HTTP method (GET, POST, etc.)', default: 'GET', }, headers: { type: 'object', description: 'HTTP headers to include', }, }, required: ['url'], }, },
- server.py:145-166 (schema)Input schema definition for the fetch_url tool in the tool registration, matching the JS version.name="fetch_url", description="Fetch content from a URL", inputSchema={ "type": "object", "properties": { "url": { "type": "string", "description": "The URL to fetch", }, "method": { "type": "string", "description": "HTTP method (GET, POST, etc.)", "default": "GET", }, "headers": { "type": "object", "description": "HTTP headers to include", }, }, "required": ["url"], }, ),
- chatgpt-proxy.js:256-269 (handler)Inline handler for fetch_url in the ChatGPT proxy server, similar to server.js implementation.case 'fetch_url': const response = await fetch(args.url, { method: args.method || 'GET', headers: args.headers || {}, }); const responseContent = await response.text(); return { success: true, status: response.status, statusText: response.statusText, headers: Object.fromEntries(response.headers), content: responseContent, };