@tronsfey/ucli 0.5.0 → 0.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tronsfey/ucli",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "ucli — proxy OpenAPI and MCP services for AI agents",
5
5
  "keywords": [
6
6
  "openapi",
@@ -37,18 +37,18 @@
37
37
  "clean": "rm -rf dist"
38
38
  },
39
39
  "dependencies": {
40
- "@tronsfey/openapi2cli": "1.0.13",
40
+ "@tronsfey/openapi2cli": "1.0.17",
41
41
  "axios": "^1.8.4",
42
42
  "commander": "^12.1.0",
43
43
  "conf": "^13.1.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@modelcontextprotocol/server-filesystem": "2026.1.14",
47
- "@tronsfey/mcp2cli": "1.0.1",
47
+ "@tronsfey/mcp2cli": "1.3.0",
48
48
  "@types/node": "^22.14.0",
49
49
  "tsup": "^8.4.0",
50
50
  "tsx": "^4.19.3",
51
- "typescript": "^5.7.3",
51
+ "typescript": "~5.8.3",
52
52
  "vitest": "^3.1.1"
53
53
  }
54
54
  }
package/skill.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ucli
3
3
  description: Proxy OpenAPI and MCP services for AI agents — discover, inspect, and invoke APIs with automatic credential injection.
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  metadata:
6
6
  openclaw:
7
7
  emoji: "🔗"
@@ -23,8 +23,73 @@ Use `ucli` whenever you need to call any external business API or MCP server too
23
23
  - Proxies registered OpenAPI services on your behalf
24
24
  - Handles authentication automatically (credentials are never exposed to you)
25
25
  - Returns structured JSON output suitable for further processing
26
+ - Supports `--output json` for fully structured envelopes (success/error)
26
27
 
27
- **When to use:** Any time you need to interact with external services (business APIs, data sources, microservices). Always check available services first with `ucli services list`.
28
+ **When to use:** Any time you need to interact with external services (business APIs, data sources, microservices). Always start with `ucli introspect` to discover all capabilities in a single call.
29
+
30
+ ---
31
+
32
+ ## Agent Methodology — OODA Loop
33
+
34
+ ucli is designed around the **Observe → Orient → Decide → Act** (OODA) loop for AI agent workflows:
35
+
36
+ 1. **Observe** — Discover all available capabilities with `ucli introspect`
37
+ 2. **Orient** — Understand specific operations with `ucli services info <name>` or `ucli mcp tools <server>`
38
+ 3. **Decide** — Choose the right operation and parameters based on the task
39
+ 4. **Act** — Execute with `ucli run` or `ucli mcp run`
40
+
41
+ ### Recommended First Call
42
+
43
+ ```bash
44
+ ucli introspect --output json
45
+ ```
46
+
47
+ This returns a complete manifest in a single call:
48
+ ```json
49
+ {
50
+ "success": true,
51
+ "data": {
52
+ "version": "1",
53
+ "services": [
54
+ { "name": "payments", "description": "...", "authType": "bearer", ... }
55
+ ],
56
+ "mcpServers": [
57
+ { "name": "weather", "description": "...", "transport": "http", ... }
58
+ ],
59
+ "commands": [
60
+ { "name": "run", "description": "...", "usage": "...", "examples": [...] }
61
+ ]
62
+ }
63
+ }
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Global Flags
69
+
70
+ | Flag | Description |
71
+ |------|-------------|
72
+ | `--output json` | Wrap ALL output in structured `{ success, data/error }` envelopes |
73
+ | `--debug` | Enable verbose debug logging |
74
+ | `-v, --version` | Show version number |
75
+
76
+ ### Structured Output Mode (`--output json`)
77
+
78
+ When `--output json` is passed, every command emits exactly one JSON object to stdout:
79
+
80
+ **Success:**
81
+ ```json
82
+ { "success": true, "data": <result> }
83
+ ```
84
+
85
+ **Error:**
86
+ ```json
87
+ { "success": false, "error": { "code": 6, "message": "Service not found: foo", "hint": "Run: ucli services list" } }
88
+ ```
89
+
90
+ Error codes: `0`=success, `1`=general, `2`=usage, `3`=config, `4`=auth, `5`=connectivity, `6`=not-found, `7`=server-error.
91
+
92
+ **Always use `--output json` when calling ucli from code or as an AI agent.** This ensures you can reliably parse both success and error results.
28
93
 
29
94
  ---
30
95
 
@@ -45,6 +110,11 @@ inventory api_key Product inventory management
45
110
  crm oauth2_cc Customer relationship management
46
111
  ```
