Skip to main content
Glama
zcaceres

Fetch MCP Server

by zcaceres

fetch_json

Retrieve JSON data from a URL by specifying the source address, optional headers, and content length parameters for web content integration.

Instructions

Fetch a JSON file from a URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the JSON to fetch
headersNoOptional headers to include in the request
max_lengthNoMaximum number of characters to return (default: 5000)
start_indexNoStart content from this character index (default: 0)

Implementation Reference

  • Core handler logic for 'fetch_json': fetches URL, parses JSON, stringifies it, applies length limits, returns formatted content or error.
    static async json(requestPayload: RequestPayload) {
      try {
        const response = await this._fetch(requestPayload);
        const json = await response.json();
        let jsonString = JSON.stringify(json);
        
        // Apply length limits
        jsonString = this.applyLengthLimits(
          jsonString,
          requestPayload.max_length ?? 5000,
          requestPayload.start_index ?? 0
        );
        
        return {
          content: [{ type: "text", text: jsonString }],
          isError: false,
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: (error as Error).message }],
          isError: true,
        };
      }
  • Zod schema for validating input parameters to 'fetch_json' and other fetch tools.
    export const RequestPayloadSchema = z.object({
      url: z.string().url(),
      headers: z.record(z.string()).optional(),
      max_length: z.number().int().min(0).optional().default(downloadLimit),
      start_index: z.number().int().min(0).optional().default(0),
    });
  • src/index.ts:109-134 (registration)
    Tool registration in ListTools handler, defining name, description, and input schema for 'fetch_json'.
    {
      name: "fetch_json",
      description: "Fetch a JSON file from a URL",
      inputSchema: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "URL of the JSON to fetch",
          },
          headers: {
            type: "object",
            description: "Optional headers to include in the request",
          },
          max_length: {
            type: "number",
            description: `Maximum number of characters to return (default: ${downloadLimit})`,
          },
          start_index: {
            type: "number",
            description: "Start content from this character index (default: 0)",
          },
        },
        required: ["url"],
      },
    },
  • Dispatch logic in CallToolRequest handler that routes 'fetch_json' calls to Fetcher.json.
    if (request.params.name === "fetch_json") {
      const fetchResult = await Fetcher.json(validatedArgs);
      return fetchResult;
  • Shared helper method for performing the HTTP fetch with security checks and error handling, used by 'fetch_json'.
    private static async _fetch({
      url,
      headers,
    }: RequestPayload): Promise<Response> {
      try {
        if (is_ip_private(url)) {
          throw new Error(
            `Fetcher blocked an attempt to fetch a private IP ${url}. This is to prevent a security vulnerability where a local MCP could fetch privileged local IPs and exfiltrate data.`,
          );
        }
        const response = await fetch(url, {
          headers: {
            "User-Agent":
              "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
            ...headers,
          },
        });
    
        if (!response.ok) {
          throw new Error(`HTTP error: ${response.status}`);
        }
        return response;
      } catch (e: unknown) {
        if (e instanceof Error) {
          throw new Error(`Failed to fetch ${url}: ${e.message}`);
        } else {
          throw new Error(`Failed to fetch ${url}: Unknown error`);
        }
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the basic action but omits critical details such as error handling (e.g., for invalid URLs or non-JSON responses), authentication needs, rate limits, or whether it performs safe read operations. This leaves significant gaps in understanding the tool's behavior.

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, direct sentence that efficiently conveys the core purpose without any wasted words. It is front-loaded and appropriately sized for the tool's complexity, 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 tool's moderate complexity (4 parameters, no output schema, and no annotations), the description is incomplete. It lacks details on return values, error cases, or behavioral traits, which are essential for an agent to use the tool effectively in varied contexts.

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?

The input schema has 100% description coverage, clearly documenting all four parameters (url, headers, max_length, start_index). The description adds no additional meaning beyond what the schema provides, such as examples or usage notes, so it meets the baseline for adequate but unenhanced parameter semantics.

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 clearly states the action ('Fetch') and resource ('a JSON file from a URL'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like fetch_html or fetch_markdown, which likely perform similar operations on different file types, so it misses full sibling distinction.

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 like fetch_html or fetch_markdown. It lacks any mention of prerequisites, exclusions, or specific contexts, leaving the agent to infer usage based on the tool name alone.

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/zcaceres/fetch-mcp'

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