openapi-docs-mcp 0.1.0 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +168 -28
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -17,41 +17,84 @@
17
17
  - Node.js 20 或更高版本
18
18
  - 开发时建议使用 pnpm 11 或更高版本
19
19
 
20
- ## 安装与构建
20
+ ## 快速开始
21
+
22
+ 包已经发布到 npm:[openapi-docs-mcp](https://www.npmjs.com/package/openapi-docs-mcp)。
23
+
24
+ ### 使用 npx(推荐)
25
+
26
+ 不需要安装,直接下载并运行指定版本:
21
27
 
22
28
  ```bash
23
- pnpm install
24
- pnpm build
29
+ npx -y openapi-docs-mcp@0.1.3 \
30
+ --source https://api.example.com/v3/api-docs \
31
+ --timeout 30000
32
+ ```
33
+
34
+ 建议在 MCP 配置中固定版本,例如 `openapi-docs-mcp@0.1.3`,避免新版本自动升级后改变行为。
35
+
36
+ 如果希望始终使用最新版本:
37
+
38
+ ```bash
39
+ npx -y openapi-docs-mcp@latest \
40
+ --source https://api.example.com/v3/api-docs
25
41
  ```
26
42
 
27
- 构建产物位于 `dist/`。
43
+ ### 使用 pnpm dlx
28
44
 
29
- ## 启动服务
45
+ ```bash
46
+ pnpm dlx openapi-docs-mcp@0.1.3 \
47
+ --source https://api.example.com/v3/api-docs \
48
+ --timeout 30000
49
+ ```
50
+
51
+ ### 全局安装
52
+
53
+ ```bash
54
+ npm install --global openapi-docs-mcp@0.1.3
55
+ ```
56
+
57
+ 安装后可以直接执行:
58
+
59
+ ```bash
60
+ openapi-docs-mcp \
61
+ --source https://api.example.com/v3/api-docs \
62
+ --timeout 30000
63
+ ```
64
+
65
+ 升级全局版本:
66
+
67
+ ```bash
68
+ npm install --global openapi-docs-mcp@latest
69
+ ```
70
+
71
+ ## 启动参数示例
30
72
 
31
73
  ### 加载本地文档
32
74
 
33
75
  支持 OpenAPI/Swagger JSON 和 YAML 文件:
34
76
 
35
77
  ```bash
36
- node dist/cli.js --source ./openapi.json
78
+ npx -y openapi-docs-mcp@0.1.3 --source ./openapi.json
37
79
  ```
38
80
 
39
81
  也可以直接使用位置参数:
40
82
 
41
83
  ```bash
42
- node dist/cli.js ./openapi.yaml
84
+ npx -y openapi-docs-mcp@0.1.3 ./openapi.yaml
43
85
  ```
44
86
 
45
87
  ### 加载远程文档
46
88
 
47
89
  ```bash
48
- node dist/cli.js --source https://api.example.com/v3/api-docs
90
+ npx -y openapi-docs-mcp@0.1.3 \
91
+ --source https://api.example.com/v3/api-docs
49
92
  ```
50
93
 
51
94
  默认远程加载超时时间为 10 秒,可以通过 `--timeout` 修改:
52
95
 
53
96
  ```bash
54
- node dist/cli.js \
97
+ npx -y openapi-docs-mcp@0.1.3 \
55
98
  --source https://api.example.com/v3/api-docs \
56
99
  --timeout 20000
57
100
  ```
@@ -61,7 +104,7 @@ node dist/cli.js \
61
104
  可以重复使用 `--header`,格式为 `NAME=VALUE`:
62
105
 
63
106
  ```bash
64
- node dist/cli.js \
107
+ npx -y openapi-docs-mcp@0.1.3 \
65
108
  --source https://api.example.com/v3/api-docs \
66
109
  --header Authorization="Bearer token" \
67
110
  --header X-Tenant-Id=tenant-1
@@ -84,14 +127,113 @@ node dist/cli.js \
84
127
 
85
128
  ## MCP Client 配置
86
129
 
87
- 构建完成后,可以在任意支持 stdio MCP Server 的 Client 中添加配置。
88
-
89
- 路径建议使用绝对路径:
130
+ 可以在任意支持 stdio MCP Server 的 Client 中通过 `npx` 启动,无需克隆或构建本项目:
90
131
 
91
132
  ```json
92
133
  {
93
134
  "mcpServers": {
94
135
  "project-api-docs": {
136
+ "command": "npx",
137
+ "args": [
138
+ "-y",
139
+ "openapi-docs-mcp@0.1.3",
140
+ "--source",
141
+ "https://api.example.com/v3/api-docs",
142
+ "--timeout",
143
+ "30000"
144
+ ]
145
+ }
146
+ }
147
+ }
148
+ ```
149
+
150
+ ### VS Code + mise 兼容配置
151
+
152
+ VS Code 使用顶层字段 `servers`。如果 VS Code 扩展宿主误用了旧版 Node.js 或旧版 `npx`,可能出现 `ERROR: You must supply a command.`。此时可以让 VS Code 通过 `mise` 固定使用 Node.js 24,再启动本包:
153
+
154
+ ```json
155
+ {
156
+ "servers": {
157
+ "project-api-docs": {
158
+ "type": "stdio",
159
+ "command": "mise",
160
+ "args": [
161
+ "exec",
162
+ "node@24",
163
+ "--",
164
+ "npx",
165
+ "--yes",
166
+ "openapi-docs-mcp@0.1.3",
167
+ "--source",
168
+ "https://api.example.com/v3/api-docs",
169
+ "--timeout",
170
+ "30000"
171
+ ]
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ 在终端执行 `where.exe mise` 可以查看本机 `mise.exe` 的实际路径,并替换示例中的 `command`。配置步骤:
178
+
179
+ 1. 在 VS Code 中按 `Ctrl + Shift + P`;
180
+ 2. 执行 `MCP: Open User Configuration`;
181
+ 3. 写入上述配置并替换 OpenAPI 地址;
182
+ 4. 执行 `MCP: List Servers`,启动或重启 `project-api-docs`。
183
+
184
+ 推荐将包含内部 OpenAPI 地址或鉴权信息的配置放在 VS Code 用户配置中,不要提交到项目仓库。MCP 使用 stdio 通信,由 VS Code 负责启动进程,不需要提前在终端中常驻运行命令。
185
+
186
+ 同一个 npm 包可以使用不同 OpenAPI 文档启动多个实例,因此不同项目之间不会冲突。
187
+
188
+ ### 同时配置多个实例
189
+
190
+ 每个实例使用不同的 MCP Server 名称和 `--source`:
191
+
192
+ ```json
193
+ {
194
+ "mcpServers": {
195
+ "safety-api-docs": {
196
+ "command": "npx",
197
+ "args": [
198
+ "-y",
199
+ "openapi-docs-mcp@0.1.3",
200
+ "--source",
201
+ "https://safety.example.com/v3/api-docs",
202
+ "--timeout",
203
+ "30000"
204
+ ]
205
+ },
206
+ "mall-api-docs": {
207
+ "command": "npx",
208
+ "args": [
209
+ "-y",
210
+ "openapi-docs-mcp@0.1.3",
211
+ "--source",
212
+ "https://mall.example.com/v3/api-docs",
213
+ "--timeout",
214
+ "30000"
215
+ ]
216
+ }
217
+ }
218
+ }
219
+ ```
220
+
221
+ ### 使用本地源码构建
222
+
223
+ 参与开发时才需要克隆源码并构建:
224
+
225
+ ```bash
226
+ pnpm install
227
+ pnpm build
228
+ node dist/cli.js --source ./openapi.json
229
+ ```
230
+
231
+ 本地 MCP 配置需要使用 `dist/cli.js` 的绝对路径:
232
+
233
+ ```json
234
+ {
235
+ "mcpServers": {
236
+ "local-api-docs": {
95
237
  "command": "node",
96
238
  "args": [
97
239
  "C:/absolute/path/openapi-docs-mcp/dist/cli.js",
@@ -103,8 +245,6 @@ node dist/cli.js \
103
245
  }
104
246
  ```
105
247
 
106
- 同一个 npm 包可以使用不同 OpenAPI 文档启动多个实例,因此不同项目之间不会冲突。
107
-
108
248
  ## MCP 工具
109
249
 
110
250
  ### `search_api`
@@ -115,22 +255,22 @@ node dist/cli.js \
115
255
 
116
256
  输入参数:
117
257
 
118
- | 参数 | 必填 | 说明 |
119
- |---|---:|---|
120
- | `query` | 否 | 搜索关键词,例如 `异常分页列表` 或 `create user` |
121
- | `method` | 否 | HTTP 方法过滤条件,例如 `GET`、`POST` |
122
- | `tag` | 否 | 精确匹配 OpenAPI Tag |
123
- | `limit` | 否 | 返回数量,默认 10,最大 50 |
258
+ | 参数 | 必填 | 说明 |
259
+ | -------- | ---: | ------------------------------------------------ |
260
+ | `query` | 否 | 搜索关键词,例如 `异常分页列表` 或 `create user` |
261
+ | `method` | 否 | HTTP 方法过滤条件,例如 `GET`、`POST` |
262
+ | `tag` | 否 | 精确匹配 OpenAPI Tag |
263
+ | `limit` | 否 | 返回数量,默认 10,最大 50 |
124
264
 
125
265
  搜索字段权重:
126
266
 
127
- | 字段 | 权重 |
128
- |---|---:|
129
- | `summary` | 10 |
130
- | `tags` | 8 |
131
- | `path` | 6 |
132
- | `description` | 4 |
133
- | `operationId` | 2 |
267
+ | 字段 | 权重 |
268
+ | ------------- | ---: |
269
+ | `summary` | 10 |
270
+ | `tags` | 8 |
271
+ | `path` | 6 |
272
+ | `description` | 4 |
273
+ | `operationId` | 2 |
134
274
 
135
275
  中文搜索不依赖空格分词,会使用标准化、包含匹配以及二元/三元字符片段进行评分。
136
276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-docs-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "A vendor-neutral MCP server for searching and understanding OpenAPI documents.",
5
5
  "type": "module",
6
6
  "bin": {