Developers can programmatically integrate the functionality of openapi-mcp-server with the following main steps:
- Import Module: Introducing Converters in Node.js Projects
import { OpenAPIToMCPConverter } from 'openapi-mcp-server' ; - Converting API Formats: Create an instance of the converter and convert to the desired format
const converter = new OpenAPIToMCPConverter(openApiSpec); // openApiSpec is OpenAPI JSON data
const openAiTools = await converter.convertToOpenAITools(); // convert to OpenAI format
const mcpTools = converter.convertToMCPTools(); // convert to MCP format - Executing API Calls: Using HttpClient for specific operations
import { HttpClient } from 'openapi-mcp-server' ;
const httpClient = new HttpClient({ baseUrl: 'https://api.example.com' }, openApiSpec);
const response = await httpClient.executeOperation(mcpTools.openApiLookup['getPetById'], { petId: 123 });
This approach is particularly suitable for scenarios where APIs need to be integrated into existing projects or automated workflows, where developers have the flexibility to programmatically control the transformation process and use the transformed API resources.
This answer comes from the articleopenapi-mcp-server: letting AI directly invoke MCP services with open APIsThe