OpenAPI to MCP Generator

by LostInBrittany

21 stars
256 downloads
Not rated
GitHub

About

A Java program that generates a Quarkus MCP server form an Open API Swagger file

Details

Author
LostInBrittany
GitHub stars
21
Downloads
256
Categories
Developer Tools

- Parses OpenAPI specification files and converts endpoints to MCP tools.
- Supports GET, POST, PUT, DELETE, and PATCH methods.
- Handles path parameters, query parameters, and request bodies.
- Provides API Key, Bearer Token, and Basic authentication support.
- Formats JSON responses and includes robust error handling.
- Allows runtime server selection when multiple servers are defined.

Use jbang SwaggerToMcpGenerator.java path/to/swagger.json GeneratedMcpServer to generate a server, then jbang GeneratedMcpServer.java to run it. Authentication is configured via environment variables such as API_KEY, BEARER_TOKEN, or API_USERNAME/API_PASSWORD.

OpenAPI to MCP Generator

This project provides a powerful tool for automatically converting OpenAPI/Swagger specifications into Model Context Protocol (MCP) servers, allowing LLMs to interact with any REST API through standardized tools.

Components

SwaggerToMcpGenerator.java

A comprehensive utility that converts any OpenAPI/Swagger specification into a fully functional MCP server:
- Parses OpenAPI specification files
- Converts API endpoints to MCP tools
- Handles path parameters, query parameters, and request bodies
- Supports multiple HTTP methods (GET, POST, PUT, DELETE, PATCH)
- Provides authentication support (API keys, Bearer tokens, Basic auth)
- Formats JSON responses for readability
- Generates robust error handling
- Includes parameter documentation with valid values and defaults

Generating an MCP Server from OpenAPI

To generate an MCP server from any OpenAPI specification:

jbang SwaggerToMcpGenerator.java path/to/swagger.json GeneratedMcpServer [options]

Parameters:
- path/to/swagger.json: Path to the OpenAPI/Swagger specification file
- GeneratedMcpServer: Name of the output Java file (without .java extension)

Options:
- --server-index <index>: Index of the server to use from the OpenAPI specification (0-based)
- --server-url <url>: URL of the server to use (overrides server-index)

This will create a new file GeneratedMcpServer.java that implements an MCP server with tools for each API endpoint defined in the swagger file. The generator will emit a warning if multiple servers are defined in the OpenAPI specification and none is explicitly selected.

Running the Generated MCP Server

To run the generated MCP server:

jbang GeneratedMcpServer.java

Server Selection

The generated MCP server includes constants for all servers defined in the OpenAPI specification, allowing you to choose which server to use at runtime. By default, the first server in the list is used, but you can select a specific server using environment variables:

```bash

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.