Skip to main content
Glama

Parse OpenAPI

parse_openapi

Parse an OpenAPI specification to extract a summary of all operations.

Instructions

Parse an OpenAPI spec and return a summary of operations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Main handler function for the parse_openapi tool. Accepts a file path, loads/dereferences the OpenAPI spec via loadSpec(), and returns title, version, servers, and a summary of operations.
    export async function parseOpenApiHandler(
      input: ParseOpenApiInput,
      config: McpDevtoolsConfig,
    ): Promise<ToolResult<ParseOpenApiOutput>> {
      const api = await loadSpec(input.path, config);
    
      const doc = api as unknown as Record<string, unknown>;
      const info = doc.info as { title?: string; version?: string } | undefined;
      const title = info?.title ?? "Untitled";
      const version = info?.version ?? "0.0.0";
    
      const servers = extractServers(doc);
      const operations = extractOperations(doc);
    
      return ok({ title, version, servers, operations });
    }
  • Input schema (Zod) defining the required 'path' string parameter for parse_openapi.
    export const ParseOpenApiInput = z.object({
      path: z.string().min(1),
    });
    
    export type ParseOpenApiInput = z.infer<typeof ParseOpenApiInput>;
  • Output type definitions: OperationSummary interface and ParseOpenApiOutput interface returned by the handler.
    export interface OperationSummary {
      operationId: string;
      method: string;
      path: string;
      summary?: string;
      tags?: string[];
    }
    
    export interface ParseOpenApiOutput {
      title: string;
      version: string;
      servers: string[];
      operations: OperationSummary[];
    }
  • Helper functions extractServers (handles OpenAPI 3.x and Swagger 2.0 server URLs) and extractOperations (iterates paths/methods to build operation summaries, capped at MAX_OPERATIONS=200).
    function extractServers(api: Record<string, unknown>): string[] {
      // OpenAPI 3.x: servers[].url
      const servers = api.servers as Array<{ url?: string }> | undefined;
      if (Array.isArray(servers)) {
        return servers.map((s) => s.url).filter((u): u is string => typeof u === "string");
      }
    
      // Swagger 2.0: host + basePath + schemes
      const host = api.host as string | undefined;
      if (typeof host === "string") {
        const basePath = (api.basePath as string) ?? "";
        const schemes = (api.schemes as string[]) ?? ["https"];
        return schemes.map((scheme) => `${scheme}://${host}${basePath}`);
      }
    
      return [];
    }
    
    function extractOperations(api: Record<string, unknown>): OperationSummary[] {
      const paths = api.paths as Record<string, Record<string, unknown>> | undefined;
      if (!paths) return [];
    
      const operations: OperationSummary[] = [];
    
      for (const [pathStr, pathItem] of Object.entries(paths)) {
        if (!pathItem || typeof pathItem !== "object") continue;
    
        for (const [method, operationValue] of Object.entries(pathItem)) {
          if (!HTTP_METHODS.has(method)) continue;
          if (!operationValue || typeof operationValue !== "object") continue;
    
          const op = operationValue as Record<string, unknown>;
          const operationId =
            typeof op.operationId === "string" ? op.operationId : `${method.toUpperCase()}_${pathStr}`;
    
          const summary: OperationSummary = {
            operationId,
            method: method.toUpperCase(),
            path: pathStr,
          };
    
          if (typeof op.summary === "string") {
            summary.summary = op.summary;
          }
          if (Array.isArray(op.tags) && op.tags.length > 0) {
            summary.tags = op.tags.filter((t): t is string => typeof t === "string");
          }
    
          operations.push(summary);
    
          if (operations.length >= MAX_OPERATIONS) {
            return operations;
          }
        }
      }
    
      return operations;
    }
  • Registration of the parse_openapi tool via defineTool(), wiring name 'parse_openapi', inputSchema ParseOpenApiInput, and handler parseOpenApiHandler into the allTools array.
    defineTool({
      name: "parse_openapi",
      title: "Parse OpenAPI",
      description: "Parse an OpenAPI spec and return a summary of operations.",
      inputSchema: ParseOpenApiInput,
      handler: parseOpenApiHandler,
    }),
Behavior2/5

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

No annotations provided; description does not disclose behavioral traits like file access mode, error handling, or output format. Fails to compensate for missing annotations.

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

Conciseness4/5

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

Single sentence, no redundant words. Could be improved by front-loading key details within same length.

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?

No output schema; description only says 'summary of operations' without specifying structure. Lacks file size limits, error conditions, or required permissions.

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?

Single parameter lacks description; schema coverage is 0%. Description adds no extra meaning about the 'path' parameter (e.g., local path, URL, supported extensions).

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

Purpose5/5

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

Clearly states verb (Parse), resource (OpenAPI spec), and result (summary of operations). Unambiguous and distinct from sibling tools.

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

Usage Guidelines3/5

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

Implied usage context (when you have an OpenAPI spec file), but no explicit when-to-use or when-not-to-use guidance or alternative recommendations.

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/marin1321/mcp-devtools'

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