@tronsfey/ucli 0.5.2 → 0.5.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.
- package/README.md +102 -89
- package/README.zh.md +80 -92
- package/dist/index.js +629 -502
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skill.md +73 -65
package/README.zh.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
- **发现** 注册在 ucli 服务端上的 OpenAPI 服务
|
|
21
21
|
- **执行** API 操作,无需直接处理凭据
|
|
22
22
|
- **本地缓存** 规范,减少网络请求
|
|
23
|
-
- **调用** MCP 服务器工具,使用 `ucli mcp
|
|
23
|
+
- **调用** MCP 服务器工具,使用 `ucli mcp <server> invoketool <tool>`
|
|
24
24
|
|
|
25
25
|
认证凭据(Bearer Token、API 密钥、OAuth2 密钥、MCP 请求头/环境变量)在服务端加密存储,运行时以环境变量或请求头方式注入——**永不落盘**,也不会出现在进程列表中。
|
|
26
26
|
|
|
@@ -37,7 +37,7 @@ sequenceDiagram
|
|
|
37
37
|
Agent->>CLI: ucli configure --server URL --token JWT
|
|
38
38
|
CLI->>CLI: 保存配置(OS 配置目录)
|
|
39
39
|
|
|
40
|
-
Agent->>CLI: ucli
|
|
40
|
+
Agent->>CLI: ucli listoas
|
|
41
41
|
CLI->>Cache: 检查本地缓存(TTL)
|
|
42
42
|
alt 缓存未命中
|
|
43
43
|
CLI->>Server: GET /api/v1/oas(Bearer JWT)
|
|
@@ -47,7 +47,7 @@ sequenceDiagram
|
|
|
47
47
|
Cache-->>CLI: OAS 列表
|
|
48
48
|
CLI-->>Agent: 表格 / JSON 输出
|
|
49
49
|
|
|
50
|
-
Agent->>CLI: ucli
|
|
50
|
+
Agent->>CLI: ucli oas payments invokeapi createPayment --data '{...}'
|
|
51
51
|
CLI->>Server: GET /api/v1/oas/payments(Bearer JWT)
|
|
52
52
|
Server-->>CLI: OAS 规范 + 解密认证配置(TLS)
|
|
53
53
|
CLI->>CLI: 将认证配置注入 ENV 变量
|
|
@@ -55,7 +55,7 @@ sequenceDiagram
|
|
|
55
55
|
API-->>CLI: HTTP 响应
|
|
56
56
|
CLI-->>Agent: 格式化输出(JSON / 表格 / YAML)
|
|
57
57
|
|
|
58
|
-
Agent->>CLI: ucli mcp
|
|
58
|
+
Agent->>CLI: ucli mcp my-server invoketool get_weather --data '{"city":"Beijing"}'
|
|
59
59
|
CLI->>Server: GET /api/v1/mcp/my-server(Bearer JWT)
|
|
60
60
|
Server-->>CLI: McpEntry + 解密认证配置(TLS)
|
|
61
61
|
CLI->>CLI: 将认证信息注入 mcp2cli 配置(headers/env)
|
|
@@ -79,13 +79,13 @@ pnpm add -g @tronsfey/ucli
|
|
|
79
79
|
ucli configure --server http://localhost:3000 --token <group-jwt>
|
|
80
80
|
|
|
81
81
|
# 2. 列出可用服务
|
|
82
|
-
ucli
|
|
82
|
+
ucli listoas
|
|
83
83
|
|
|
84
84
|
# 3. 查看服务的操作列表
|
|
85
|
-
ucli
|
|
85
|
+
ucli oas payments listapi
|
|
86
86
|
|
|
87
87
|
# 4. 执行操作
|
|
88
|
-
ucli
|
|
88
|
+
ucli oas payments invokeapi getPetById --params '{"petId": 42}'
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
## 命令参考
|
|
@@ -109,12 +109,12 @@ ucli configure --server <url> --token <jwt>
|
|
|
109
109
|
|
|
110
110
|
---
|
|
111
111
|
|
|
112
|
-
### `
|
|
112
|
+
### `listoas`
|
|
113
113
|
|
|
114
114
|
列出当前群组可访问的所有 OpenAPI 服务。
|
|
115
115
|
|
|
116
116
|
```bash
|
|
117
|
-
ucli
|
|
117
|
+
ucli listoas [--format table|json|yaml] [--refresh]
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
| 参数 | 默认值 | 说明 |
|
|
@@ -122,54 +122,50 @@ ucli services list [--format table|json|yaml] [--refresh]
|
|
|
122
122
|
| `--format` | `table` | 输出格式:`table`、`json` 或 `yaml` |
|
|
123
123
|
| `--refresh` | `false` | 绕过本地缓存,从服务器重新拉取 |
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
---
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
NAME DESCRIPTION CACHE TTL
|
|
129
|
-
payments 支付服务 API 3600s
|
|
130
|
-
inventory 库存管理 1800s
|
|
131
|
-
crm CRM 操作 7200s
|
|
132
|
-
```
|
|
127
|
+
### `oas <service> info`
|
|
133
128
|
|
|
134
|
-
|
|
129
|
+
显示指定服务的详细信息。
|
|
135
130
|
|
|
136
|
-
```
|
|
137
|
-
[
|
|
138
|
-
{ "name": "payments", "description": "支付服务 API", "cacheTtl": 3600 },
|
|
139
|
-
{ "name": "inventory", "description": "库存管理", "cacheTtl": 1800 }
|
|
140
|
-
]
|
|
131
|
+
```bash
|
|
132
|
+
ucli oas <service> info [--format json|table|yaml]
|
|
141
133
|
```
|
|
142
134
|
|
|
143
135
|
---
|
|
144
136
|
|
|
145
|
-
### `
|
|
137
|
+
### `oas <service> listapi`
|
|
146
138
|
|
|
147
|
-
|
|
139
|
+
列出指定服务的所有可用 API 操作。
|
|
148
140
|
|
|
149
141
|
```bash
|
|
150
|
-
ucli
|
|
142
|
+
ucli oas <service> listapi [--format json|table|yaml]
|
|
151
143
|
```
|
|
152
144
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### `oas <service> apiinfo <api>`
|
|
148
|
+
|
|
149
|
+
显示指定 API 操作的详细输入输出参数信息。
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
ucli oas <service> apiinfo <api>
|
|
153
|
+
```
|
|
157
154
|
|
|
158
155
|
---
|
|
159
156
|
|
|
160
|
-
### `
|
|
157
|
+
### `oas <service> invokeapi <api>`
|
|
161
158
|
|
|
162
159
|
执行 OpenAPI 规范中定义的单个 API 操作。
|
|
163
160
|
|
|
164
161
|
```bash
|
|
165
|
-
ucli
|
|
162
|
+
ucli oas <service> invokeapi <api> [选项]
|
|
166
163
|
```
|
|
167
164
|
|
|
168
165
|
| 参数 | 必填 | 说明 |
|
|
169
166
|
|------|------|------|
|
|
170
|
-
| `--
|
|
171
|
-
| `--
|
|
172
|
-
| `--params` | 否 | JSON 字符串(路径参数、查询参数、请求体合并传入) |
|
|
167
|
+
| `--data` | 否 | 请求体(JSON 字符串或 @文件名) |
|
|
168
|
+
| `--params` | 否 | JSON 字符串(路径参数、查询参数合并传入) |
|
|
173
169
|
| `--format` | 否 | 输出格式:`json`(默认)、`table`、`yaml` |
|
|
174
170
|
| `--query` | 否 | JMESPath 表达式,用于过滤响应 |
|
|
175
171
|
| `--machine` | 否 | 结构化 JSON 信封输出(Agent 友好模式) |
|
|
@@ -179,108 +175,97 @@ ucli run --service <name> --operation <operationId> [选项]
|
|
|
179
175
|
|
|
180
176
|
```bash
|
|
181
177
|
# GET 带路径参数
|
|
182
|
-
ucli
|
|
183
|
-
--params '{"petId": 42}'
|
|
178
|
+
ucli oas petstore invokeapi getPetById --params '{"petId": 42}'
|
|
184
179
|
|
|
185
180
|
# POST 带请求体
|
|
186
|
-
ucli
|
|
187
|
-
--
|
|
188
|
-
--format json
|
|
181
|
+
ucli oas payments invokeapi createPayment \
|
|
182
|
+
--data '{"amount": 100, "currency": "CNY", "recipient": "acct_123"}'
|
|
189
183
|
|
|
190
184
|
# 使用 JMESPath 过滤结果
|
|
191
|
-
ucli
|
|
185
|
+
ucli oas inventory invokeapi listProducts \
|
|
192
186
|
--params '{"category": "electronics"}' \
|
|
193
187
|
--query 'items[?price < `500`].name'
|
|
194
188
|
|
|
195
|
-
# 从文件读取参数
|
|
196
|
-
ucli run --service crm --operation createContact \
|
|
197
|
-
--params "@./contact.json"
|
|
198
|
-
|
|
199
189
|
# Agent 友好结构化输出
|
|
200
|
-
ucli
|
|
190
|
+
ucli oas payments invokeapi listTransactions --machine
|
|
201
191
|
|
|
202
192
|
# 预览请求但不执行
|
|
203
|
-
ucli
|
|
193
|
+
ucli oas payments invokeapi createPayment --dry-run \
|
|
204
194
|
--data '{"amount": 5000, "currency": "CNY"}'
|
|
205
195
|
```
|
|
206
196
|
|
|
207
197
|
---
|
|
208
198
|
|
|
209
|
-
### `
|
|
199
|
+
### `listmcp`
|
|
210
200
|
|
|
211
201
|
列出当前群组可访问的所有 MCP 服务器。
|
|
212
202
|
|
|
213
203
|
```bash
|
|
214
|
-
ucli
|
|
204
|
+
ucli listmcp [--format table|json|yaml]
|
|
215
205
|
```
|
|
216
206
|
|
|
217
207
|
---
|
|
218
208
|
|
|
219
|
-
### `mcp
|
|
209
|
+
### `mcp <server> listtool`
|
|
220
210
|
|
|
221
211
|
列出指定 MCP 服务器上的可用工具。
|
|
222
212
|
|
|
223
213
|
```bash
|
|
224
|
-
ucli mcp
|
|
214
|
+
ucli mcp <server> listtool [--format table|json|yaml]
|
|
225
215
|
```
|
|
226
216
|
|
|
227
217
|
---
|
|
228
218
|
|
|
229
|
-
### `mcp
|
|
219
|
+
### `mcp <server> toolinfo <tool>`
|
|
230
220
|
|
|
231
221
|
查看 MCP 服务器上指定工具的详细参数模式。
|
|
232
222
|
|
|
233
223
|
```bash
|
|
234
|
-
ucli mcp
|
|
224
|
+
ucli mcp <server> toolinfo <tool> [--json]
|
|
235
225
|
```
|
|
236
226
|
|
|
237
227
|
| 参数 | 说明 |
|
|
238
228
|
|------|------|
|
|
239
|
-
| `<server
|
|
240
|
-
| `<tool
|
|
229
|
+
| `<server>` | MCP 服务器名称(来自 `listmcp`) |
|
|
230
|
+
| `<tool>` | 工具名称(来自 `mcp <server> listtool`) |
|
|
241
231
|
| `--json` | 以 JSON 格式输出完整模式(适合 Agent 消费) |
|
|
242
232
|
|
|
243
233
|
**示例:**
|
|
244
234
|
|
|
245
235
|
```bash
|
|
246
236
|
# 人类可读的工具描述
|
|
247
|
-
ucli mcp
|
|
237
|
+
ucli mcp weather toolinfo get_forecast
|
|
248
238
|
|
|
249
239
|
# JSON 模式(适合 Agent 内省)
|
|
250
|
-
ucli mcp
|
|
240
|
+
ucli mcp weather toolinfo get_forecast --json
|
|
251
241
|
```
|
|
252
242
|
|
|
253
243
|
---
|
|
254
244
|
|
|
255
|
-
### `mcp
|
|
245
|
+
### `mcp <server> invoketool <tool>`
|
|
256
246
|
|
|
257
247
|
在 MCP 服务器上执行指定工具。
|
|
258
248
|
|
|
259
249
|
```bash
|
|
260
|
-
ucli mcp
|
|
250
|
+
ucli mcp <server> invoketool <tool> [--data <json>] [--json]
|
|
261
251
|
```
|
|
262
252
|
|
|
263
|
-
参数以 `key=value` 形式传入,或使用 `--input-json` 直接传入 JSON 对象。
|
|
264
|
-
|
|
265
253
|
| 参数 | 说明 |
|
|
266
254
|
|------|------|
|
|
255
|
+
| `--data` | 以 JSON 对象形式传入工具参数 |
|
|
267
256
|
| `--json` | 结构化 JSON 输出 |
|
|
268
|
-
| `--input-json` | 以 JSON 对象形式传入工具参数(Agent 推荐) |
|
|
269
257
|
|
|
270
258
|
**示例:**
|
|
271
259
|
|
|
272
260
|
```bash
|
|
273
261
|
# 调用天气工具
|
|
274
|
-
ucli mcp
|
|
262
|
+
ucli mcp weather invoketool get_forecast --data '{"location": "北京", "units": "metric"}'
|
|
275
263
|
|
|
276
264
|
# 调用搜索工具
|
|
277
|
-
ucli mcp
|
|
278
|
-
|
|
279
|
-
# 以 JSON 输入调用(Agent 推荐)
|
|
280
|
-
ucli mcp run weather get_forecast --input-json '{"location": "北京", "units": "metric"}'
|
|
265
|
+
ucli mcp search-server invoketool web_search --data '{"query": "ucli MCP", "limit": 5}'
|
|
281
266
|
|
|
282
267
|
# 获取结构化 JSON 输出
|
|
283
|
-
ucli mcp
|
|
268
|
+
ucli mcp weather invoketool get_forecast --json --data '{"location": "北京"}'
|
|
284
269
|
```
|
|
285
270
|
|
|
286
271
|
---
|
|
@@ -321,7 +306,7 @@ ucli help
|
|
|
321
306
|
- OAS 条目以 JSON 文件形式缓存到 OS 临时目录(`ucli/` 子目录)
|
|
322
307
|
- 每个条目的缓存 TTL 由服务端管理员通过 `cacheTtl` 字段设置(单位:秒)
|
|
323
308
|
- 过期条目在下次访问时自动重新拉取
|
|
324
|
-
- 强制刷新:`ucli refresh` 或在 `
|
|
309
|
+
- 强制刷新:`ucli refresh` 或在 `listoas` 时添加 `--refresh`
|
|
325
310
|
|
|
326
311
|
## 认证处理
|
|
327
312
|
|
|
@@ -346,40 +331,43 @@ AI 智能体将 `ucli` 作为技能使用时,推荐的工作流程:
|
|
|
346
331
|
|
|
347
332
|
```bash
|
|
348
333
|
# 第一步:发现可用服务
|
|
349
|
-
ucli
|
|
334
|
+
ucli listoas --format json
|
|
350
335
|
|
|
351
336
|
# 第二步:查看服务支持的操作
|
|
352
|
-
ucli
|
|
337
|
+
ucli oas <service-name> listapi --format json
|
|
338
|
+
|
|
339
|
+
# 第三步:查看具体 API 的详细参数
|
|
340
|
+
ucli oas <service-name> apiinfo <api>
|
|
353
341
|
|
|
354
|
-
#
|
|
355
|
-
ucli
|
|
356
|
-
--
|
|
342
|
+
# 第四步:预览请求(dry-run,不执行)
|
|
343
|
+
ucli oas <service-name> invokeapi <api> --dry-run \
|
|
344
|
+
--data '{ ... }'
|
|
357
345
|
|
|
358
|
-
#
|
|
359
|
-
ucli
|
|
360
|
-
--
|
|
346
|
+
# 第五步:执行操作并获取结构化输出
|
|
347
|
+
ucli oas <service-name> invokeapi <api> \
|
|
348
|
+
--data '{ ... }' --machine
|
|
361
349
|
|
|
362
|
-
#
|
|
363
|
-
ucli
|
|
350
|
+
# 第六步:用 JMESPath 过滤结果
|
|
351
|
+
ucli oas inventory invokeapi listProducts \
|
|
364
352
|
--query 'items[?inStock == `true`] | [0:5]'
|
|
365
353
|
|
|
366
|
-
#
|
|
367
|
-
PRODUCT_ID=$(ucli
|
|
354
|
+
# 第七步:链式操作(将前一个结果作为下一个的输入)
|
|
355
|
+
PRODUCT_ID=$(ucli oas inventory invokeapi listProducts \
|
|
368
356
|
--query 'items[0].id' | tr -d '"')
|
|
369
|
-
ucli
|
|
370
|
-
--
|
|
357
|
+
ucli oas orders invokeapi createOrder \
|
|
358
|
+
--data "{\"productId\": \"$PRODUCT_ID\", \"quantity\": 1}"
|
|
371
359
|
|
|
372
|
-
#
|
|
373
|
-
ucli mcp
|
|
374
|
-
ucli mcp
|
|
360
|
+
# 第八步:MCP — 查看工具参数模式,然后以 JSON 输入调用
|
|
361
|
+
ucli mcp weather toolinfo get_forecast --json
|
|
362
|
+
ucli mcp weather invoketool get_forecast --data '{"location": "北京", "units": "metric"}'
|
|
375
363
|
```
|
|
376
364
|
|
|
377
365
|
**智能体使用建议:**
|
|
378
|
-
- 始终先运行 `
|
|
366
|
+
- 始终先运行 `ucli listoas` 发现可用服务
|
|
379
367
|
- 使用 `--machine` 获取结构化信封输出
|
|
380
368
|
- 使用 `--dry-run` 预览请求,避免误操作
|
|
381
|
-
- 使用 `mcp
|
|
382
|
-
- 使用 `--
|
|
369
|
+
- 使用 `ucli mcp <server> toolinfo <tool> --json` 发现工具参数模式
|
|
370
|
+
- 使用 `--data` 传入 JSON 输入(适合复杂或嵌套参数)
|
|
383
371
|
- 使用 `--format json` 方便程序解析
|
|
384
372
|
- 使用 `--query` 配合 JMESPath 提取特定字段
|
|
385
373
|
- 注意列表操作的分页字段(`nextPage`、`totalCount`)
|
|
@@ -390,9 +378,9 @@ ucli mcp run weather get_forecast --input-json '{"location": "北京", "units":
|
|
|
390
378
|
| 错误 | 可能原因 | 解决方法 |
|
|
391
379
|
|------|---------|---------|
|
|
392
380
|
| `Unauthorized (401)` | JWT 已过期或被吊销 | 联系管理员获取新令牌 |
|
|
393
|
-
| `Service not found` | 服务名拼写错误或不在当前群组 | 运行 `
|
|
394
|
-
| `Operation not found` | 无效的 `operationId` | 运行 `
|
|
395
|
-
| `MCP server not found` | MCP 服务器名拼写错误或不在当前群组 | 运行 `ucli
|
|
396
|
-
| `Tool not found` | 无效的工具名 | 运行 `ucli mcp
|
|
381
|
+
| `Service not found` | 服务名拼写错误或不在当前群组 | 运行 `ucli listoas` 查看可用服务 |
|
|
382
|
+
| `Operation not found` | 无效的 `operationId` | 运行 `ucli oas <service> listapi` 查看有效操作 |
|
|
383
|
+
| `MCP server not found` | MCP 服务器名拼写错误或不在当前群组 | 运行 `ucli listmcp` 查看可用服务器 |
|
|
384
|
+
| `Tool not found` | 无效的工具名 | 运行 `ucli mcp <server> listtool` 查看可用工具 |
|
|
397
385
|
| `Connection refused` | 服务器未运行或 URL 错误 | 用 `ucli configure` 检查服务器 URL |
|
|
398
386
|
| `Cache error` | 临时目录权限问题 | 运行 `ucli refresh` 重置缓存 |
|