Files
soul-yongping/.cursor/apifox-mcp-setup.md
2026-03-14 14:37:17 +08:00

117 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Apifox MCP 配置说明
已在 Cursor 的 `mcp.json` 中添加 Apifox MCP 配置,你需要根据使用场景填写对应参数。
## 前置条件
- Node.js >= 18
- Apifox 版本 >= 2.7.2(若使用项目/文档站)
---
## 方式一:项目 ID + 访问令牌(推荐,团队私有文档)
适用于:读取自己团队 Apifox 项目内的 API 文档。
### 1. 获取项目 ID
- 打开 Apifox 项目
- 左侧边栏 → **项目设置****基本设置**
- 复制「项目 ID」
### 2. 获取访问令牌
- Apifox 右上角头像 → **账号设置****API 访问令牌**
- 创建新的 API 访问令牌并复制
### 3. 修改 mcp.json
编辑 `C:\Users\29195\.cursor\mcp.json`,将 Apifox 配置中的占位符替换为实际值:
```json
"Apifox": {
"command": "npx",
"args": [
"-y",
"apifox-mcp-server@latest",
"--project-id=你的项目ID"
],
"env": {
"APIFOX_ACCESS_TOKEN": "你的访问令牌"
}
}
```
---
## 方式二Site ID公开发布的文档
适用于:读取已公开发布的 API 文档站,无需令牌。
### 1. 获取 Site ID
- Apifox 项目内:**分享文档** → **发布文档站****AI 功能**
- 开启 MCP 服务,复制生成的 `site-id`
### 2. 修改 mcp.json
将 Apifox 配置改为使用 `--site-id`,并移除 `env`
```json
"Apifox": {
"command": "npx",
"args": [
"-y",
"apifox-mcp-server@latest",
"--site-id=你的SiteID"
],
"env": {}
}
```
---
## 方式三OpenAPI/Swagger 文件
适用于:本地或线上的 OpenAPI/Swagger 文档,不依赖 Apifox 项目。
```json
"Apifox": {
"command": "npx",
"args": [
"-y",
"apifox-mcp-server@latest",
"--oas=https://example.com/openapi.json"
],
"env": {}
}
```
本地文件示例:`--oas=E:/path/to/openapi.json`
---
## 私有化部署
若使用 Apifox 私有化部署,需在 `args` 中增加:
```
"--apifox-api-base-url=https://你的私有化服务器地址"
```
---
## 生效方式
修改 `mcp.json` 后,重启 Cursor 或重新加载 MCP 服务即可。
## 使用示例
配置完成后,可对 AI 说:
- 「通过 MCP 获取 API 文档,然后生成 Product 及其相关模型的定义代码」
- 「根据 API 文档,在 Product DTO 里添加 API 文档新增的几个字段」
- 「根据 API 文档,生成接口 /users 相关的所有 MVC 代码」
文档有更新时,可提示 AI「刷新接口文档数据」。