Apifox MCP Server
Apifox MCP Server allows you to use interface documents within an Apifox project as a data source, providing it to AI programming IDE tools like Cursor so that AI can directly access the interface document data corresponding to the project.
Developers can accomplish the following tasks with the help of an AI assistant: generate or modify code based on interface documents, search interface document content, etc. As for what more powerful tasks AI can perform with this interface document data, unleash your and your team's imagination 😜
🎯 How to Use
After installing and configuring MCP, Apifox MCP Server will automatically read all interface document data from the entire Apifox project and cache it on the local computer. AI can read the interface document data of all interfaces within the project through MCP.
You just need to tell AI what you want to do with the API documentation. Examples:
- “Get the API documentation through MCP, and then generate the definition code for Product and its related models”
- “Based on the API documentation, add a few new fields added by the API documentation to the Product DTO”
- “Add comments to each field of the Product class based on the API documentation”
- “Generate all MVC code related to the /users interface based on the API documentation”
Note: Interface document data is cached locally by default. If there are updates to the data in Apifox, please tell AI to refresh the interface document data; otherwise, the data read by AI may not be the latest.
🚀 Installation Method
Prerequisites
- Node.js environment installed (version >= 18, the latest LTS version is recommended)
- Any IDE that supports MCP:
- Cursor
- VSCode + Cline plugin
Installation
- Generate Access Token in Apifox
a. Open Apifox, hover the mouse 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. Get the API access token and replace the
<access-token>
in the configuration file below - Get Apifox Project ID
a. Open the corresponding project in Apifox
b. Click “Project Settings” in the left sidebar, and copy the project ID on the “Basic Settings” page
c. Get the project ID and replace the
<project-id>
in the configuration file below - Configure IDE
Add the following JSON configuration to the corresponding MCP configuration file of the IDE:
{
"mcpServers": {
"API 文档": {
"command": "npx",
"args": [
"-y",
"apifox-mcp-server@latest",
"--project-id=<project-id>"
],
"env": {
"APIFOX_ACCESS_TOKEN": "<access-token>"
}
}
}
}
If you are using the Windows operating system and the above configuration file does not work properly, use the following configuration file:
{
"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 Cline panel > MCP Server > Configure MCP Server
Note:
- Please replace the
<access-token>
and<project-id>
above with your personal Apifox API access token and Apifox project ID. - It is recommended to fill in the MCP Server name in the configuration file with a name containing the words “API documentation,” such as “API Documentation” or “xxx API Documentation,” so that AI can easily and correctly identify the purpose of this MCP Server. It is not recommended to fill in “Apifox” or “Apifox MCP” because AI cannot easily identify the purpose with this writing.
- If you need to use API documentation from multiple projects, add multiple MCP Servers in the configuration file (different projects have different
<project-id>
), and fill in the MCP Server name with “xxx API Documentation.” - If the team is accustomed to synchronizing the MCP configuration file to the code repository, it is recommended to delete "APIFOX_ACCESS_TOKEN": "
<access-token>
" in the configuration and change it to each member configuring an environment variable named APIFOX_ACCESS_TOKEN on their own computer to avoid APIFOX_ACCESS_TOKEN leakage issues. - For users using a privately deployed version, please add the parameter: "--apifox-api-base-url=
<API address of the privately deployed server, starting with http:// or https://>
" to the IDE's MCP configuration file. In addition, please ensure that the network can accesswww.npm.com
normally. - In addition to Apifox projects, direct reading of Swagger/OAS files is also supported. Please delete 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
ornpx apifox-mcp-server --oas ~/data/petstore/swagger.json
❓ Help and Support
Apifox MCP Server is still in the internal testing stage. You are welcome to give us suggestions and ideas. Please join the internal testing group: