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
| Name | Required | Description | Default |
|---|---|---|---|
| apiId | Yes | Unique identifier for this API | |
| source | Yes | URL or file path to the OpenAPI/Swagger specification |
Implementation Reference
- src/index.ts:199-230 (handler)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 }; } }
- src/index.ts:195-198 (schema)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 }; } } );