47
112
 
113
+ For machine-readable output:
114
+ ```bash
115
+ ucli services list --output json
116
+ ```
117
+
48
118
  ---
49
119
 
50
120
  ## Step 2 — Inspect a Service's Operations
@@ -75,6 +145,33 @@ ucli run <service> <operation> [options]
75
145
  | `--format json\|table\|yaml` | Output format (default: json) | `--format table` |
76
146
  | `--query <jmespath>` | Filter response with JMESPath | `--query "items[*].id"` |
77
147
  | `--data <json\|@file>` | Request body for POST/PUT/PATCH | `--data '{"amount":100}'` |
148
+ | `--machine` | Structured JSON envelope output (agent-friendly) | `--machine` |
149
+ | `--dry-run` | Preview the HTTP request without executing (implies `--machine`) | `--dry-run` |
150
+
151
+ ### Agent-Friendly Mode (`--machine`)
152
+
153
+ Use `--machine` for structured JSON envelope output that agents can parse deterministically:
154
+
155
+ ```bash
156
+ # Structured success output
157
+ ucli run payments listTransactions --machine
158
+ # → { "success": true, "data": {...}, "meta": { "durationMs": 42 } }
159
+
160
+ # Structured error output
161
+ ucli run payments getTransaction --transactionId invalid --machine
162
+ # → { "success": false, "error": { "type": "HttpClientError", "message": "...", "statusCode": 404 } }
163
+ ```
164
+
165
+ ### Dry-Run Mode (`--dry-run`)
166
+
167
+ Preview the HTTP request that *would* be sent, without actually executing it:
168
+
169
+ ```bash
170
+ ucli run payments createCharge --dry-run --data '{"amount": 5000, "currency": "USD"}'
171
+ # → { "method": "POST", "url": "https://api.example.com/charges", "headers": {...}, "body": {...} }
172
+ ```
173
+
174
+ This is useful for verifying parameters before making destructive or costly API calls.
78
175
 
79
176
  ### Examples
80
177
 
@@ -132,25 +229,32 @@ By default, `ucli run` returns JSON. You can:
132
229
  ## Complete Workflow Example
133
230
 
134
231
  ```bash
135
- # 1. Discover services
136
- ucli services list
232
+ # 1. Discover all capabilities (single call)
233
+ ucli introspect --output json
137
234
 
138
- # 2. Check what operations are available on "payments"
139
- ucli services info payments
235
+ # 2. Inspect a specific service's operations
236
+ ucli services info payments --output json
140
237
 
141
- # 3. List recent transactions
142
- ucli run payments listTransactions --query "transactions[*].{id:id,amount:amount,status:status}"
238
+ # 3. Preview a request (dry-run, no execution)
239
+ ucli run payments createCharge --dry-run --data '{"amount": 9900, "currency": "USD"}'
143
240
 
144
- # 4. Get a specific transaction
241
+ # 4. Execute with structured output (--machine)
242
+ ucli run payments listTransactions --machine --query "transactions[*].{id:id,amount:amount,status:status}"
243
+
244
+ # 5. Get a specific transaction
145
245
  ucli run payments getTransaction --transactionId txn_abc123
146
246
 
147
- # 5. Create a new charge
247
+ # 6. Create a new charge
148
248
  ucli run payments createCharge --data '{
149
249
  "amount": 9900,
150
250
  "currency": "USD",
151
251
  "customerId": "cus_xyz789",
152
252
  "description": "Monthly subscription"
153
253
  }'
254
+
255
+ # 7. MCP: describe a tool's parameters, then call it
256
+ ucli mcp describe weather get_forecast --json
257
+ ucli mcp run weather get_forecast --input-json '{"location": "New York", "units": "metric"}'
154
258
  ```
155
259
 
156
260
  ---
@@ -166,11 +270,21 @@ ucli run payments createCharge --data '{
166
270
  | `429 Too Many Requests` | Rate limit exceeded | Wait and retry |
167
271
  | `5xx Server Error` | Upstream service error | Retry once; if persistent, report to the service owner |
168
272
 
273
+ ### Error Recovery Strategy for Agents
274
+
275
+ 1. **Parse the exit code** — non-zero means failure (codes 1–7 have specific meanings)
276
+ 2. **When using `--output json`** — check `success` field; on failure read `error.hint`
277
+ 3. **Retry logic** — on `code: 5` (connectivity) or `code: 7` (server error), retry once after a brief wait
278
+ 4. **Re-discover** — on `code: 6` (not found), re-run `ucli introspect` to refresh your capability model
279
+
169
280
  **On persistent errors:**
170
281
  ```bash
171
282
  # Refresh the local OAS cache (may resolve stale spec issues)
172
283
  ucli refresh
173
284
 
285
+ # Run diagnostics
286
+ ucli doctor --output json
287
+
174
288
  # Then retry the operation
175
289
  ucli run <service> <operation>
176
290
  ```
@@ -190,7 +304,10 @@ ucli mcp list
190
304
  # Step 2: Inspect a server's available tools
191
305
  ucli mcp tools <server-name>
192
306
 
193
- # Step 3: Run a tool (args as key=value pairs)
307
+ # Step 3: Describe a specific tool's schema (parameters, types)
308
+ ucli mcp describe <server-name> <tool-name>
309
+
310
+ # Step 4: Run a tool (args as key=value pairs)
194
311
  ucli mcp run <server-name> <tool-name> [key=value ...]
195
312
  ```
196
313
 
@@ -200,8 +317,37 @@ ucli mcp run <server-name> <tool-name> [key=value ...]
200
317
  |---------|-------------|
201
318
  | `ucli mcp list` | List all MCP servers available to your group |
202
319
  | `ucli mcp tools <server>` | List tools available on the server |
320
+ | `ucli mcp describe <server> <tool>` | Show detailed parameter schema for a tool |
203
321
  | `ucli mcp run <server> <tool> [args...]` | Execute a tool on the server |
204
322
 
323
+ ### Tool Introspection (`mcp describe`)
324
+
325
+ Before calling a tool, use `mcp describe` to discover its parameters:
326
+
327
+ ```bash
328
+ # Human-readable description
329
+ ucli mcp describe weather get_forecast
330
+
331
+ # JSON schema (for agent consumption)
332
+ ucli mcp describe weather get_forecast --json
333
+ ```
334
+
335
+ ### JSON Input Mode (`--input-json`)
336
+
337
+ For agent callers, use `--input-json` to pass tool arguments as a JSON object (bypasses CLI flag parsing):
338
+
339
+ ```bash
340
+ ucli mcp run weather get_forecast --input-json '{"location": "New York", "units": "metric"}'
341
+ ```
342
+
343
+ ### JSON Output Mode (`--json`)
344
+
345
+ Use `--json` on `mcp run` to get structured JSON envelope output:
346
+
347
+ ```bash
348
+ ucli mcp run weather get_forecast --json location="New York"
349
+ ```
350
+
205
351
  ### Examples
206
352
 
207
353
  ```bash
