Content
# Apifox MCP Server
With Apifox MCP Server, you can provide the interface documentation within the Apifox project as a data source to IDE tools like Cursor that support AI programming, allowing AI to directly access the corresponding interface documentation data of the project.
Developers can accomplish the following tasks with the AI assistant: generate or modify code based on the interface documentation, search the content of the interface documentation, and more. As for what more powerful tasks AI can perform with this interface documentation data, let your imagination and that of your team run wild 😜
## 🎯 How to Use
After installing and configuring MCP, Apifox MCP Server will automatically read all the interface documentation data from the entire Apifox project and cache it on your local computer. AI can read all the interface documentation data of the interfaces within the project through MCP.
You just need to tell the AI what you want to do with the API documentation, for example:
1. “Get API documentation through MCP, then generate definition code for Product and its related models”
2. “Add several new fields from the API documentation to the Product DTO”
3. “Add comments to each field of the Product class based on the API documentation”
4. “Generate all MVC code related to the /users interface based on the API documentation”
Note: The interface documentation data is cached locally by default. If there are updates to the data in Apifox, please tell the AI to refresh the interface documentation data; otherwise, the data read by the AI may not be the latest.
## 🚀 Installation Method
### Prerequisites
- Node.js environment installed (version >= 18, latest LTS version recommended)
- Any IDE that supports MCP:
- Cursor
- VSCode + Cline plugin
### Installation
1. **Generate Access Token in Apifox**
a. Open Apifox, hover over the avatar in the upper right corner of the page, and click “Account Settings -> API Access Token”
b. Create a new API access token, see the help documentation for details
c. Obtain the API access token and replace `<access-token>` in the configuration file below
2. **Get Apifox Project ID**
a. Open the corresponding project in Apifox
b. Click on “Project Settings” in the left sidebar, and you can copy the project ID on the “Basic Settings” page
c. Obtain the project ID and replace `<project-id>` in the configuration file below
3. **Configure IDE**
Add the following JSON configuration to the corresponding MCP configuration file of the IDE:
```json
{
"mcpServers": {
"API 文档": {
"command": "npx",
"args": [
"-y",
"apifox-mcp-server@latest",
"--project-id=<project-id>"
],
"env": {
"APIFOX_ACCESS_TOKEN": "<access-token>"
}
}
}
}
```
If you are using Windows and the above configuration file does not work properly, please use the following configuration file:
```json
{
"mcpServers": {
"API 文档": {
"command": "cmd",
"args": [
"/c",
"npx",
"-y",
"apifox-mcp-server@latest",
"--project-id=<project-id>"
],
"env": {
"APIFOX_ACCESS_TOKEN": "<access-token>"
}
}
}
}
```
- Cursor: Add to the global `~/.cursor/mcp.json` or the project’s `.cursor/mcp.json`
- Cline: Open the Cline panel > MCP Server > Configure MCP Server
**Note:**
1. Please replace `<access-token>` and `<project-id>` above with your personal Apifox API access token and Apifox project ID.
2. It is recommended to name the MCP Server in the configuration file something like “API 文档” or “xxx API 文档” that includes the term “API 文档”, so that AI can more easily recognize the purpose of this MCP Server. Avoid naming it “Apifox” or “Apifox MCP”, as this makes it harder for AI to identify its purpose.
3. If you need to use API documentation from multiple projects, simply add configurations for multiple MCP Servers in the configuration file (different projects have different `<project-id>`), naming the MCP Server “xxx API 文档”.
4. If your team prefers to sync the MCP configuration file to the code repository, it is recommended to remove `"APIFOX_ACCESS_TOKEN": "<access-token>"` from the configuration and instead configure an environment variable named APIFOX_ACCESS_TOKEN on each member's computer to avoid potential leakage of the APIFOX_ACCESS_TOKEN.
5. For users using a private deployment version, please add the parameter: `"--apifox-api-base-url=<API address of the private deployment server, starting with http:// or https://>"` in the IDE's MCP configuration file. Additionally, ensure that the network can access `www.npm.com` properly.
6. In addition to Apifox projects, it also supports directly reading Swagger/OAS files. Please remove the `"--project-id=<project-id>"` parameter and add the `"--oas=<oas-url-or-path>"` parameter. For example: `npx apifox-mcp-server --oas https://petstore.swagger.io/v2/swagger.json` or `npx apifox-mcp-server --oas ~/data/petstore/swagger.json`
## ❓ Help and Support
Apifox MCP Server is still in the beta testing phase. We welcome your suggestions and ideas. Please join the beta testing group:
