openapi2mcp

by VitalyMalakanov

180 downloads
Not rated
GitHub

About

**Automatically generate FAST Model-Context-Protocol (MCP) servers from OpenAPI/Swagger specs.**

Details

Author
VitalyMalakanov
Downloads
180
Categories
Other

- Generates FastMCP server code from OpenAPI 3.x specs.
- Supports stdio and Google Pub/Sub transports.
- Mount path customization for server resources.
- Automatic generation of llms.txt for LLM tool descriptions.
- Built-in code validation with the check command.
- Simple CLI with three commands: generate, check, version.

Install via poetry install. Then use the openapi2mcp generate command to create a Python MCP server from a JSON or YAML OpenAPI spec, specifying input, output, transport (stdio or google_pubsub), an optional resource mount path, and an optional llms.txt file. Validate the generated code with openapi2mcp check and display the version with openapi2mcp version.

openapi2mcp

A tool to convert OpenAPI 3.x specifications to FastMCP servers.

Installation

poetry install

Usage / Commands

openapi2mcp provides a command-line interface to generate and manage MCP server code from OpenAPI specifications.

generate

Generates the MCP server Python code from an OpenAPI specification file.

Syntax:

openapi2mcp generate [OPTIONS]

Options:

-i, --input-file PATH: Path to the OpenAPI specification file (JSON or YAML). (Required)
-o, --output-file PATH: Path to the output Python file for the generated MCP server. (Required)
-t, --transport [stdio|google_pubsub]: The transport mechanism for the MCP server. (Default: stdio)
--llms-txt-file PATH: Optional path to generate an llms.txt file, which provides a description of the generated tools and resources for language models. If not specified, llms.txt will be created in the same directory as the output server file.
--mount TEXT: Optional mount path for resources (e.g., /myapi/v1). (Default: "")

Example:

openapi2mcp generate --input-file examples/example_openapi.yaml --output-file generated_server.py --transport stdio --mount "/api"

This command will parse examples/example_openapi.yaml, generate an MCP server file named generated_server.py using the stdio transport, and set the resource mount path to /api. It will also generate an llms.txt file in the same directory as generated_server.py.

check

Checks a generated MCP server Python file for basic code validity, including syntax and presence of key MCP patterns.

Syntax:

openapi2mcp check --server-file PATH

Options:

--server-file PATH: Path to the generated MCP server Python file to check. (Required)

Example:

openapi2mcp check --server-file generated_server.py

version

Displays the version of the openapi2mcp tool.

Syntax:

openapi2mcp version

Example:

openapi2mcp version

Examples

See example implementations:
- HTTP Server
- SSE Server
- STDIO Server
- Sample OpenAPI spec

Project Structure

- openapi2mcp/parser.py: OpenAPI specification parser
- openapi2mcp/generator.py: FastMCP server code generator
- openapi2mcp/cli.py: Command-line interface

License

MIT - See LICENSE

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.