MCP ExplorerExplorer

Openapi Mcp Codegen

@cnoe-ioon 9 months ago
3 Apache-2.0
FreeCommunity
AI Systems
#codegen#mcp#openapi
OpenAPI MCP Code Generator

Overview

What is Openapi Mcp Codegen

openapi-mcp-codegen is a tool designed to easily generate a Model Context Protocol (MCP) server from any OpenAPI specification, enabling developers to bootstrap new MCP servers for APIs.

Use cases

Use cases include generating server code for RESTful APIs, creating prototypes for API services, and facilitating rapid development of API-driven applications.

How to use

To use openapi-mcp-codegen, place your OpenAPI specification file (in JSON or YAML format) in the project directory and run the command ‘make generate’ with the appropriate parameters to generate the MCP server code.

Key features

Key features include automatic MCP server generation from OpenAPI specs, support for JSON and YAML formats, auto-detection of spec file types, tool modules for API endpoints, API client code generation, logging and error handling setup, configuration files, and comprehensive documentation generation.

Where to use

openapi-mcp-codegen can be used in software development projects where APIs are defined using OpenAPI specifications, particularly in environments that utilize the Model Context Protocol.

Content

🚀 OpenAPI to MCP Server Code Generator

Python
Poetry
License

Conventional Commits
Ruff Linter
Super Linter
Unit Tests
Dependabot Updates


Easily generate a Model Context Protocol (MCP) server from any OpenAPI specification!

This tool helps you bootstrap new MCP servers for any API with an OpenAPI spec.


✨ Features

  • Automatic MCP server generation from OpenAPI specs
  • 📝 Supports JSON and YAML formats
  • 🔍 Auto-detects spec file type (.json, .yaml, .yml)
  • 🛠️ Tool modules for each API endpoint
  • 🤖 API client code generation
  • 📋 Logging & error handling setup
  • ⚙️ Configuration files (pyproject.toml, .env.example)
  • 📚 Comprehensive documentation generation

📦 Requirements

  • 🐍 Python 3.8+
  • uv and uvx (recommended)
  • 🧪 Optional: Poetry for local development

⚡ Quick Start with uvx (Recommended)

No install required — just run the generator directly from GitHub:

uvx https://github.com/cnoe-io/openapi-mcp-codegen.git -- generate \
  --spec-file examples/openapi_petstore.json \
  --output-dir examples/mcp_petstore \
  --enhance-docstring-with-llm-openapi

📌 Optional: Pin a release tag

uvx https://github.com/cnoe-io/[email protected] -- generate \
  --spec-file examples/openapi_petstore.json \
  --output-dir examples/mcp_petstore

🧑‍💻 Local Development

Prefer to run locally or contribute?

1. Clone the repo:

git clone https://github.com/cnoe-io/openapi-mcp-codegen
cd openapi-mcp-codegen

2. Install dependencies with Poetry:

poetry install

3. Run the generator:

  • The generator will create code in a new directory called mcp_<server-name> or the directory you specify.
  • Follow the setup instructions printed by the generator.

Option 1:

make generate -- --spec-file examples/openapi_petstore.json --output-dir examples/mcp_petstore

Option 2:

poetry run generate --spec-file examples/openapi_petstore.json --output-dir examples/mcp_petstore

🗂️ Generated MCP Server Structure

mcp_petstore/
├── mcp_petstore/
│   ├── __init__.py
│   ├── api/
│   │   ├── __init__.py
│   │   └── client.py
│   ├── models/
│   │   ├── __init__.py
│   │   └── [models].py
│   ├── server.py
│   ├── tools/
│   │   ├── __init__.py
│   │   └── [tools].py
│   └── utils/
│       └── __init__.py
├── poetry.lock
├── pyproject.toml
└── README.md

🛠️ Customization

  • ✏️ Modify generated tool modules in tools/
  • 🧩 Add custom models in models/
  • 🔌 Extend the API client in api/client.py
  • 🛠️ Add utility functions in utils/

👥 Maintainers

See MAINTAINERS.md


🤝 Contributing

See CONTRIBUTING.md


📄 License

Apache 2.0


🔒 Security

If you discover a security vulnerability, please see our SECURITY.md for responsible disclosure guidelines.


🧑‍💼 Code of Conduct

This project follows the Contributor Covenant Code of Conduct.


🙏 Acknowledgements

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers