mcp-openapi-generator 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_openapi_generator-1.0.0/.gitignore +13 -0
- mcp_openapi_generator-1.0.0/.vscode/settings.json +4 -0
- mcp_openapi_generator-1.0.0/Dockerfile +58 -0
- mcp_openapi_generator-1.0.0/LICENSE +21 -0
- mcp_openapi_generator-1.0.0/PKG-INFO +332 -0
- mcp_openapi_generator-1.0.0/README.md +305 -0
- mcp_openapi_generator-1.0.0/openapitools.json +7 -0
- mcp_openapi_generator-1.0.0/pyproject.toml +78 -0
- mcp_openapi_generator-1.0.0/smithery.yaml +92 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/__init__.py +13 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/cli.py +198 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/server.py +300 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/tools/__init__.py +14 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/tools/generate.py +291 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/tools/validate.py +277 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/types/__init__.py +195 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/utils/__init__.py +21 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/utils/config_inference.py +219 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/utils/post_process.py +229 -0
- mcp_openapi_generator-1.0.0/src/mcp_openapi_generator/utils/spec_resolver.py +184 -0
- mcp_openapi_generator-1.0.0/tests/fixtures/openapi-smoke.yaml +19 -0
- mcp_openapi_generator-1.0.0/tests/test_core.py +326 -0
- mcp_openapi_generator-1.0.0/tests/test_external_tools.py +53 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Multi-stage build for MCP OpenAPI Generator
|
|
2
|
+
# Stage 1: Build dependencies
|
|
3
|
+
FROM python:3.11-slim AS builder
|
|
4
|
+
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
# Install system dependencies
|
|
8
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
9
|
+
build-essential \
|
|
10
|
+
curl \
|
|
11
|
+
git \
|
|
12
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
13
|
+
|
|
14
|
+
# Install UV for fast package management
|
|
15
|
+
RUN pip install --no-cache-dir uv
|
|
16
|
+
|
|
17
|
+
# Copy project files
|
|
18
|
+
COPY pyproject.toml README.md ./
|
|
19
|
+
COPY src/ ./src/
|
|
20
|
+
|
|
21
|
+
# Install package in editable mode
|
|
22
|
+
RUN uv pip install --system -e .
|
|
23
|
+
|
|
24
|
+
# Stage 2: Runtime with generators
|
|
25
|
+
FROM python:3.11-slim AS runtime
|
|
26
|
+
|
|
27
|
+
WORKDIR /app
|
|
28
|
+
|
|
29
|
+
# Install system dependencies including OpenAPI generators
|
|
30
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
31
|
+
openjdk-17-jre-headless \
|
|
32
|
+
curl \
|
|
33
|
+
git \
|
|
34
|
+
npm \
|
|
35
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
36
|
+
|
|
37
|
+
# Install openapi-generator-cli and swagger-codegen via npm
|
|
38
|
+
RUN npm install -g @openapitools/openapi-generator-cli swagger-codegen
|
|
39
|
+
|
|
40
|
+
# Install validation tools
|
|
41
|
+
RUN npm install -g @stoplight/spectral-cli vacuum
|
|
42
|
+
|
|
43
|
+
# Copy Python package from builder
|
|
44
|
+
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
|
45
|
+
COPY --from=builder /usr/local/bin /usr/local/bin
|
|
46
|
+
|
|
47
|
+
# Copy source code
|
|
48
|
+
COPY src/ ./src/
|
|
49
|
+
|
|
50
|
+
# Create non-root user
|
|
51
|
+
RUN useradd --create-home --shell /bin/bash mcp
|
|
52
|
+
USER mcp
|
|
53
|
+
|
|
54
|
+
# Set working directory
|
|
55
|
+
WORKDIR /home/mcp
|
|
56
|
+
|
|
57
|
+
# Default command
|
|
58
|
+
ENTRYPOINT ["python", "-m", "mcp_openapi_generator.server"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 M.K. Abdullahi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mcp-openapi-generator
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: MCP server for OpenAPI code generation (openapi-generator, swagger-codegen) and validation (Spectral, Vacuum)
|
|
5
|
+
Project-URL: Homepage, https://github.com/mkabdullahi/mcp-openapi-generator
|
|
6
|
+
Project-URL: Repository, https://github.com/mkabdullahi/mcp-openapi-generator
|
|
7
|
+
Project-URL: Issues, https://github.com/mkabdullahi/mcp-openapi-generator/issues
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: httpx>=0.27.0
|
|
12
|
+
Requires-Dist: mcp>=1.0.0
|
|
13
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
14
|
+
Requires-Dist: rich>=13.7.0
|
|
15
|
+
Requires-Dist: tenacity>=8.3.0
|
|
16
|
+
Requires-Dist: typer>=0.12.0
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: mypy>=1.10.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: pre-commit>=3.7.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=8.2.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
24
|
+
Provides-Extra: smithery
|
|
25
|
+
Requires-Dist: docker>=7.0.0; extra == 'smithery'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# MCP OpenAPI Generator
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/mcp-openapi-generator/)
|
|
31
|
+
[](https://pypi.org/project/mcp-openapi-generator/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
[](https://smithery.ai)
|
|
34
|
+
|
|
35
|
+
An **MCP (Model Context Protocol) server** that provides OpenAPI code generation and validation capabilities to AI assistants. Wraps industry-standard tools:
|
|
36
|
+
|
|
37
|
+
- **Code Generation**: `openapi-generator` and `swagger-codegen` for 50+ target languages/frameworks
|
|
38
|
+
- **Validation**: `Spectral` and `Vacuum` for OpenAPI specification linting
|
|
39
|
+
- **Project Intelligence**: Auto-detects project type and suggests appropriate targets
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
| Capability | Tools | Description |
|
|
44
|
+
|------------|-------|-------------|
|
|
45
|
+
| **Generate Client** | openapi-generator, swagger-codegen | Generate SDKs for TypeScript, Python, Java, Go, Rust, Swift, C#, Kotlin, and more |
|
|
46
|
+
| **Validate Spec** | Spectral, Vacuum | Lint OpenAPI specs with customizable rulesets |
|
|
47
|
+
| **List Generators** | — | Discover available generators and targets |
|
|
48
|
+
| **Infer Project** | — | Auto-detect project type (Node, Python, Rust, Go, Java, etc.) and suggest targets |
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
### Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Via pip (recommended)
|
|
56
|
+
pip install mcp-openapi-generator
|
|
57
|
+
|
|
58
|
+
# Or via Smithery (for MCP clients)
|
|
59
|
+
smithery install @mkabdullahi/mcp-openapi-generator
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Usage as MCP Server
|
|
63
|
+
|
|
64
|
+
Configure in your MCP client (Claude Desktop, Cursor, etc.):
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"openapi-generator": {
|
|
70
|
+
"command": "python",
|
|
71
|
+
"args": ["-m", "mcp_openapi_generator.server"]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For a local VS Code setup, create `.vscode/mcp.json` with the following
|
|
78
|
+
configuration after creating and installing into the project virtual
|
|
79
|
+
environment:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python3 -m venv .venv
|
|
83
|
+
.venv/bin/python -m pip install -e .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"servers": {
|
|
89
|
+
"openapi-generator": {
|
|
90
|
+
"type": "stdio",
|
|
91
|
+
"command": "${workspaceFolder}/.venv/bin/python",
|
|
92
|
+
"args": ["-m", "mcp_openapi_generator.server"],
|
|
93
|
+
"cwd": "${workspaceFolder}"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
In VS Code, open the MCP server controls and start `openapi-generator`. This
|
|
100
|
+
workspace configuration is ignored by Git because it points to a local virtual
|
|
101
|
+
environment.
|
|
102
|
+
|
|
103
|
+
### Usage as CLI Tool
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Generate TypeScript client from Petstore
|
|
107
|
+
mcp-openapi-generator generate https://petstore.swagger.io/v2/swagger.json \
|
|
108
|
+
--target typescript-axios \
|
|
109
|
+
--output ./petstore-client
|
|
110
|
+
|
|
111
|
+
# Validate a spec
|
|
112
|
+
mcp-openapi-generator validate https://petstore.swagger.io/v2/swagger.json
|
|
113
|
+
|
|
114
|
+
# List available generators
|
|
115
|
+
mcp-openapi-generator generators
|
|
116
|
+
|
|
117
|
+
# Infer project config
|
|
118
|
+
mcp-openapi-generator infer
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Available Tools (MCP)
|
|
122
|
+
|
|
123
|
+
| Tool | Description | Parameters |
|
|
124
|
+
|------|-------------|------------|
|
|
125
|
+
| `generate-client` | Generate client code from OpenAPI spec | `spec`, `target`, `output_dir`, `package_name`, `package_version`, `additional_properties`, `generate_tests`, `post_process` |
|
|
126
|
+
| `validate-spec` | Validate OpenAPI specification | `spec`, `tool` (spectral/vacuum), `ruleset`, `fail_on_warnings` |
|
|
127
|
+
| `list-generators` | List available generators and targets | — |
|
|
128
|
+
| `infer-project` | Detect project type and suggest target | — |
|
|
129
|
+
|
|
130
|
+
### Tool: generate-client
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"spec": {
|
|
135
|
+
"source": "url",
|
|
136
|
+
"location": "https://api.example.com/openapi.yaml",
|
|
137
|
+
"format": "yaml"
|
|
138
|
+
},
|
|
139
|
+
"target": "typescript-axios",
|
|
140
|
+
"output_dir": "./generated",
|
|
141
|
+
"package_name": "my-api-client",
|
|
142
|
+
"package_version": "1.0.0",
|
|
143
|
+
"additional_properties": {
|
|
144
|
+
"supportsES6": "true",
|
|
145
|
+
"npmName": "@myorg/api-client"
|
|
146
|
+
},
|
|
147
|
+
"generate_tests": true,
|
|
148
|
+
"post_process": true
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Tool: validate-spec
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"spec": {
|
|
157
|
+
"source": "file",
|
|
158
|
+
"location": "./openapi.yaml"
|
|
159
|
+
},
|
|
160
|
+
"tool": "spectral",
|
|
161
|
+
"ruleset": "spectral:oas",
|
|
162
|
+
"fail_on_warnings": false
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Supported Targets
|
|
167
|
+
|
|
168
|
+
| Category | Targets |
|
|
169
|
+
|----------|---------|
|
|
170
|
+
| **TypeScript** | `typescript-axios`, `typescript-fetch`, `typescript-node` |
|
|
171
|
+
| **Python** | `python`, `python-aiohttp` |
|
|
172
|
+
| **Java** | `spring`, `spring-boot` |
|
|
173
|
+
| **Kotlin** | `kotlin-spring` |
|
|
174
|
+
| **Go** | `go`, `go-gin` |
|
|
175
|
+
| **Rust** | `rust` |
|
|
176
|
+
| **Swift** | `swift5` |
|
|
177
|
+
| **C#** | `csharp-netcore` |
|
|
178
|
+
|
|
179
|
+
Run `mcp-openapi-generator generators` for the full list (depends on installed generators).
|
|
180
|
+
|
|
181
|
+
## Prerequisites
|
|
182
|
+
|
|
183
|
+
The server wraps external CLI tools. Install them for full functionality:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Code generators (choose one or both)
|
|
187
|
+
npm install -g @openapitools/openapi-generator-cli
|
|
188
|
+
npm install -g swagger-codegen
|
|
189
|
+
|
|
190
|
+
# Validators
|
|
191
|
+
npm install -g @stoplight/spectral-cli
|
|
192
|
+
npm install -g vacuum
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Or use the Docker image which includes everything:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
docker run --rm -v $(pwd):/workspace ghcr.io/mkabdullahi/mcp-openapi-generator generate ...
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Configuration
|
|
202
|
+
|
|
203
|
+
### Project Auto-Detection
|
|
204
|
+
|
|
205
|
+
The server automatically detects your project type:
|
|
206
|
+
|
|
207
|
+
| File | Detected As |
|
|
208
|
+
|------|-------------|
|
|
209
|
+
| `package.json` | TypeScript/JavaScript |
|
|
210
|
+
| `pyproject.toml` / `requirements.txt` | Python |
|
|
211
|
+
| `Cargo.toml` | Rust |
|
|
212
|
+
| `go.mod` | Go |
|
|
213
|
+
| `pom.xml` / `build.gradle` | Java/Kotlin |
|
|
214
|
+
|
|
215
|
+
### Default Targets by Language
|
|
216
|
+
|
|
217
|
+
| Language | Default Target |
|
|
218
|
+
|----------|----------------|
|
|
219
|
+
| TypeScript | `typescript-axios` |
|
|
220
|
+
| Python | `python` |
|
|
221
|
+
| Java | `spring-boot` |
|
|
222
|
+
| Kotlin | `kotlin-spring` |
|
|
223
|
+
| Go | `go-gin` |
|
|
224
|
+
| Rust | `rust` |
|
|
225
|
+
| Swift | `swift5` |
|
|
226
|
+
| C# | `csharp-netcore` |
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
### Setup
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
git clone https://github.com/mkabdullahi/mcp-openapi-generator
|
|
234
|
+
cd mcp-openapi-generator
|
|
235
|
+
|
|
236
|
+
# Create virtual environment
|
|
237
|
+
python3 -m venv .venv
|
|
238
|
+
source .venv/bin/activate
|
|
239
|
+
|
|
240
|
+
# Install in development mode
|
|
241
|
+
pip install -e ".[dev]"
|
|
242
|
+
|
|
243
|
+
# Install pre-commit hooks
|
|
244
|
+
pre-commit install
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Running Tests
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Run all tests
|
|
251
|
+
pytest
|
|
252
|
+
|
|
253
|
+
# Run with coverage
|
|
254
|
+
pytest --cov=mcp_openapi_generator --cov-report=html
|
|
255
|
+
|
|
256
|
+
# Run only unit tests (skip integration)
|
|
257
|
+
pytest -m "not integration"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Code Quality
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# Format
|
|
264
|
+
ruff format .
|
|
265
|
+
|
|
266
|
+
# Lint
|
|
267
|
+
ruff check .
|
|
268
|
+
|
|
269
|
+
# Type check
|
|
270
|
+
mypy src/
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Publishing
|
|
274
|
+
|
|
275
|
+
### To PyPI
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
# Build
|
|
279
|
+
python -m build
|
|
280
|
+
|
|
281
|
+
# Publish
|
|
282
|
+
twine upload dist/*
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### To Smithery
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# Build Docker image
|
|
289
|
+
docker build -t ghcr.io/mkabdullahi/mcp-openapi-generator:latest .
|
|
290
|
+
|
|
291
|
+
# Push
|
|
292
|
+
docker push ghcr.io/mkabdullahi/mcp-openapi-generator:latest
|
|
293
|
+
|
|
294
|
+
# Publish to Smithery
|
|
295
|
+
smithery publish
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Architecture
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
mcp_openapi_generator/
|
|
302
|
+
├── server.py # MCP server implementation
|
|
303
|
+
├── cli.py # CLI entry points
|
|
304
|
+
├── tools/
|
|
305
|
+
│ ├── generate.py # Code generation wrapper
|
|
306
|
+
│ └── validate.py # Validation wrapper
|
|
307
|
+
├── utils/
|
|
308
|
+
│ ├── config_inference.py # Project type detection
|
|
309
|
+
│ ├── spec_resolver.py # Spec fetching & resolution
|
|
310
|
+
│ └── post_process.py # Formatting & test stubs
|
|
311
|
+
└── types/
|
|
312
|
+
└── __init__.py # Type definitions (dataclasses, enums)
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
318
|
+
|
|
319
|
+
## Contributing
|
|
320
|
+
|
|
321
|
+
1. Fork the repository
|
|
322
|
+
2. Create a feature branch
|
|
323
|
+
3. Make your changes
|
|
324
|
+
4. Run tests and linting
|
|
325
|
+
5. Submit a PR
|
|
326
|
+
|
|
327
|
+
## Related
|
|
328
|
+
|
|
329
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/)
|
|
330
|
+
- [OpenAPI Generator](https://openapi-generator.tech/)
|
|
331
|
+
- [Spectral](https://meta.stoplight.io/spectral/)
|
|
332
|
+
- [Vacuum](https://github.com/daveshanley/vacuum)
|