apifox-mcp-server 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -87
- package/lib/index.js +531 -0
- package/package.json +35 -19
- package/index.js +0 -11083
package/README.md
CHANGED
|
@@ -1,94 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# 如果没有安装 pnpm,可先运行:npm i -g pnpm
|
|
30
|
-
|
|
31
|
-
pnpm i && pnpm build && pnpm start
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### 1.5 看到启动成功日志
|
|
35
|
-
|
|
36
|
-
```shell
|
|
37
|
-
> apifox-mcp-demo@0.0.1 start /Users/code/apifox-mcp-demo
|
|
38
|
-
> node lib/index.js
|
|
39
|
-
|
|
40
|
-
SSE endpoint: http://localhost:4444/sse
|
|
41
|
-
Message endpoint: http://localhost:4444/messages
|
|
42
|
-
HTTP server listening on port 4444
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## 2. 准备 Cursor
|
|
46
|
-
|
|
47
|
-
### 2.1 创建一个空白的 Nestjs 项目
|
|
48
|
-
|
|
49
|
-
```shell
|
|
50
|
-
npm i -g @nestjs/cli
|
|
51
|
-
nest new nest-ai-demo
|
|
52
|
-
cd nest-ai-demo
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 2.2 添加一个 Cursor MCP 配置
|
|
56
|
-
|
|
57
|
-
从 `apifox-mcp-demo` 项目中复制 `sse 的地址`,填到 `Server URL` 中。
|
|
58
|
-
|
|
59
|
-

|
|
60
|
-
|
|
61
|
-
可以看到MCP 服务连接成功
|
|
62
|
-
|
|
63
|
-

|
|
64
|
-
|
|
65
|
-
### 2.3 打开 Cursor Composer,并切换到 Agent 模式
|
|
66
|
-
|
|
67
|
-

|
|
68
|
-
|
|
69
|
-
### 2.4 复制一个 Apifox 接口的协作链接
|
|
70
|
-
|
|
71
|
-

|
|
72
|
-
|
|
73
|
-
### 2.5 粘贴到 Composer 中,并让其实现接口
|
|
74
|
-
|
|
75
|
-
```plaintext
|
|
76
|
-
https://app.apifox.com/link/project/5898808/apis/api-263537040
|
|
77
|
-
|
|
78
|
-
通过这个 Apifox 协作链接,获取其 OpenAPI 的定义,然后根据定义实现这个接口。
|
|
79
|
-
|
|
80
|
-
注意:技术是:nestjs + typescript,项目我已经搭建了好了,直接实现即可。
|
|
1
|
+
# Apifox Mcp Server
|
|
2
|
+
|
|
3
|
+
使用 Apifox MCP Server,可以将 Apifox 项目内的接口文档作为数据源提供给 AI 工具,以便让 AI 直接访问接口文档。
|
|
4
|
+
开发者可以通过 AI 助手完成以下工作:根据接口文档生成代码、在接口文档内搜索内容等。
|
|
5
|
+
|
|
6
|
+
Node.js 版本需要 >= 18。
|
|
7
|
+
|
|
8
|
+
## 将 MCP 服务器与 Cursor 一起使用
|
|
9
|
+
|
|
10
|
+
建议在项目目录中创建一个 .cursor/mcp.json 文件,通过 --project 参数配置项目 ID:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"mcpServers": {
|
|
15
|
+
"apifox": {
|
|
16
|
+
"command": "npx",
|
|
17
|
+
"args": [
|
|
18
|
+
"-y",
|
|
19
|
+
"apifox-mcp-server@latest"
|
|
20
|
+
"--project=<project-id>"
|
|
21
|
+
],
|
|
22
|
+
"env": {
|
|
23
|
+
// 也可以在操作系统配置名为 APIFOX_ACCESS_TOKEN 的环境变量
|
|
24
|
+
"APIFOX_ACCESS_TOKEN": "<access-token>"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
81
29
|
```
|
|
82
30
|
|
|
83
|
-
|
|
31
|
+
启动 Apifox MCP Server 之前,需要先准备 Apifox 的个人 API 访问令牌。在 Apifox 内,
|
|
32
|
+
将鼠标悬停在页面右上角的头像上,点击 “账号设置 -> API 访问令牌”,即可创建新令牌,
|
|
33
|
+
详见帮助文档。将令牌的实际内容,替换上面配置文件中的<access-token>。
|
|
84
34
|
|
|
85
|
-
|
|
35
|
+
此外,需要 Apifox 项目的 ID。在 Apifox 内打开项目,在左侧边栏点击“项目设置”,
|
|
36
|
+
在“基本设置”页面即可复制项目 ID。使用真实项目 ID,替换上面配置文件中的 <project-id>。
|
|
86
37
|
|
|
87
|
-
|
|
38
|
+
然后,使用 ⌘+I 打开 Agent 模式的 AI 对话界面,用自然语言和 AI 对话,
|
|
39
|
+
比如:根据接口文档,生成 Product 相关接口的代码,使用 Express.js。
|
|
88
40
|
|
|
89
|
-
|
|
41
|
+
## 帮助与支持
|
|
90
42
|
|
|
91
|
-
|
|
43
|
+
请加入 Apifox MCP Server 内测群:
|
|
92
44
|
|
|
93
|
-
|
|
94
|
-

|
|
45
|
+

|