1.0.4 • Published 4 months ago
openapi-mcp-generator v1.0.4
OpenAPI to MCP Generator
A command-line tool that generates Model Context Protocol (MCP) server code from OpenAPI specifications. This tool helps you quickly create an MCP server that acts as a bridge between LLMs (Large Language Models) and your API.
Features
- Automatic Tool Generation: Converts each API endpoint in your OpenAPI spec into an MCP tool
- Multiple Transport Options: Supports stdio, WebSocket, and HTTP transport methods
- Complete Project Setup: Generates all necessary files to run an MCP server
- TypeScript Support: Includes TypeScript definitions and configuration
- Easy Configuration: Simple environment-based configuration for the generated server
Installation
# Install globally from npm
npm install -g openapi-mcp-generator
# Or with yarn
yarn global add openapi-mcp-generator
# Or with pnpm
pnpm add -g openapi-mcp-generator
Usage
Generate an MCP server from an OpenAPI specification:
openapi-mcp-generator --openapi path/to/openapi.json --output /Path/to/output
Command Line Options
Option | Alias | Description | Default |
---|---|---|---|
--openapi | -o | Path or URL to OpenAPI specification | (required) |
--output | -d | Output directory for generated files | ./mcp-server |
--name | -n | Name for the MCP server | openapi-mcp-server |
--version | -v | Version for the MCP server | 1.0.0 |
--transport | -t | Transport mechanism (stdio, websocket, http) | stdio |
--port | -p | Port for websocket or HTTP server | 3000 |
--help | -h | Show help information |
Examples
Generate from a local OpenAPI file:
openapi-mcp-generator --openapi ./specs/petstore.json --output ./petstore-mcp
Generate from a remote OpenAPI URL:
openapi-mcp-generator --openapi https://petstore3.swagger.io/api/v3/openapi.json --output ./petstore-mcp
Specify a WebSocket transport:
openapi-mcp-generator --openapi ./specs/petstore.json --transport websocket --port 8080
Generated Files
The tool generates the following files in the output directory:
server.js
- The main MCP server implementationpackage.json
- Dependencies and scriptsREADME.md
- Documentation for the generated server.env.example
- Template for environment variablestypes.d.ts
- TypeScript type definitions for the APItsconfig.json
- TypeScript configuration
Using the Generated Server
After generating your MCP server:
Navigate to the generated directory:
cd my-mcp-server
Install dependencies:
npm install
Create an environment file:
cp .env.example .env
Edit
.env
to set your API base URL and any required headers:API_BASE_URL=https://api.example.com API_HEADERS=Authorization:Bearer your-token-here
Start the server:
npm start
Requirements
- Node.js 16.x or higher
- npm 7.x or higher
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
MIT