Skip to main content

MCP OpenAPI Generator

PyPI version Python Version License: MIT Smithery

An MCP (Model Context Protocol) server that provides OpenAPI code generation and validation capabilities to AI assistants. Wraps industry-standard tools:

  • Code Generation: openapi-generator and swagger-codegen for 50+ target languages/frameworks
  • Validation: Spectral and Vacuum for OpenAPI specification linting
  • Project Intelligence: Auto-detects project type and suggests appropriate targets

Features

Capability Tools Description
Generate Client openapi-generator, swagger-codegen Generate SDKs for TypeScript, Python, Java, Go, Rust, Swift, C#, Kotlin, and more
Validate Spec Spectral, Vacuum Lint OpenAPI specs with customizable rulesets
List Generators — Discover available generators and targets
Infer Project — Auto-detect project type (Node, Python, Rust, Go, Java, etc.) and suggest targets

Quick Start

Installation

# Via pip (recommended)
pip install mcp-openapi-generator

# Or via Smithery (for MCP clients)
smithery install @mkabdullahi/mcp-openapi-generator

Usage as MCP Server

Configure in your MCP client (Claude Desktop, Cursor, etc.):

{
  "mcpServers": {
    "openapi-generator": {
      "command": "python",
      "args": ["-m", "mcp_openapi_generator.server"]
    }
  }
}

For a local VS Code setup, create .vscode/mcp.json with the following configuration after creating and installing into the project virtual environment:

python3 -m venv .venv
.venv/bin/python -m pip install -e .
{
  "servers": {
    "openapi-generator": {
      "type": "stdio",
      "command": "${workspaceFolder}/.venv/bin/python",
      "args": ["-m", "mcp_openapi_generator.server"],
      "cwd": "${workspaceFolder}"
    }
  }
}

In VS Code, open the MCP server controls and start openapi-generator. This workspace configuration is ignored by Git because it points to a local virtual environment.

Usage as CLI Tool

# Generate TypeScript client from Petstore
mcp-openapi-generator generate https://petstore.swagger.io/v2/swagger.json \
  --target typescript-axios \
  --output ./petstore-client

# Validate a spec
mcp-openapi-generator validate https://petstore.swagger.io/v2/swagger.json

# List available generators
mcp-openapi-generator generators

# Infer project config
mcp-openapi-generator infer

Available Tools (MCP)

Tool Description Parameters
generate-client Generate client code from OpenAPI spec spec, target, output_dir, package_name, package_version, additional_properties, generate_tests, post_process
validate-spec Validate OpenAPI specification spec, tool (spectral/vacuum), ruleset, fail_on_warnings
list-generators List available generators and targets —
infer-project Detect project type and suggest target —

Tool: generate-client

{
  "spec": {
    "source": "url",
    "location": "https://api.example.com/openapi.yaml",
    "format": "yaml"
  },
  "target": "typescript-axios",
  "output_dir": "./generated",
  "package_name": "my-api-client",
  "package_version": "1.0.0",
  "additional_properties": {
    "supportsES6": "true",
    "npmName": "@myorg/api-client"
  },
  "generate_tests": true,
  "post_process": true
}

Tool: validate-spec

{
  "spec": {
    "source": "file",
    "location": "./openapi.yaml"
  },
  "tool": "spectral",
  "ruleset": "spectral:oas",
  "fail_on_warnings": false
}

Supported Targets

Category Targets
TypeScript typescript-axios, typescript-fetch, typescript-node
Python python, python-aiohttp
Java spring, spring-boot
Kotlin kotlin-spring
Go go, go-gin
Rust rust
Swift swift5
C# csharp-netcore

Run mcp-openapi-generator generators for the full list (depends on installed generators).

Prerequisites

The server wraps external CLI tools. Install them for full functionality:

# Code generators (choose one or both)
npm install -g @openapitools/openapi-generator-cli
npm install -g swagger-codegen

# Validators
npm install -g @stoplight/spectral-cli
npm install -g vacuum

Or use the Docker image which includes everything:

docker run --rm -v $(pwd):/workspace ghcr.io/mkabdullahi/mcp-openapi-generator generate ...

Configuration

Project Auto-Detection

The server automatically detects your project type:

File Detected As
package.json TypeScript/JavaScript
pyproject.toml / requirements.txt Python
Cargo.toml Rust
go.mod Go
pom.xml / build.gradle Java/Kotlin

Default Targets by Language

Language Default Target
TypeScript typescript-axios
Python python
Java spring-boot
Kotlin kotlin-spring
Go go-gin
Rust rust
Swift swift5
C# csharp-netcore

Development

Setup

git clone https://github.com/mkabdullahi/mcp-openapi-generator
cd mcp-openapi-generator

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install in development mode
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=mcp_openapi_generator --cov-report=html

# Run only unit tests (skip integration)
pytest -m "not integration"

Code Quality

# Format
ruff format .

# Lint
ruff check .

# Type check
mypy src/

Publishing

To PyPI

# Build
python -m build

# Publish
twine upload dist/*

To Smithery

# Build Docker image
docker build -t ghcr.io/mkabdullahi/mcp-openapi-generator:latest .

# Push
docker push ghcr.io/mkabdullahi/mcp-openapi-generator:latest

# Publish to Smithery
smithery publish

Architecture

mcp_openapi_generator/
├── server.py          # MCP server implementation
├── cli.py             # CLI entry points
├── tools/
│   ├── generate.py    # Code generation wrapper
│   └── validate.py    # Validation wrapper
├── utils/
│   ├── config_inference.py  # Project type detection
│   ├── spec_resolver.py     # Spec fetching & resolution
│   └── post_process.py      # Formatting & test stubs
└── types/
    └── __init__.py    # Type definitions (dataclasses, enums)

License

MIT License - see LICENSE for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a PR

Metadata

Release files for mcp-openapi-generator 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-openapi-generator 1.0.0
File Size Uploaded Provenance Actions
mcp_openapi_generator-1.0.0.tar.gz 22.4 kB Without provenance Details for mcp_openapi_generator-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-openapi-generator 1.0.0
File Interpreter ABI Platform Actions
mcp_openapi_generator-1.0.0-py3-none-any.whl Python 3 none any Details for mcp_openapi_generator-1.0.0-py3-none-any.whl

Total release size: 46.7 kB

Release files / mcp_openapi_generator-1.0.0.tar.gz

Download URL mcp_openapi_generator-1.0.0.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a921c07e8f53ce8e0dcc068850eeb0c307d12e11e8891cb6cc15c7ffe7b7e758
BLAKE2b-256 checksum
How to use checksums
41370ad6c4a4006af909e2630714eda56381072a927cd7a2ce81415f4494f872
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release files / mcp_openapi_generator-1.0.0-py3-none-any.whl

Download URL mcp_openapi_generator-1.0.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
253f211d352ef0c2e56e7006c96dd93e6a45812fe74be65feea08c84727dfa6f
BLAKE2b-256 checksum
How to use checksums
899cfce38f9e8f9420b24acb23496f3861d222654a2bac5e367b21c187c80862
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Security for mcp-openapi-generator 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page