Skip to main content
Glama

fetch_openapi_spec

Retrieve OpenAPI specification content from one or more URLs to integrate API documentation into development workflows using SushiMCP.

Instructions

Fetches the content of one or more OpenAPI spec URLs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesURL string, URL object, or array of URL/objects to fetch OpenAPI specs from

Implementation Reference

  • Core implementation of the fetch_openapi_spec tool handler. Normalizes input URLs, parses targets, checks domains, fetches content, and returns text contents.
    export const fetch_openapi_spec = async (
      input: UrlFetchInput,
      extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
      allowedDomains: Set<string>
    ): Promise<CallToolResult> => {
      logger.debug("Processing fetch_openapi_spec request with input:", input);
    
      // Normalize input to always be an array of { url: string } objects
      const urlList = normalizeUrlInput(input);
      const results: TextContent[] = [];
    
      for (const urlItem of urlList) {
        const url = urlItem.url;
    
        try {
          logger.debug(`Processing OpenAPI spec URL: ${url}`);
    
          // Validate the URL and get target info using the library function
          const targetInfo = await parseFetchTarget(url);
          if (targetInfo.type === "unsupported") {
            const errorMsg = `Unsupported URL format: ${targetInfo.reason}`;
            logger.error(errorMsg);
            throw new Error(errorMsg);
          }
    
          logger.debug(`Target info:`, targetInfo);
    
          // Check domain access using the library function
          checkDomainAccess(targetInfo, allowedDomains);
    
          logger.debug(`Fetching OpenAPI spec from: ${url}`);
    
          // Fetch the content using the library function
          const fileContent = await fetchContent(targetInfo);
          results.push({
            type: "text",
            text: fileContent,
          });
    
          logger.debug(
            `Successfully fetched ${fileContent.length} bytes from ${url}`
          );
        } catch (error) {
          const errorMsg = `Failed to process OpenAPI spec request for ${url}: ${
            error instanceof Error ? error.message : String(error)
          }`;
          logger.error(errorMsg);
          throw new Error(errorMsg);
        }
      }
    
      logger.debug(`Successfully processed ${results.length} OpenAPI specs`);
      return {
        content: results,
      };
    };
  • Zod schema defining the input for URL fetch tools, supporting single URL string, URL object, or array. Used by both fetch_openapi_spec and fetch_llms_txt.
    export const UrlFetchInputSchema = z.union([
      z.string().url("Input must be a valid URL string"),
      z.object({
        url: z
          .string()
          .url("Input must contain a valid URL string under the 'url' key"),
      }),
      z.array(
        z.union([
          z.string().url("Each array item must be a valid URL string"),
          z.object({
            url: z
              .string()
              .url(
                "Each array item must contain a valid URL string under the 'url' key"
              ),
          }),
        ])
      ),
    ]);
    
    // Type exports for use in function parameters
    export type UrlFetchInput = z.infer<typeof UrlFetchInputSchema>;
  • src/index.ts:90-101 (registration)
    Tool capabilities declaration including name, description, inputSchema reference, and annotations.
    fetch_openapi_spec: {
      name: "fetch_openapi_spec",
      description: "Fetches the content of a OpenAPI spec url.",
      inputSchema: UrlFetchInputSchema,
      annotations: {
        title: "Fetch OpenAPI spec content",
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: true,
      },
    },
  • src/index.ts:142-161 (registration)
    Actual server.tool registration that wraps the imported handler, handles params.input extraction, and passes extra and allowedDomains.
    server.tool(
      "fetch_openapi_spec",
      "Fetches the content of one or more OpenAPI spec URLs.",
      {
        input: UrlFetchInputSchema.describe(
          "URL string, URL object, or array of URL/objects to fetch OpenAPI specs from"
        ),
      },
      async (params, extra) => {
        const input = params?.input ?? params;
        if (!input) {
          throw new Error("No input provided to fetch_openapi_spec");
        }
        return fetch_openapi_spec(
          input,
          extra as RequestHandlerExtra<ServerRequest, ServerNotification>,
          allowedDomains
        );
      }
    );
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool fetches content but omits critical details: whether it handles errors (e.g., invalid URLs), supports authentication, has rate limits, returns raw text or parsed data, or includes metadata like HTTP status. For a fetch operation with zero annotation coverage, this is a significant gap in transparency.

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, efficient sentence that front-loads the core action ('fetches') and resource ('OpenAPI spec URLs'), with zero wasted words. It's appropriately sized for the tool's complexity, making it easy for an agent to parse quickly without unnecessary elaboration.

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 has no annotations and no output schema, the description is incomplete. It doesn't explain what the return values look like (e.g., structured data, raw text), error handling, or behavioral constraints like network timeouts. For a fetch operation that could involve multiple URLs and potential failures, more context is needed to guide the agent effectively.

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%, with the schema detailing that 'input' can be a URL string, URL object, or array of URLs/objects. The description adds minimal value beyond this, only noting it fetches from 'one or more OpenAPI spec URLs', which aligns with the schema's array support. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't provide additional syntax or format details.

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 ('fetches') and resource ('content of one or more OpenAPI spec URLs'), making the purpose immediately understandable. It distinguishes from sibling tools like 'list_openapi_spec_sources' by focusing on fetching content rather than listing sources. However, it doesn't specify the format of the fetched content (e.g., JSON/YAML), which prevents a perfect score.

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_llms_txt' or 'list_openapi_spec_sources'. It doesn't mention prerequisites, such as whether URLs need to be accessible or authenticated, or clarify use cases like bulk fetching versus single spec retrieval. This leaves the agent without context for tool selection.

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/maverickg59/sushimcp'

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