Skip to main content
Glama
saksham0712

MCP Complete Implementation Guide

by saksham0712

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
NameRequiredDescriptionDefault
headersNoHTTP headers to include
methodNoHTTP method (GET, POST, etc.)GET
urlYesThe URL to fetch

Implementation Reference

  • 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}`);
      }
    }
  • 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)}")
  • 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'],
      },
    },
  • 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"],
        },
    ),
  • 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,
      };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention error handling, timeouts, authentication needs, rate limits, or what 'content' includes (e.g., HTML, JSON, binary data). This leaves significant gaps for an agent to understand how to use it effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero waste—it directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of HTTP operations and lack of annotations or output schema, the description is incomplete. It doesn't explain return values (e.g., status codes, body content), error cases, or behavioral nuances like redirects or timeouts, which are critical for proper tool usage in this context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters (url, method, headers) thoroughly. The description adds no additional meaning beyond implying URL fetching, which is redundant with the schema. This meets the baseline of 3 when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Fetch content from a URL' clearly states the verb ('fetch') and resource ('content from a URL'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'read_file' or 'execute_command' which might also retrieve data, so it's not fully distinctive.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention scenarios like web scraping, API calls, or file downloads, nor does it contrast with siblings like 'read_file' for local files or 'execute_command' for system-level operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saksham0712/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server