Skip to main content

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 string
  • options (optional): Import configuration options
    • targetEndpointFolderId: Target folder ID for endpoints
    • targetSchemaFolderId: Target folder ID for schemas
    • endpointOverwriteBehavior: How to handle existing endpoints (OVERWRITE_EXISTING, AUTO_MERGE, KEEP_EXISTING, CREATE_NEW)
    • schemaOverwriteBehavior: How to handle existing schemas
    • updateFolderOfChangedEndpoint: Whether to update folder of changed endpoints
    • prependBasePath: Whether to prepend base path
    • targetBranchId: Target branch ID
    • moduleId: 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:

  1. Types (apifox_write_mcp/types/): Data models and error definitions
  2. Utils (apifox_write_mcp/utils/): Logging and error handling
  3. Config (apifox_write_mcp/config/): Configuration management
  4. Validator (apifox_write_mcp/validator/): OpenAPI document validation
  5. Client (apifox_write_mcp/client/): HTTP client for Apifox API
  6. Services (apifox_write_mcp/services/): Import workflow orchestration
  7. 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 httpx instead of axios for HTTP requests
  • Uses Python's native asyncio instead of Node.js promises
  • Uses dataclasses instead of TypeScript interfaces
  • Uses Python's logging module concepts adapted for structured logging

License

See the TypeScript implementation for license information.

Metadata

Release files for apifox-write-mcp 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 apifox-write-mcp 1.0.0
File Size Uploaded Provenance
apifox_write_mcp-1.0.0.tar.gz 22.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apifox-write-mcp 1.0.0
File Interpreter ABI Platform
apifox_write_mcp-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 52.1 kB

Release files / apifox_write_mcp-1.0.0.tar.gz

Download URL apifox_write_mcp-1.0.0.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e81fa2c386afe7a455c51363bda7c2acc428fc5c1ea87b11f4e90ab279cca405
BLAKE2b-256 checksum
How to use checksums
19ae0bbf0ec3d601d86ec0d94d64c654f13ea523904d5ccbcf8cf967993e3800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

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

Download URL apifox_write_mcp-1.0.0-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
583ee7f61110600f5dc73da76377d05b706ae814b319db27773a521afbfd9a5a
BLAKE2b-256 checksum
How to use checksums
443ad440139b2f87cb2a4d6c16b5f100b2ebc9c82b2a832319e3133fac376d06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for apifox-write-mcp 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