Skip to main content
Glama
gulbaki

Swagger/OpenAPI MCP Server

by gulbaki

load_api

Load API specifications into the Swagger/OpenAPI MCP Server by providing the API ID and source URL or file path to enable exploration and interaction with endpoints.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiIdYesUnique identifier for this API
sourceYesURL or file path to the OpenAPI/Swagger specification

Implementation Reference

  • The handler function that loads the OpenAPI/Swagger specification from the provided source, parses and dereferences it using SwaggerParser, caches it in the internal apis Map keyed by apiId, calculates path and endpoint counts, and returns a success message or error.
    async ({ apiId, source }) => { try { console.error(`Loading API from: ${source}`); const parser = new SwaggerParser(); const spec = await parser.dereference(source) as OpenAPIV3.Document; this.apis.set(apiId, { spec, parser }); const pathCount = Object.keys(spec.paths || {}).length; const endpointCount = Object.values(spec.paths || {}).reduce((count, pathItem) => { if (!pathItem) return count; return count + ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'] .filter(method => (pathItem as any)[method]).length; }, 0); return { content: [{ type: "text", text: `Successfully loaded API '${spec.info?.title || apiId}' (v${spec.info?.version || 'unknown'}) with ${pathCount} paths and ${endpointCount} endpoints.` }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to load API: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • Input schema defined using Zod validators for the two required parameters: apiId (unique string ID) and source (string URL or file path to the spec).
    { apiId: z.string().describe("Unique identifier for this API"), source: z.string().describe("URL or file path to the OpenAPI/Swagger specification") },
  • src/index.ts:194-231 (registration)
    The registration of the load_api tool on the McpServer instance using the tool() method, specifying the name, input schema, and handler function.
    "load_api", { apiId: z.string().describe("Unique identifier for this API"), source: z.string().describe("URL or file path to the OpenAPI/Swagger specification") }, async ({ apiId, source }) => { try { console.error(`Loading API from: ${source}`); const parser = new SwaggerParser(); const spec = await parser.dereference(source) as OpenAPIV3.Document; this.apis.set(apiId, { spec, parser }); const pathCount = Object.keys(spec.paths || {}).length; const endpointCount = Object.values(spec.paths || {}).reduce((count, pathItem) => { if (!pathItem) return count; return count + ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'] .filter(method => (pathItem as any)[method]).length; }, 0); return { content: [{ type: "text", text: `Successfully loaded API '${spec.info?.title || apiId}' (v${spec.info?.version || 'unknown'}) with ${pathCount} paths and ${endpointCount} endpoints.` }] }; } catch (error) { return { content: [{ type: "text", text: `Failed to load API: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );

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/gulbaki/swagger-mcp-server'

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