
OpenAPI to MCP Generator (openapi-mcp-generator)
Generate Model Context Protocol (MCP) servers from OpenAPI specifications.
This CLI tool automates the generation of MCP-compatible servers that proxy requests to existing REST APIsβenabling AI agents and other MCP clients to seamlessly interact with your APIs using your choice of transport methods.
β¨ Features
π§ OpenAPI 3.0 Support: Converts any OpenAPI 3.0+ spec into an MCP-compatible server.
π Proxy Behavior: Proxies calls to your original REST API while validating request structure and security.
π Authentication Support: API keys, Bearer tokens, Basic auth, and OAuth2 supported via environment variables.
π§ͺ Zod Validation: Automatically generates Zod schemas from OpenAPI definitions for runtime input validation.
βοΈ Typed Server: Fully typed, maintainable TypeScript code output.
π Multiple Transports: Communicate over stdio, SSE via Hono, or StreamableHTTP.
π§° Project Scaffold: Generates a complete Node.js project with
tsconfig.json, package.json, and entry point.π§ͺ Built-in HTML Test Clients: Test API interactions visually in your browser (for web-based transports).
π Installation
You can also use
yarn global add openapi-mcp-generator or pnpm add -g openapi-mcp-generatorπ Usage
CLI Options
Option Alias Description Default
--input -i Path or URL to OpenAPI specification (YAML or JSON) Required --output -o Directory to output the generated MCP project Required --server-name -n Name of the MCP server (package.json:name) OpenAPI title or mcp-api-server --server-version -v Version of the MCP server (package.json:version) OpenAPI version or 1.0.0 --base-url -b Base URL for API requests. Required if OpenAPI servers missing or ambiguous. Auto-detected if possible --transport -t Transport mode: "stdio" (default), "web", or "streamable-http" "stdio" --port -p Port for web-based transports 3000 --force Overwrite existing files in the output directory without confirmation falseπ¦ Programmatic API
You can also use this package programmatically in your Node.js applications:
For full documentation of the programmatic API, see PROGRAMMATIC_API.md.
π§± Project Structure
The generated project includes:
Core dependencies:
@modelcontextprotocol/sdk - MCP protocol implementationaxios - HTTP client for API requestszod - Runtime validationjson-schema-to-zod - Convert JSON Schema to ZodTransport-specific deps (Hono, uuid, etc.)
π‘ Transport Modes
Stdio (Default)
Communicates with MCP clients via standard input/output. Ideal for local development or integration with LLM tools.
Web Server with SSE
Launches a fully functional HTTP server with:
Server-Sent Events (SSE) for bidirectional messaging
REST endpoint for client β server communication
In-browser test client UI
Multi-connection support
Built with lightweight Hono framework
StreamableHTTP
Implements the MCP StreamableHTTP transport which offers:
Stateful JSON-RPC over HTTP POST requests
Session management using HTTP headers
Proper HTTP response status codes
Built-in error handling
Compatibility with MCP StreamableHTTPClientTransport
In-browser test client UI
Built with lightweight Hono framework
Transport Comparison
Feature stdio web (SSE) streamable-http Protocol JSON-RPC over stdio JSON-RPC over SSE JSON-RPC over HTTP Connection Persistent Persistent Request/response Bidirectional Yes Yes Yes (stateful) Multiple clients No Yes Yes Browser compatible No Yes Yes Firewall friendly No Yes Yes Load balancing No Limited Yes Status codes No Limited Full HTTP codes Headers No Limited Full HTTP headers Test client No Yes Yes
π Environment Variables for Authentication
Configure auth credentials in your environment:
Auth Type Variable Format API Key
API_KEY_<SCHEME_NAME> Bearer BEARER_TOKEN_<SCHEME_NAME> Basic Auth BASIC_USERNAME_<SCHEME_NAME>, BASIC_PASSWORD_<SCHEME_NAME> OAuth2 OAUTH_CLIENT_ID_<SCHEME_NAME>, OAUTH_CLIENT_SECRET_<SCHEME_NAME>, OAUTH_SCOPES_<SCHEME_NAME>βΆοΈ Running the Generated Server
Testing Web-Based Servers
For web and StreamableHTTP transports, a browser-based test client is automatically generated:
Start the server using the appropriate command
Open your browser to
http://localhost:<port>Use the test client to interact with your MCP server
β οΈ Requirements
Node.js v20 or later
Star History
π€ Contributing
Contributions are welcome!
Fork the repo
Create a feature branch:
git checkout -b feature/amazing-featureCommit your changes:
git commit -m "Add amazing feature"Push and open a PR
π Repository: github.com/harsha-iiiv/openapi-mcp-generator
π License
MIT License β see LICENSE for full details.
0 likes Β· 6 views Β· May 25, 2025
The openapi-mcp-generator, which generates MCP servers from OpenAPI specifications, has surpassed 1,000 downloads and 6,000 views.