MCP server for importing OpenAPI documents to Apifox
Project description
apifox-write-mcp
A Model Context Protocol (MCP) server for importing OpenAPI documents to Apifox projects.
Overview
This MCP server provides tools for importing OpenAPI 3.0 specifications into Apifox projects. It validates OpenAPI documents, handles configuration management, and communicates with the Apifox API to perform imports.
Features
- OpenAPI 3.0 document validation
- Configurable import options
- Error handling and retry logic
- MCP protocol compliance
- Python 3.12+ support
- Async/await support
Installation
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .
Run Without Installing (uvx)
After publishing to PyPI (or from a local path), you can run the server with uvx:
# From PyPI
uvx --from apifox-write-mcp apifox-write-mcp
Configuration
Set the following environment variables or create an apifox.config.json file:
Environment Variables
export APIFOX_PROJECT_ID="your-project-id"
export APIFOX_ACCESS_TOKEN="your-access-token"
export APIFOX_BASE_URL="https://api.apifox.com" # Optional
export LOG_LEVEL="2" # Optional: 0=ERROR, 1=WARN, 2=INFO, 3=DEBUG
Configuration File
Create apifox.config.json in your project root:
{
"projectId": "your-project-id",
"accessToken": "your-access-token",
"baseUrl": "https://api.apifox.com",
"apiVersion": "v1",
"retryAttempts": 3,
"timeout": 30000
}
Usage
As MCP Server
Run the server:
# Installed console script
apifox-write-mcp
# Or module execution
python -m apifox_write_mcp
# Or legacy (repo-only) entrypoint
python main.py
The server will listen on stdio for MCP protocol messages.
MCP Tool: import_openapi_to_apifox
Import an OpenAPI document to Apifox:
Parameters:
document(required): OpenAPI document as JSON stringoptions(optional): Import configuration optionstargetEndpointFolderId: Target folder ID for endpointstargetSchemaFolderId: Target folder ID for schemasendpointOverwriteBehavior: How to handle existing endpoints (OVERWRITE_EXISTING,AUTO_MERGE,KEEP_EXISTING,CREATE_NEW)schemaOverwriteBehavior: How to handle existing schemasupdateFolderOfChangedEndpoint: Whether to update folder of changed endpointsprependBasePath: Whether to prepend base pathtargetBranchId: Target branch IDmoduleId: Target module ID
Project Structure
.
├── apifox_write_mcp/
│ ├── client/ # Apifox API client
│ ├── config/ # Configuration management
│ ├── services/ # Import service orchestration
│ ├── types/ # Type definitions and error classes
│ ├── utils/ # Logging and error handling utilities
│ ├── validator/ # OpenAPI document validation
│ └── server.py # MCP server entrypoint (console script)
├── main.py # Legacy wrapper entrypoint
├── pyproject.toml # Project configuration
└── README.md # This file
Development
Running Tests
# Install dev dependencies
uv sync --dev
# Run tests
pytest
Code Structure
The project follows a modular architecture:
- Types (
apifox_write_mcp/types/): Data models and error definitions - Utils (
apifox_write_mcp/utils/): Logging and error handling - Config (
apifox_write_mcp/config/): Configuration management - Validator (
apifox_write_mcp/validator/): OpenAPI document validation - Client (
apifox_write_mcp/client/): HTTP client for Apifox API - Services (
apifox_write_mcp/services/): Import workflow orchestration - Server (
apifox_write_mcp/server.py): MCP server implementation
Migration from TypeScript
This is a Python port of the TypeScript implementation located in the ts/ directory. The main differences:
- Uses
httpxinstead ofaxiosfor HTTP requests - Uses Python's native
asyncioinstead of Node.js promises - Uses dataclasses instead of TypeScript interfaces
- Uses Python's
loggingmodule concepts adapted for structured logging
License
See the TypeScript implementation for license information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apifox_write_mcp-1.0.0.tar.gz.
File metadata
- Download URL: apifox_write_mcp-1.0.0.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e81fa2c386afe7a455c51363bda7c2acc428fc5c1ea87b11f4e90ab279cca405
|
|
| MD5 |
2bd01904482fae3b7b80595d53c3f2f6
|
|
| BLAKE2b-256 |
19ae0bbf0ec3d601d86ec0d94d64c654f13ea523904d5ccbcf8cf967993e3800
|
File details
Details for the file apifox_write_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: apifox_write_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
583ee7f61110600f5dc73da76377d05b706ae814b319db27773a521afbfd9a5a
|
|
| MD5 |
19a839c150a5d6036e71c7ec3de49b84
|
|
| BLAKE2b-256 |
443ad440139b2f87cb2a4d6c16b5f100b2ebc9c82b2a832319e3133fac376d06
|