rmcp-openapi
Expose OpenAPI definition endpoints as MCP tools using the official Rust SDK for the Model Context Protocol.
Overview
This project provides a bridge between OpenAPI specifications and the Model Context Protocol (MCP), allowing you to automatically generate MCP tools from OpenAPI definitions. This enables AI assistants to interact with REST APIs through a standardized interface.
Features
- Automatic Tool Generation: Parse OpenAPI specifications and automatically generate MCP tools for all operations
- Flexible Spec Loading: Support for both URL-based and local file OpenAPI specifications
- HTTP Client Integration: Built-in HTTP client with configurable base URLs and request handling
- Parameter Mapping: Intelligent mapping of OpenAPI parameters (path, query, body) to MCP tool parameters
- Dual Usage Modes: Use as a standalone MCP server or integrate as a Rust library
- Transport Support: SSE (Server-Sent Events) transport for MCP communication
- Comprehensive Testing: Includes integration tests with JavaScript and Python MCP clients
- Built with Official SDK: Uses the official Rust MCP SDK for reliable protocol compliance
Installation
Install Binary
Build from Source
As a Library
Add to your Cargo.toml:
[]
= "0.1.0"
Usage as a Library
Basic Example
use ;
use Url;
async
Advanced Example with Custom Base URL
use ;
use Url;
async
Usage as an MCP Server
Basic Usage
# Basic usage with Petstore API
# See all available options
MCP Client Connection
The server exposes an SSE endpoint for MCP clients:
http://localhost:8080/sse
Example with Claude Desktop
Add to your Claude Desktop MCP configuration:
Example with JavaScript MCP Client
import from '@modelcontextprotocol/sdk/client/index.js';
import from '@modelcontextprotocol/sdk/client/sse.js';
const client = ;
const transport = ;
await client.;
// List available tools
const tools = await client.;
console.log;
// Call a tool
const result = await client.;
Generated Tools
The server automatically generates MCP tools for each OpenAPI operation:
- Tool Names: Uses
operationIdor generates from HTTP method + path - Parameters: Maps OpenAPI parameters (path, query, body) to tool parameters
- Descriptions: Combines OpenAPI
summaryanddescriptionfields - Validation: Includes parameter schemas for validation
Example generated tools for Petstore API:
addPet: Add a new pet to the storefindPetsByStatus: Find pets by statusgetPetById: Find pet by IDupdatePet: Update an existing petdeletePet: Delete a pet
Examples
See the examples/ directory for usage examples:
petstore.sh: Demonstrates server usage with the Swagger Petstore API
Testing
# Run all tests
# Run with live API testing
RMCP_TEST_LIVE_API=true
# Run specific integration tests
License
MIT License - see LICENSE file for details.