Skip to main content
Glama
apifox-import-mcp

apifox-import-mcp

by hexonal
README.md
# apifox-import-mcp

A Model Context Protocol (MCP) server for importing OpenAPI documents to Apifox.

## Features

- **Import OpenAPI to Apifox**: Directly import OpenAPI YAML/JSON files to your Apifox project
- **Validate OpenAPI Files**: Validate and extract statistics from OpenAPI documents
- **Easy Configuration**: Configure via environment variables in `.mcp.json`
- **Async Operations**: Built with async/await for optimal performance
- **Error Handling**: Comprehensive error messages for troubleshooting

## Installation

### Using uvx (Recommended)

```bash
uvx apifox-import-mcp
```

### Using pip

```bash
pip install apifox-import-mcp
```

### From Source

```bash
git clone https://github.com/hexonal/apifox-import-mcp.git
cd apifox-import-mcp
pip install -e .
```

## Configuration

Add to your `.mcp.json`:

```json
{
  "mcpServers": {
    "apifox-import": {
      "command": "uvx",
      "args": ["apifox-import-mcp"],
      "env": {
        "APIFOX_PROJECT_ID": "your-project-id",
        "APIFOX_ACCESS_TOKEN": "your-access-token"
      }
    }
  }
}
```

### Environment Variables

| Variable | Required | Description | Default |
|----------|----------|-------------|---------|
| `APIFOX_PROJECT_ID` | Yes | Apifox project ID | - |
| `APIFOX_ACCESS_TOKEN` | Yes | Apifox access token | - |
| `APIFOX_API_BASE` | No | API base URL | `https://api.apifox.com/api/v1` |

## Tools

### import_openapi

Import OpenAPI document to Apifox project.

**Parameters:**
- `file_path` (required): Absolute path to OpenAPI YAML/JSON file
- `delete_unmatched` (optional): Whether to delete unmatched resources (default: `true`)
- `api_overwrite_mode` (optional): API overwrite mode (default: `"methodAndPath"`)
  - Options: `"methodAndPath"`, `"ignore"`, `"all"`
- `schema_overwrite_mode` (optional): Schema overwrite mode (default: `"title"`)
  - Options: `"title"`, `"ignore"`, `"all"`

**Returns:**
```json
{
  "status": "success",
  "data": {
    "api": {
      "created": 5,
      "updated": 2,
      "errors": 0,
      "ignored": 0
    },
    "folder": {
      "created": 3,
      "updated": 1
    }
  }
}
```

**Example Usage:**
```
User: Import the OpenAPI file at /path/to/openapi.yaml to Apifox
Claude: Calling import_openapi tool...
```

### validate_openapi

Validate OpenAPI file and extract statistics.

**Parameters:**
- `file_path` (required): Absolute path to OpenAPI YAML/JSON file

**Returns:**
```json
{
  "status": "success",
  "data": {
    "file": "/path/to/openapi.yaml",
    "size": "25.3 KB",
    "format": "YAML",
    "version": "3.0.3",
    "endpoints": 5,
    "schemas": 12,
    "tags": ["Tag1", "Tag2"]
  }
}
```

**Example Usage:**
```
User: Validate the OpenAPI file at /path/to/openapi.yaml
Claude: Calling validate_openapi tool...
```

## Troubleshooting

### Error: "APIFOX_PROJECT_ID not set"

Make sure your `.mcp.json` includes the `APIFOX_PROJECT_ID` environment variable.

### Error: "File not found: /path/to/file.yaml"

Verify the file path is correct and the file exists. Use absolute paths, not relative paths.

### Error: "Invalid OpenAPI format"

Ensure your file is valid YAML or JSON and conforms to the OpenAPI specification.

### Error: "HTTP 401: Invalid access token"

Check that your `APIFOX_ACCESS_TOKEN` is correct and has not expired.

### Error: "HTTP 404: Project not found"

Verify your `APIFOX_PROJECT_ID` is correct.

## Development

### Setup

```bash
git clone https://github.com/hexonal/apifox-import-mcp.git
cd apifox-import-mcp
pip install -e ".[dev]"
```

### Run Tests

```bash
pytest tests/ -v
```

### Code Formatting

```bash
black .
isort .
```

### Type Checking

```bash
mypy apifox_import_mcp/
```

## License

MIT License - see [LICENSE](LICENSE) for details.

## Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

## Links

- [GitHub Repository](https://github.com/hexonal/apifox-import-mcp)
- [Apifox API Documentation](https://apifox.com/apidoc/)
- [Model Context Protocol](https://github.com/anthropics/mcp)