MCP HubMCP Hub
harsha-iiiv

openapi-mcp-generator

by: harsha-iiiv

A tool that converts OpenAPI specifications to MCP server

19created 09/03/2025
Visit
OpenAPI
converter

πŸ“ŒOverview

Purpose: To generate Model Context Protocol (MCP) server code from OpenAPI specifications, facilitating seamless integration between Large Language Models and APIs.

Overview: The OpenAPI to MCP Generator is a command-line tool designed to automate the creation of MCP server code. By converting OpenAPI specifications into fully functional MCP servers, it streamlines the development process and enhances the interoperability of APIs with LLMs.

Key Features:

  • Automatic Tool Generation: Effortlessly translates each API endpoint from an OpenAPI specification into corresponding MCP tools, minimizing manual coding efforts.

  • Multiple Transport Options: Offers flexibility in communication methods, supporting stdio, WebSocket, and HTTP, which allows for a wide range of application scenarios.

  • Complete Project Setup: Automatically generates all essential files needed to run an MCP server, providing a ready-to-deploy environment.

  • TypeScript Support: Includes TypeScript definitions, ensuring type safety and developer familiarity.

  • Easy Configuration: Simplifies server setup through environment-based configuration, making it user-friendly for developers.


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 either standard input/output or HTTP-based transport.


✨ 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.
  • πŸ’¬ Stdio & Web Transport: Communicate over stdio or HTTP (beta, SSE support).
  • 🧰 Project Scaffold: Generates a complete Node.js project with tsconfig.json, package.json, and entry point.
  • πŸ§ͺ Built-in HTML Test Client (Web mode): Test API interactions visually in your browser.

πŸš€ Installation

npm install -g openapi-mcp-generator

You can also use yarn global add openapi-mcp-generator or pnpm add -g openapi-mcp-generator


πŸ›  Usage

# Generate an MCP server (stdio)
openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir

# Generate an MCP web server (beta)
openapi-mcp-generator --input path/to/openapi.json --output path/to/output/dir --transport=web --port=3000

CLI Options

OptionAliasDescriptionDefault
--input-iPath or URL to OpenAPI specification (YAML or JSON)Required
--output-oDirectory to output the generated MCP projectRequired
--server-name-nName of the MCP server (package.json:name)OpenAPI title or mcp-api-server
--server-version-vVersion of the MCP server (package.json:version)OpenAPI version or 1.0.0
--base-url-bBase URL for API requests. Required if OpenAPI servers missing or ambiguous.Auto-detected if possible
--transport-tTransport mode: "stdio" (default) or "web" (beta)"stdio"
--port-pPort for web server mode3000
--forceOverwrite existing files in the output directory without confirmationfalse

🧱 Project Structure

The generated project includes:

<output_directory>/
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── src/
    └── index.ts
  • Uses axios, zod, @modelcontextprotocol/sdk, and json-schema-to-zod.
  • Secure API key/tokens via environment variables.
  • Tool generation for each endpoint.

πŸ“‘ Transport Modes

Stdio (Default)

Communicates with MCP clients via standard input/output. Ideal for local development or integration with LLM tools.

Web Server Mode (Beta)

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

⚠️ Note: Web mode is experimental and may have breaking changes in future updates.


πŸ” Environment Variables for Authentication

Configure auth credentials in your environment:

Auth TypeVariable Format
API KeyAPI_KEY_<SCHEME_NAME>
BearerBEARER_TOKEN_<SCHEME_NAME>
Basic AuthBASIC_USERNAME_<SCHEME_NAME>, BASIC_PASSWORD_<SCHEME_NAME>
OAuth2OAUTH_CLIENT_ID_<SCHEME_NAME>, OAUTH_CLIENT_SECRET_<SCHEME_NAME>, OAUTH_SCOPES_<SCHEME_NAME>

▢️ Running the Generated Server

cd path/to/output/dir
npm install

# Run in stdio mode
npm start

# Run in web server mode (if generated with --transport=web)
npm run start:web

⚠️ Requirements

  • Node.js v18 or later

🀝 Contributing

Contributions are welcome!

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m "Add amazing feature"
  4. Push and open a PR

πŸ“Œ Repository: github.com/harsha-iiiv/openapi-mcp-generator


πŸ“„ License

MIT License β€” see LICENSE for full details.