AI Personal Learning
and practical guidance
豆包Marscode1

openapi-mcp-server: letting AI directly invoke MCP services with open APIs

General Introduction

openapi-mcp-server is an open source tool designed to transform OpenAPI v3.1 compliant APIs into AI usable resources. It is maintained by janwilmake and developed based on the Model Context Protocol (MCP) protocol. The core functionality of the project is to act as an API proxy, allowing developers to use the Claude Tools such as Desktop interact directly with the API. This tool is especially suited for developers and AI engineers who need to integrate APIs quickly. It's designed to be simple and straightforward, open-sourced on GitHub, and free for anyone to use or contribute code.

openapi-mcp-server:让AI直接调用开放API的MCP服务-1


 

Function List

  • API to MCP proxy: Converts OpenAPI-specified endpoints into tools available to Claude.
  • Supports multiple formats: APIs can be converted to OpenAI, Anthropic, or MCP Tool format.
  • command-line operation: Provides CLI tools to facilitate programmatic calls to the API.
  • sample server: Built-in Petstore API examples to help users get started quickly.
  • Open source and free: The code is publicly available and can be freely modified and expanded by the user.

 

Using Help

openapi-mcp-server doesn't require a complicated installation, you can get the source code directly from GitHub and run it. Here are the detailed steps.

Installation and operation

  1. Preparing the environment
    Make sure you have Node.js and pnpm installed on your computer (recommended). This can be checked with the command:
node -v
pnpm -v

If not, visit https://nodejs.org cap (a poem) https://pnpm.io Download and install.
2. clone warehouse
Open a terminal and type:

git clone https://github.com/janwilmake/openapi-mcp-server.git
cd openapi-mcp-server
  1. Installation of dependencies
    Run in the project directory:
pnpm install
  1. Build the project
    Build the code to ensure proper operation:
pnpm build
  1. Linking global commands
    Make command line tools available:
npm link

Configuring Claude Desktop

  1. Edit Configuration File
    Find the configuration file for Claude Desktop, usually in:
  • Windows. %AppData%\Claude\claude_desktop_config.json
  • Mac. ~/Library/Application Support/Claude/claude_desktop_config.json
    If not, create a new file.
  1. Adding an MCP Server
    Add the following to the configuration file:
{
"mcpServers": {
"petstore-api": {
"command": "npx",
"args": ["openapi-mcp-server", "/path/to/petstore-openapi.json"]
}
}
}

commander-in-chief (military) /path/to/petstore-openapi.json Replace it with the path to your OpenAPI file, e.g. the project examples/petstore-openapi.jsonThe
3. Start Claude Desktop
Run Claude Desktop and it will automatically load this server.

Calling the API with the CLI

  1. Preparing the OpenAPI file
    Make sure you have the OpenAPI v3.1 JSON file for the target API, for example petstore-openapi.jsonThe
  2. Run command
    Enter it in the terminal:
npx openapi-mcp-server /path/to/your-openapi.json

This will start a proxy server.
3. Test Petstore Example
The project comes with a Petstore API example. Run it:

npx openapi-mcp-server examples/petstore-openapi.json

Then interact with it in Claude Desktop, for example by typing "get pet by ID".

Programmatic Conversion API

  1. Import Module
    In your Node.js project, add the code:
import { OpenAPIToMCPConverter } from 'openapi-mcp-server';
  1. Conversion API
    Use the following code to convert OpenAPI to tool format:
const converter = new OpenAPIToMCPConverter(openApiSpec); // openApiSpec 是你的 JSON 数据
const openAiTools = await converter.convertToOpenAITools(); // 转为 OpenAI 格式
const mcpTools = converter.convertToMCPTools(); // 转为 MCP 格式
  1. invoke an API
    Use HttpClient to execute the request:
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 });

operation suggestion

  • Debugging Issues: If Claude crashes, check if the OpenAPI file is normalized by using the https://editor.swagger.io Validation.
  • Update Code: After modifying the code, run pnpm build and restart Claude Desktop.
  • Learning Examples: View examples/README.mdTo understand the CRUD operations of the Petstore server, you need to know how to use the Petstore server.

 

application scenario

  1. Fast API Integration
    A developer wants to add pet management functionality to his project. He loads the Petstore API with openapi-mcp-server and tests the endpoints directly in Claude, saving him the time of writing code manually.
  2. AI-assisted development
    The AI engineer needs to generate the API call code. He converts the OpenAPI file with a tool and generates the full request code with Claude.
  3. Teaching Demonstration
    The teacher uses the Petstore example to show students how to plug APIs into AI tools and learn about API interactions.

 

QA

  1. Do I have to pay for it?
    No need, the project is completely open source and free, hosted on GitHub.
  2. What APIs are supported?
    Any API that is part of the OpenAPI v3.1 specification is fine, such as GitHub, Cloudflare, etc.
  3. What if Claude doesn't recognize it?
    Check that the configuration file path and OpenAPI file are correct and make sure the server is up.
May not be reproduced without permission:Chief AI Sharing Circle " openapi-mcp-server: letting AI directly invoke MCP services with open APIs
en_USEnglish