A Go tool for converting OpenAPI specifications into MCP tools.
简体中文
openapi-to-mcp
is a Go implementation for converting OpenAPI specifications into MCP (Model Context Protocol) tools.
This project aims to provide a flexible framework that allows developers to automatically expose existing OpenAPI interfaces as MCP tools through simple configuration, enabling AI models to call these interfaces directly.
stdio
(Standard I/O), sse
(Server-Sent Events), and stream
(HTTP Stream) as transport protocols for MCP communication..env
file or system environment variables.You can install openapi-to-mcp
in two ways.
go install
(Recommended)The easiest way to install and run the tool is using go install
. After installation, the openapi-to-mcp
command will be available in your shell.
go install github.com/constellation39/openapi-to-mcp@latest
If you want to modify the code or contribute, clone the repository and build the project.
git clone https://github.com/constellation39/openapi-to-mcp cd openapi-to-mcp go build .
Follow these steps to configure and run the tool.
Create a .env
file in the project's root directory or set the following environment variables in your system. You can start by copying the example file:
copy .env.example .env
cp .env.example .env
Then, edit the .env
file with your desired configuration:
MCP_TRANSPORT="stdio"
MCP_BASE_URL="http://localhost:8080"
OPENAPI_SRC="./example/openapi.yaml"
OPENAPI_BASE_URL=
EXTRA_HEADERS='{"X-API-Key": "your-api-key"}'
USE_COOKIE=true
LOG_OUTPUT=false
RATE_LIMIT_PER_SECOND=1
AUTHORIZATION_HEADERS="Basic xxxx"
Execute the application from your terminal.
If you installed using go install
:
openapi-to-mcp
If you built from source:
./openapi-to-mcp
For development, you can also run directly using go run
:
go run main.go
Configure your MCP client to connect to openapi-to-mcp
based on the MCP_TRANSPORT
you've chosen.
- Stdio Mode (Default): If MCP_TRANSPORT
is stdio
, configure your client to execute the command directly. The env
block can be used to pass or override environment variables.
{ "mcpServers": { "openapi-to-mcp": { "command": "openapi-to-mcp", "env": { "MCP_BASE_URL": "http://localhost:8080", "OPENAPI_SRC": "./example/openapi.yaml" } } } }
Note: If running from source, you might set "command"
to "./openapi-to-mcp"
or use go run main.go
.
- SSE Mode: If MCP_TRANSPORT
is sse
, the server will start on the MCP_BASE_URL
. Configure your client to connect to the /sse
endpoint.
{ "mcpServers": { "openapi-to-mcp": { "url": "http://localhost:8080/sse" } } }
- Stream Mode: If MCP_TRANSPORT
is stream
, the server will start on the MCP_BASE_URL
. Configure your client to connect to the /stream
endpoint.
{ "mcpServers": { "openapi-to-mcp": { "url": "http://localhost:8080/stream" } } }
Please ensure http://localhost:8080
matches the MCPBASEURL
in your configuration.
.github/
core/
├── openapi.go # OpenAPI specification parsing and tool generation logic
├── session/ # Session management
├── middleware.go # MCP middleware definitions
└── utils.go # Common utility functions
example/
├── openapi.yaml # Example OpenAPI specification file
main.go # Main application entry point
README.md
README_zh.md
go.mod
go.sum
Contributions are welcome! Feel free to submit a Pull Request or report an Issue.
This project is released under the MIT License.
Provides developers with continuous, project-centric context awareness. Requires a TursoDB database.
iOS Swift Package Manager server written in Swift
A collection of reference implementations for Model Context Protocol (MCP) servers in Typescript and Python, demonstrating MCP features and SDK usage.
Bridges AI coding assistants with Neovim's Language Server Protocol for AI-powered code intelligence and navigation.
Query A/B test data using the Hackle API.
A collection of reference server implementations for the Model Context Protocol (MCP) using Typescript and Python SDKs.
A collection of MCP servers designed for rapid prototyping in CS experimentation workshops.
Provides tools for geospatial analysis within Jupyter notebooks.
MCP server for secure command-line interactions on Windows systems, enabling controlled access to PowerShell, CMD, and Git Bash shells.
An intelligent scientific reasoning framework that uses graph structures and Neo4j to perform advanced reasoning via the Model Context Protocol (MCP).