Skip to main content
Glama

fetch_url

Fetch data from web URLs using HTTP methods like GET or POST, with configurable headers, body content, and timeout settings for automation workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
methodNoGET
headersNo
bodyNo
timeoutNo
followRedirectsNo

Implementation Reference

  • The core handler function for the 'fetch_url' tool that executes the HTTP request using fetchWithTimeout, processes the response text and headers, and returns formatted content and metadata.
    async ({ url, method, headers, body, timeout, followRedirects }) => {
      return wrapToolExecution(async () => {
        const response = await fetchWithTimeout(url, {
          method,
          headers,
          body,
          timeout,
          followRedirects
        });
    
        const responseText = await response.text();
        const responseHeaders = extractHeaders(response);
    
        return {
          content: [{ type: "text" as const, text: responseText }],
          metadata: {
            status: response.status,
            statusText: response.statusText,
            headers: responseHeaders,
            url: response.url
          }
        };
      }, {
        errorCode: ERROR_CODES.HTTP_REQUEST,
        context: "Failed to fetch URL"
      });
    }
  • Zod schema for input validation of the 'fetch_url' tool parameters: url (required), method, headers, body, timeout, followRedirects.
    {
      url: z.string().url("Valid URL is required"),
      method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().default(DEFAULTS.HTTP_METHOD),
      headers: z.record(z.string()).optional().default({}),
      body: z.string().optional(),
      timeout: z.number().optional().default(DEFAULT_TIMEOUTS.HTTP_REQUEST),
      followRedirects: z.boolean().optional().default(DEFAULTS.HTTP_FOLLOW_REDIRECTS)
  • The registerFetchUrl function that directly registers the 'fetch_url' tool on the MCP server using server.tool(), including schema and handler.
    function registerFetchUrl(server: McpServer): void {
      server.tool("fetch_url",
        {
          url: z.string().url("Valid URL is required"),
          method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().default(DEFAULTS.HTTP_METHOD),
          headers: z.record(z.string()).optional().default({}),
          body: z.string().optional(),
          timeout: z.number().optional().default(DEFAULT_TIMEOUTS.HTTP_REQUEST),
          followRedirects: z.boolean().optional().default(DEFAULTS.HTTP_FOLLOW_REDIRECTS)
        },
        async ({ url, method, headers, body, timeout, followRedirects }) => {
          return wrapToolExecution(async () => {
            const response = await fetchWithTimeout(url, {
              method,
              headers,
              body,
              timeout,
              followRedirects
            });
    
            const responseText = await response.text();
            const responseHeaders = extractHeaders(response);
    
            return {
              content: [{ type: "text" as const, text: responseText }],
              metadata: {
                status: response.status,
                statusText: response.statusText,
                headers: responseHeaders,
                url: response.url
              }
            };
          }, {
            errorCode: ERROR_CODES.HTTP_REQUEST,
            context: "Failed to fetch URL"
          });
        }
      );
    }
  • src/index.ts:66-66 (registration)
    Invocation of registerWebTools(server) in the main server initialization, which calls registerFetchUrl to register the tool.
    registerWebTools(server);
  • Key helper function fetchWithTimeout used by the handler to perform HTTP fetches with configurable timeout, method, headers, body, and redirect handling using AbortController.
    async function fetchWithTimeout(
      url: string,
      options: {
        method: HttpMethod;
        headers?: Record<string, string>;
        body?: string;
        timeout: number;
        followRedirects: boolean;
      }
    ): Promise<Response> {
      const { method, headers, body, timeout, followRedirects } = options;
      const controller = new AbortController();
      const timeoutId = setTimeout(() => controller.abort(), timeout);
    
      const requestInit: RequestInit = {
        method,
        headers,
        signal: controller.signal,
        redirect: followRedirects ? "follow" : "manual"
      };
    
      if (body && ["POST", "PUT", "PATCH"].includes(method)) {
        requestInit.body = body;
      }
    
      try {
        const response = await fetch(url, requestInit);
        return response;
      } catch (error) {
        if (error instanceof Error && error.name === 'AbortError') {
          throw new Error(`Request timeout after ${timeout}ms`);
        }
        throw error;
      } finally {
        clearTimeout(timeoutId);
      }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/ishuru/open-mcp'

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