Openapi MCP Generator
MCP server: Openapi MCP Generator
Installation
npx openapi-mcp-generatorAsk AI about Openapi MCP Generator
Powered by Claude Β· Grounded in docs
I know everything about Openapi MCP Generator. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
OpenAPI-to-MCP Generator
Automatically generate Model Context Protocol (MCP) servers from OpenAPI 3.0 specifications, enabling AI agents to interact with any REST API.
β¨ Features
- β Full OpenAPI 3.0 Support - Parse and convert any valid OpenAPI 3.0 specification
- β Complete Type Generation - TypeScript interfaces for all schemas with JSDoc comments
- β Type Safety Excellence - 99.38% type coverage with CI enforcement (exceeds 95% industry standard)
- β Automatic Tool Creation - MCP tools for every API operation with parameter validation
- β Authentication Support - Built-in support for API Key, Bearer Token, OAuth 2.0, Basic Auth
- β Production Ready - Generated servers compile, run, and integrate with Claude Desktop
- β Fast Generation - Generate complete servers in seconds (<30s for 260KB specs)
- β Error Handling - Comprehensive validation with actionable error messages and rollback support
π Quick Start
Installation
# Install globally (recommended)
npm install -g @openapi-to-mcp/cli
# Or use with npx (no installation)
npx @openapi-to-mcp/cli generate swagger.json --output ./my-mcp-server
Generate MCP Server
# Generate from OpenAPI spec
@openapi-to-mcp/cli generate swagger.json --output ./my-mcp-server
# Example output from Ozon Performance API (260KB spec):
# β
Parsing OpenAPI spec... (260KB)
# β
Validated OpenAPI schema
# β
Resolved 45 $ref references
# β
Extracted 220 schemas
# β
Extracted 39 operations
# β
Extracted 3 security schemes
# β
Extracted 12 tags
# β
Extracted 1 server(s)
# β
Scaffolding project structure...
# β
Generating TypeScript interfaces... (220 types)
# β
Generating MCP tool definitions... (39 tools)
# β
Generating server files...
# β
MCP server generated successfully at ./my-mcp-server
# Build and run
cd my-mcp-server
npm install
npm run build
node dist/index.js
Use with Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"my-api": {
"command": "node",
"args": ["/absolute/path/to/my-mcp-server/dist/index.js"],
"env": {
"API_KEY": "your-api-key-here"
}
}
}
}
Restart Claude Desktop and your API tools will be available!
π Example Output
From the Ozon Performance API OpenAPI specification (260KB):
my-mcp-server/
βββ package.json # Dependencies: @modelcontextprotocol/sdk, axios, zod
βββ tsconfig.json # TypeScript config: ES2022, ESM, strict mode
βββ README.md # Generated usage instructions
βββ .env.example # Environment variables template
βββ src/
βββ index.ts # MCP server entry point (39 tools registered)
βββ types.ts # 220 TypeScript interfaces with JSDoc
βββ tools.ts # 39 MCP tool definitions
βββ http-client.ts # HTTP client with authentication
Generated Tools (39 total):
postBotsSendMessage- Send messages via botpostPerformanceReports- Get performance analyticspostProductsInfo- Retrieve product informationpostV1ActionsProducts- Manage product actions- And 35 more...
Generated Types (220+ interfaces):
BotSendMessageRequest,BotSendMessageResponsePerformanceReportRequest,PerformanceDataProductInfoRequest,ProductDetails- And 217 more...
π Documentation
| Document | Description |
|---|---|
| Quick Start Tutorial | Generate your first MCP server in 5 minutes |
| Generation Pipeline | Architecture and data flow |
| Troubleshooting Guide | Common issues and solutions |
| Project Brief | Project overview, goals, and scope |
| Architecture | System design and algorithms |
| API Reference | Complete API documentation |
| Examples | Usage examples and recipes |
| Testing Guide | Testing strategy and test cases |
π― Use Cases
1. E-Commerce APIs (Ozon, Amazon, Shopify)
# Generate MCP server for Ozon Performance API
openapi-to-mcp generate ./ozon-swagger.json \
-o ./ozon-mcp \
-n ozon-performance-api
# AI agent can now:
# - List advertising campaigns
# - Get campaign statistics
# - Update campaign budgets
# - Manage products and ads
2. Developer Tools (GitHub, GitLab, Jira)
# Generate GitHub API MCP server
openapi-to-mcp generate https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json \
-f "repos,issues,pulls" \
-o ./github-mcp
# AI agent can now:
# - Create issues and pull requests
# - Manage repositories
# - Review code
3. Payment Processing (Stripe, PayPal)
# Generate Stripe API MCP server
openapi-to-mcp generate ./stripe-openapi.json \
-f "Customers,PaymentIntents,Charges" \
-o ./stripe-mcp
# AI agent can now:
# - Create customers
# - Process payments
# - Manage subscriptions
4. Internal Company APIs
# Generate MCP server for internal API
openapi-to-mcp generate http://internal-api.company.local/openapi.json \
-o ./company-api-mcp
# AI agent can now:
# - Access internal tools
# - Automate workflows
# - Query business data
ποΈ Architecture
High-Level Overview
OpenAPI Spec β Parser β Generator β MCP Server
β β
$refs Types
Resolved Tools
Client
Component Structure
openapi-to-mcp/
βββ packages/
β βββ cli/ # Command-line interface
β βββ parser/ # OpenAPI parsing + $ref resolution
β βββ generator/ # Code generation (types, tools, client)
β βββ shared/ # Shared utilities and types
βββ examples/ # Example generated servers
βββ tests/ # Test suites
βββ docs/ # Documentation
Key Algorithms
$ref Resolution:
// Handles nested references with circular detection
function resolveRef(ref: string, spec: any): any {
// Parse: "#/components/schemas/Campaign"
// Traverse: spec.components.schemas.Campaign
// Detect circular: visited set tracking
// Return: resolved object
}
Tool Generation:
// Converts OpenAPI operation β MCP tool
function generateTool(path, method, operation): MCPTool {
name: operation.operationId || generated_name,
description: AI-optimized description,
inputSchema: parameters + requestBody,
metadata: { path, method, tags, category }
}
Smart Filtering:
// Tag-based categorization for AI context management
const categories = groupByTags(operations);
// Campaign: 15 methods
// Statistics: 12 methods
// Products: 18 methods
// β AI loads only relevant category
See Architecture Documentation for details.
π§ CLI Reference
generate
Generate MCP server from OpenAPI specification.
openapi-to-mcp generate <input> [options]
Options:
-o, --output <dir>- Output directory (default:./generated)-n, --name <name>- Package name override-f, --filter <tags>- Comma-separated tags to include--no-types- Skip TypeScript types generation--no-client- Skip HTTP client generation-v, --verbose- Verbose logging
Examples:
# Basic usage
openapi-to-mcp generate ./swagger.json
# Filter by tags
openapi-to-mcp generate ./api.json -f "Campaign,Statistics"
# Custom output and name
openapi-to-mcp generate ./spec.yaml -o ./my-server -n my-api
validate
Validate OpenAPI specification.
openapi-to-mcp validate <input> [options]
Options:
--strict- Enable strict validation-v, --verbose- Verbose output
Example:
openapi-to-mcp validate ./swagger.json
# Output:
# β Valid OpenAPI 3.0.0 specification
# β 39 paths found
# β 87 schemas found
# β 2 operations without operationId
init
Initialize new MCP server project.
openapi-to-mcp init <name> [options]
Options:
-t, --template <type>- Template type:basic|advanced-d, --directory <dir>- Target directory
π¦ Generated Output
File Structure
my-mcp-server/
βββ package.json # Package configuration
βββ tsconfig.json # TypeScript config
βββ README.md # Usage documentation
βββ .env.example # Environment variables template
βββ src/
β βββ server.ts # MCP server implementation
β βββ types.ts # Generated TypeScript types
β βββ client.ts # HTTP client with auth
β βββ config.ts # Configuration handling
βββ dist/ # Compiled JavaScript
βββ server.js
Example: server.ts
import { Server } from '@modelcontextprotocol/sdk/server';
import { APIClient } from './client';
export function createServer(config: ServerConfig) {
const client = new APIClient(config);
const server = new Server();
// Generated tool: listCampaigns
server.tool(
'listCampaigns',
{
description: 'List all advertising campaigns\nπ Category: Campaign',
inputSchema: {
type: 'object',
properties: {
page: { type: 'number', description: 'Page number' },
pageSize: { type: 'number', description: 'Items per page' },
},
},
},
async (input) => {
return await client.get('/api/client/campaign', {
params: input,
});
}
);
// ... 38 more tools
// Meta-tool: listMethods
server.tool('listMethods', ..., async (input) => {
return filterTools(allTools, input.category, input.search);
});
return server;
}
Example: types.ts
// Generated from OpenAPI schemas
export interface Campaign {
id: string;
title: string;
budget?: number;
status: 'ACTIVE' | 'PAUSED' | 'ARCHIVED';
createdAt?: Date;
}
export interface CampaignStatistics {
campaignId: string;
impressions: number;
clicks: number;
spend: number;
}
// ... 85 more interfaces
π§ͺ Testing
Run Tests
# All tests
npm test
# With coverage
npm run test:coverage
# Watch mode
npm run test:watch
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e
Test Coverage
Target Requirements:
- Lines: 80%
- Functions: 80%
- Branches: 75%
- Statements: 80%
Current Baseline (as of 2025-01-04):
- Overall: 66% lines, 81% functions, 83% branches, 66% statements
- CLI: 14 passing tests
- Generator: 20 passing tests
- Coverage enforced in CI to prevent regression
Note: Current thresholds set to 65% (lines/statements) and 70% (branches) to prevent regression. Goal is to reach 80% coverage for all new code by Epic 2 completion.
See Testing Guide for details.
π CI/CD
Automated Checks
Every pull request and push to main branch triggers automated quality checks:
Quality Gates (all must pass):
- β TypeScript compilation (strict mode)
- β ESLint (no errors)
- β Unit tests (β₯80% coverage)
- β Build succeeds for all packages
Test Matrix:
- Node.js versions: 18, 20, 22 (LTS)
- Operating systems: Ubuntu, macOS, Windows
- Total jobs: 9 parallel tests
Running Checks Locally
Before pushing code, run all CI checks locally:
# Run all checks in order
pnpm install
pnpm tsc --noEmit # TypeScript compilation
pnpm lint # ESLint
pnpm test # Unit tests
pnpm build # Build packages
Troubleshooting CI Failures
TypeScript errors:
- Check
pnpm tsc --noEmitoutput - Ensure all types are properly defined
- Verify
tsconfig.jsonis correct
Linting errors:
- Run
pnpm lintto see errors - Auto-fix:
pnpm lint --fix - Check
.eslintrc.jsonfor rules
Test failures:
- Run
pnpm testlocally - Check test logs in GitHub Actions
- Ensure tests are deterministic
Build failures:
- Verify all dependencies installed
- Check for missing imports
- Review build scripts in
package.json
π οΈ Development
Prerequisites
- Node.js: 20.11.0 LTS (minimum β₯18.0.0)
- pnpm: 8.15.1 or higher
- TypeScript: 5.3.3
Setup
# Clone repository
git clone https://github.com/your-org/openapi-to-mcp.git
cd openapi-to-mcp
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run tests
pnpm test
# Run linting
pnpm lint
# Format code
pnpm format
Monorepo Structure
openapi-to-mcp/
βββ packages/
β βββ cli/ # Command-line interface
β βββ parser/ # OpenAPI 3.0 parsing
β βββ generator/ # Code generation engine
β βββ templates/ # Boilerplate templates
βββ examples/ # Real-world test cases
βββ tests/ # Cross-package integration tests
βββ docs/ # Architecture + API docs
βββ scripts/ # Build and utility scripts
βββ pnpm-workspace.yaml # pnpm workspace configuration
βββ package.json # Root package configuration
βββ tsconfig.json # Base TypeScript configuration
βββ README.md # This file
Development Workflow
# Create feature branch
git checkout -b feature/my-feature
# Make changes
# ... edit code ...
# Run tests
npm test
# Build
npm run build
# Test locally
openapi-to-mcp generate ./test-spec.json
# Commit
git add .
git commit -m "feat: add my feature"
# Push and create PR
git push origin feature/my-feature
π Examples
Example 1: Ozon Performance API
Input: swagger/swagger.json
- 39 paths
- 87 schemas
- 6 tags (Campaign, Statistics, Ad, Product, etc.)
Command:
openapi-to-mcp generate ./swagger/swagger.json \
-o ./examples/ozon-performance \
-n ozon-performance-api
Output:
- 39 MCP tools + 1 meta-tool (listMethods)
- 87 TypeScript interfaces
- HTTP client with Bearer auth
- Complete MCP server ready to deploy
Usage:
// List campaigns
const campaigns = await mcp.listCampaigns({ page: 1, pageSize: 10 });
// Get statistics
const stats = await mcp.getCampaignStatistics({
campaignId: '12345',
dateFrom: '2025-01-01',
dateTo: '2025-01-31',
});
// Update campaign
await mcp.updateCampaign({
campaignId: '12345',
body: { dailyBudget: 5000 },
});
See Examples Documentation for more.
π€ Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Write tests: Ensure 80%+ coverage
- Follow code style: Run
npm run lint - Commit with conventional commits:
feat:,fix:,docs:, etc. - Push and create PR
See CONTRIBUTING.md for details.
π License
MIT License - see LICENSE file for details.
π Acknowledgments
- OpenAPI Specification - API standard
- Model Context Protocol - MCP specification
- Ozon Performance API - Test case and validation
π Support
- Documentation: docs/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
πΊοΈ Roadmap
MVP (v0.1.0) - Current
- OpenAPI 3.0 parser with $ref resolution
- TypeScript type generation from schemas
- MCP tool generation from operations
- HTTP client with Bearer/API key auth
- Tag-based smart filtering
- CLI with generate/validate/init commands
- Documentation (brief, research, architecture, API, examples, testing)
Post-MVP (v0.2.0)
- OpenAPI 3.1 support
- Swagger 2.0 support
- OAuth2 authentication
- Server variables support
- Response formatters (compact, verbose, custom)
- Plugin system
- Web UI for generation
- Generated server caching
- Rate limiting
Future (v1.0.0)
- GraphQL to MCP generator
- gRPC to MCP generator
- Live API proxy mode (no generation)
- AI-powered API discovery
- Multi-language support (Python, Go, Rust)
Built with β€οΈ for the AI agent ecosystem
Documentation β’ Examples β’ API Reference
