Skip to main content
Glama

fetch_json

Retrieve JSON data from any URL by specifying the endpoint and optional headers. Simplify API integration and data extraction for web content.

Instructions

Fetch a JSON file from a URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
headersNoOptional headers to include in the request
urlYesURL of the JSON to fetch

Implementation Reference

  • The static method `Fetcher.json` that executes the core logic of the `fetch_json` tool: fetches the JSON from the provided URL, parses it, stringifies it, and returns it in the expected MCP response format.
    static async json(requestPayload: RequestPayload) {
      try {
        const response = await this._fetch(requestPayload);
        const json = await response.json();
        return {
          content: [{ type: "text", text: JSON.stringify(json) }],
          isError: false,
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: (error as Error).message }],
          isError: true,
        };
      }
  • src/index.ts:105-122 (registration)
    Registers the `fetch_json` tool in the `ListToolsRequestHandler` with its name, description, and input schema.
    {
      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",
          },
        },
        required: ["url"],
      },
    },
  • Dispatches the `CallToolRequest` for `fetch_json` by calling `Fetcher.json` after validation.
    if (request.params.name === "fetch_json") {
      const fetchResult = await Fetcher.json(validatedArgs);
      return fetchResult;
  • Shared Zod schema `RequestPayloadSchema` used to validate the input arguments for the `fetch_json` tool (and others) in the `CallToolRequestHandler`.
    import { z } from "zod";
    
    export const RequestPayloadSchema = z.object({
      url: z.string().url(),
      headers: z.record(z.string()).optional(),
    });
    
    export type RequestPayload = z.infer<typeof RequestPayloadSchema>;
  • Private helper method `_fetch` used by `Fetcher.json` (and other methods) to perform the actual HTTP fetch with error handling and default User-Agent.
    private static async _fetch({
      url,
      headers,
    }: RequestPayload): Promise<Response> {
      try {
        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. 'Fetch a JSON file from a URL' implies a read operation but doesn't specify error handling, authentication needs, rate limits, or what happens if the URL doesn't return valid JSON. This leaves significant behavioral gaps for an agent.

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 extremely concise at just one sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple tool, 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 lack of annotations and output schema, the description is incomplete for effective tool use. It doesn't explain what the tool returns (parsed JSON object? raw response?), error conditions, or behavioral constraints, leaving the agent with insufficient context for a fetch operation.

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 schema description coverage is 100%, with both parameters clearly documented in the schema itself. The description doesn't add any meaningful parameter semantics beyond what's already in the schema, so it meets the baseline for high schema coverage without providing extra value.

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

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. There are no explicit instructions about when to choose fetch_json over fetch_html, fetch_markdown, or fetch_txt, nor any context about prerequisites or exclusions for its use.

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

Related 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/tokenizin-agency/mcp-npx-fetch'

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