Skip to content

Commit ffcefa0

Browse files
authored
Merge pull request #4 from EvilFreelancer/feat/pavel-suggestions
Add custom headers, command prefix, force path params required, trans…
2 parents 72d0e10 + 6a1557a commit ffcefa0

13 files changed

Lines changed: 874 additions & 16 deletions

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ When an agent has access to 200+ API endpoints, loading all of them as MCP tools
4545
| Non-HTTP integrations (desktop apps) ||||
4646
| Session management / undo-redo ||||
4747
| JSON structured output ||||
48+
| Custom HTTP headers ||||
49+
| Command name prefix ||||
4850
| Basic / Bearer auth ||||
4951
| OAuth2 / Auth0 ||||
5052
| Response JMESPath filtering ||||
@@ -63,7 +65,9 @@ ocli profiles add myapi \
6365
--openapi-spec http://127.0.0.1:2222/openapi.json \
6466
--api-bearer-token "..." \
6567
--include-endpoints get:/messages,get:/channels \
66-
--exclude-endpoints post:/admin/secret
68+
--exclude-endpoints post:/admin/secret \
69+
--command-prefix "myapi_" \
70+
--custom-headers '{"X-Tenant":"acme","X-Request-Source":"cli"}'
6771
```
6872

6973
Alternatively, `ocli onboard` (with the same options, no profile name) creates a profile named `default`.
@@ -104,6 +108,64 @@ ocli commands -r "messages" -n 3
104108

105109
The BM25 engine (ported from [picoclaw](https://github.com/sipeed/picoclaw)) ranks commands by relevance across name, method, path, description, and parameter names. This enables agents to discover the right endpoint without loading all command schemas into context. The legacy `ocli search` command is kept as a deprecated alias and internally forwards to `ocli commands` with the same flags.
106110

111+
### Benchmark: three strategies for AI agent ↔ API interaction
112+
113+
Tested against [Swagger Petstore](https://petstore3.swagger.io/) ([OpenAPI spec](https://petstore3.swagger.io/api/v3/openapi.json)). Scaling projections use the [GitHub API](https://api.apis.guru/v2/specs/github.com/api.github.com/1.1.4/openapi.json) (845 endpoints).
114+
115+
Three strategies compared:
116+
117+
| # | Strategy | How it works | Tools in context |
118+
|---|----------|-------------|-----------------|
119+
| 1 | **MCP Naive** | All endpoints as MCP tools | N tools (one per endpoint) |
120+
| 2 | **MCP+Search** | 2 tools: `search_tools` + `call_api` | 2 tools |
121+
| 3 | **CLI (ocli)** | 1 tool: `execute_command` | 1 tool |
122+
123+
Run the benchmark yourself:
124+
125+
```bash
126+
npx ts-node benchmarks/benchmark.ts
127+
```
128+
129+
Results (19 endpoints, 15 natural-language queries):
130+
131+
```
132+
TOOL DEFINITION OVERHEAD (sent with every API request)
133+
134+
MCP Naive ██████████████████████████████ 2 945 tok (19 tools)
135+
MCP+Search ████ 346 tok (2 tools)
136+
CLI (ocli) █ 138 tok (1 tool)
137+
138+
SEARCH RESULT SIZE (3 matching endpoints)
139+
140+
MCP+Search ██████████████████████████████ 995 tok (full JSON schemas)
141+
CLI (ocli) ██ 67 tok (name + method + path)
142+
143+
SCALING: OVERHEAD PER TURN vs ENDPOINT COUNT
144+
145+
Endpoints MCP Naive MCP+Search CLI (ocli) Naive/CLI
146+
19 2 945 tok 346 tok 138 tok 21x ← Petstore
147+
100 15 415 tok 346 tok 138 tok 112x
148+
845 130 106 tok 346 tok 138 tok 943x ← GitHub API
149+
150+
VERDICT
151+
152+
Overhead/turn Search result Accuracy Server?
153+
MCP Naive 2 945 tok N/A 100% Yes
154+
MCP+Search 346 tok 995 tok/query 93% Yes
155+
CLI (ocli) 138 tok 67 tok/query 93% No
156+
157+
Monthly cost (845 endpoints, 100 tasks/day, Claude Sonnet $3/M input):
158+
MCP Naive $1 172/month
159+
MCP+Search $ 92/month
160+
CLI (ocli) $ 4/month
161+
```
162+
163+
Key insights:
164+
- **MCP Naive** is simple but scales terribly (130K tokens at 845 endpoints).
165+
- **MCP+Search** fixes the overhead but search results carry full JSON schemas — 15x larger than CLI text output.
166+
- **CLI** returns compact text, needs no MCP server, and works with any agent that has shell access.
167+
- Both search approaches share the same BM25 accuracy (93% top-3). The 7% miss is recoverable — the agent retries with a different query.
168+
107169
### Installation and usage via npm and npx
108170

109171
To use `ocli` locally without installing it globally you can rely on `npx`:
@@ -228,7 +290,9 @@ The `ocli` binary provides the following core commands:
228290
- `--api-basic-auth <user:pass>` - optional;
229291
- `--api-bearer-token <token>` - optional;
230292
- `--include-endpoints <list>` - comma-separated `method:path`;
231-
- `--exclude-endpoints <list>` - comma-separated `method:path`.
293+
- `--exclude-endpoints <list>` - comma-separated `method:path`;
294+
- `--command-prefix <prefix>` - prefix for command names (e.g. `api_` -> `api_messages`, `api_users`);
295+
- `--custom-headers <json>` - custom HTTP headers as JSON string (e.g. `'{"X-Tenant":"acme","X-Request-Source":"cli"}'`). Legacy comma-separated `key:value` format is also supported for simple values without commas.
232296

233297
- `ocli profiles add <name>` - add a new profile with the given name and cache the OpenAPI spec. Same options as `onboard` (profile name is the positional argument).
234298

@@ -271,6 +335,19 @@ The project mirrors parts of the `openapi-to-mcp` architecture but implements a
271335
- `bm25` - generic BM25 ranking engine with Robertson IDF smoothing and min-heap top-K extraction.
272336
- `cli` - entry point, argument parser, command registration, help output.
273337

338+
### Using with AI agents (Claude Code skill example)
339+
340+
An example skill file is provided in [`examples/skill-ocli-api.md`](examples/skill-ocli-api.md). Copy it to `.claude/skills/api.md` in your project to let Claude Code discover and use your API via `ocli`:
341+
342+
```bash
343+
cp examples/skill-ocli-api.md .claude/skills/api.md
344+
```
345+
346+
The agent workflow:
347+
1. `ocli commands --query "upload file"` — discover the right command
348+
2. `ocli files_content_post --help` — check parameters
349+
3. `ocli files_content_post --file ./data.csv` — execute
350+
274351
### Similar projects
275352

276353
- [openapi-cli-generator](https://github.com/danielgtaylor/openapi-cli-generator) - generates a CLI from an OpenAPI 3 specification using code generation.

0 commit comments

Comments
 (0)