OpenAPI to MCP Generator logo

OpenAPI to MCP Generator

by LostInBrittany

This project converts OpenAPI/Swagger specifications into Model Context Protocol (MCP) servers, enabling LLMs to interact with REST APIs through standardized tools. It allows LLMs to discover and use tools without being tied to specific implementations.

View on GitHub

Last updated: N/A

What is OpenAPI to MCP Generator?

The OpenAPI to MCP Generator is a tool that automatically converts OpenAPI/Swagger specifications into functional Model Context Protocol (MCP) servers. This allows Large Language Models (LLMs) to interact with any REST API using a standardized protocol.

How to use OpenAPI to MCP Generator?

To use the generator, run the SwaggerToMcpGenerator.java script with the path to your OpenAPI/Swagger JSON or YAML file and the desired name for the generated MCP server file. You can specify server index or URL to select which server to use from the OpenAPI specification. The generated Java file can then be run using jbang.

Key features of OpenAPI to MCP Generator

  • 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)

Use cases of OpenAPI to MCP Generator

  • Exposing REST APIs to LLMs for automated interaction

  • Creating standardized interfaces for LLMs to access various services

  • Building tools that can be easily discovered and used by LLMs

  • Simplifying the integration of REST APIs into LLM-powered applications

FAQ from OpenAPI to MCP Generator

What is MCP?

The Model Context Protocol (MCP) is a standardized way for tools and LLMs to communicate, allowing tools to expose their functionality to any MCP-compatible LLM.

What authentication methods are supported?

The generator supports API keys, Bearer tokens, and Basic authentication, configurable through environment variables.

How do I select a specific server from the OpenAPI specification?

You can select a server by specifying its index (0-based) or URL using the --server-index or --server-url options when running the generator.

What HTTP methods are supported?

The generator supports GET, POST, PUT, DELETE, and PATCH methods.

How are parameters handled?

Path parameters are incorporated into the URL, query parameters are added to the URL builder, and request bodies are properly formatted and attached to the request.