@@ -211,30 +357,46 @@ ucli mcp list
211
357
  # See what tools are available on "weather" server
212
358
  ucli mcp tools weather
213
359
 
214
- # Call the get_forecast tool with arguments
360
+ # Describe the get_forecast tool's parameters
361
+ ucli mcp describe weather get_forecast
362
+
363
+ # Call the get_forecast tool with key=value arguments
215
364
  ucli mcp run weather get_forecast location="New York" units=metric
216
365
 
217
- # Call a search tool
218
- ucli mcp run search-server web_search query="ucli documentation" limit=5
366
+ # Call with JSON input (preferred for agents)
367
+ ucli mcp run weather get_forecast --input-json '{"location": "New York", "units": "metric"}'
368
+
369
+ # Call a search tool with structured JSON output
370
+ ucli mcp run search-server web_search --json query="ucli documentation" limit=5
219
371
  ```
220
372
 
221
373
  ---
222
374
 
223
375
  ## Tips for AI Agents
224
376
 
225
- 1. **Always discover first.** Don't guess service or operation names run `ucli services list` then `ucli services info <name>`.
377
+ 1. **Start with `ucli introspect`.** This gives you a complete picture of all services, MCP servers, and available commands in a single call. Don't make multiple discovery calls when one will do.
378
+
379
+ 2. **Always use `--output json`.** This wraps every result in `{ success: true, data }` or `{ success: false, error }`. Never parse human-readable text output.
226
380
 
227
- 2. **Use JSON output.** Default `--format json` gives you machine-parseable data. Only switch to `table` when presenting to humans.
381
+ 3. **Use `--machine` for operation execution.** When running API operations, use `--machine` to get structured envelope output with metadata (timing, method, path). This is more reliable than parsing raw API responses.
228
382
 
229
- 3. **Use `--query` to extract.** Instead of parsing the entire response, use JMESPath to extract exactly what you need.
383
+ 4. **Preview before mutating with `--dry-run`.** Before making POST/PUT/DELETE calls, use `--dry-run` to verify the request URL, headers, and body without actually executing. This prevents accidental mutations.
230
384
 
231
- 4. **Chain operations.** Use the output of one operation as input to the next:
385
+ 5. **Use `--query` to extract.** Instead of parsing the entire response, use JMESPath to extract exactly what you need.
386
+
387
+ 6. **Use `mcp describe` before `mcp run`.** Use `ucli mcp describe <server> <tool> --json` to discover a tool's full parameter schema before calling it. This avoids parameter errors.
388
+
389
+ 7. **Use `--input-json` for MCP tool calls.** When calling MCP tools programmatically, prefer `--input-json '{"key": "value"}'` over `key=value` pairs. JSON input is more reliable for complex or nested arguments.
390
+
391
+ 8. **Chain operations.** Use the output of one operation as input to the next:
232
392
  ```bash
233
393
  # Get customer ID, then create a charge
234
394
  CUSTOMER_ID=$(ucli run crm findCustomer --email user@example.com --query "id" | tr -d '"')
235
395
  ucli run payments createCharge --data "{\"customerId\": \"$CUSTOMER_ID\", \"amount\": 1000}"
236
396
  ```
237
397
 
238
- 5. **Check pagination.** Large result sets may be paginated. Look for `nextPage`, `cursor`, or `Link` headers in the response.
398
+ 9. **Check pagination.** Large result sets may be paginated. Look for `nextPage`, `cursor`, or `Link` headers in the response.
399
+
400
+ 10. **Use exit codes for control flow.** Exit code `0` = success, non-zero = failure. Use `--output json` for richer error context.
239
401
 
240
- 6. **Validate before mutating.** For destructive operations (DELETE, large updates), confirm the resource exists and is correct before proceeding.
402
+ 11. **Re-introspect on capability changes.** If you encounter a `not found` error for a service that should exist, run `ucli refresh` then `ucli introspect` to refresh your model of available capabilities.