You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78-26Lines changed: 78 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,50 @@
1
1
## OpenAPI to CLI (ocli)
2
2
3
-
`openapi-to-cli` (short `ocli`) is a TypeScript CLI concept that turns any HTTP API described by an OpenAPI/Swagger spec into a set of CLI commands.
3
+
`openapi-to-cli` (short `ocli`) is a TypeScript CLI that turns any HTTP API described by an OpenAPI/Swagger spec into a set of CLI commands — at runtime, without code generation.
4
4
5
5
-**Input**: OpenAPI/Swagger spec (URL or file) plus API connection settings.
6
6
-**Output**: an executable `ocli` binary where each API operation is exposed as a dedicated subcommand.
7
7
8
-
Unlike [openapi-to-mcp](https://github.com/EvilFreelancer/openapi-to-mcp), which starts an MCP server with tools, `ocli` provides a direct command line interface.
8
+
Unlike [openapi-to-mcp](https://github.com/EvilFreelancer/openapi-to-mcp), which starts an MCP server with tools, `ocli` provides a direct command-line interface.
9
+
10
+
### Why convert OpenAPI spec to CLI?
11
+
12
+
The trend is clear: **CLI commands are cheaper and more native than MCP tools** for AI agents.
13
+
14
+
| Factor | MCP Tools | CLI Commands |
15
+
|--------|-----------|--------------|
16
+
|**Token cost**| Each tool call requires full JSON schema in context on every request | CLI commands are invoked by name with flags — minimal token overhead |
17
+
|**Startup overhead**| MCP server must be running, connected via transport layer | Single process, instant execution, zero transport cost |
18
+
|**Composability**| Tools are isolated in MCP server scope | CLI commands pipe, chain, and integrate with shell scripts natively |
19
+
|**Agent compatibility**| Requires MCP-aware client (Claude, Cursor, etc.) | Any agent that can run shell commands — universal |
20
+
|**Discoverability**| Agent must hold all tool schemas in context window |`--help` for quick lookup, `search --query` for BM25-ranked discovery |
21
+
|**Multi-API**| One MCP server per API, each consuming context | Multiple profiles in one binary, switch with `ocli use <profile>`|
22
+
|**Endpoint scoping**| All tools exposed at once, no per-session filtering | Per-profile `--include/--exclude-endpoints` — same API, different command sets for different roles |
23
+
|**Debugging**| Opaque transport, hard to inspect | Plain HTTP requests, visible in terminal |
24
+
25
+
When an agent has access to 200+ API endpoints, loading all of them as MCP tools burns thousands of tokens per turn. With `ocli`, the agent calls `ocli search --query "upload files"` to discover relevant commands, then executes them directly. The context window stays clean.
26
+
27
+
**Bottom line**: if your agent talks to HTTP APIs, CLI is the most token-efficient and portable interface available today.
28
+
29
+
### Comparison with [openapi-cli-generator](https://github.com/danielgtaylor/openapi-cli-generator)
30
+
31
+
| Feature | ocli | openapi-cli-generator |
32
+
|---------|:----:|:---------------------:|
33
+
| Runtime interpretation (no codegen) | ✅ | ❌ |
34
+
| Zero-setup install (`npx`) | ✅ | ❌ |
35
+
| Multiple API profiles in one binary | ✅ | ❌ |
36
+
| Multiple endpoint sets per API | ✅ | ❌ |
37
+
| BM25 command search | ✅ | ❌ |
38
+
| Regex command search | ✅ | ❌ |
39
+
| Per-profile endpoint filtering | ✅ | ❌ |
40
+
| Spec caching with refresh | ✅ | ❌ |
41
+
| Add new API without recompile | ✅ | ❌ |
42
+
| Basic / Bearer auth | ✅ | ✅ |
43
+
| OAuth2 / Auth0 | ❌ | ✅ |
44
+
| Response JMESPath filtering | ❌ | ✅ |
45
+
| Syntax-highlighted output | ❌ | ✅ |
46
+
| Middleware / waiters | ❌ | ✅ |
47
+
| Active project | ✅ | ❌ (deprecated) |
9
48
10
49
### High level idea
11
50
@@ -43,6 +82,22 @@ ocli use myapi
43
82
ocli messages --limit 10
44
83
```
45
84
85
+
### Command search
86
+
87
+
When the API surface is too large for `--help`, use the built-in search:
88
+
89
+
```bash
90
+
# BM25 natural language search
91
+
ocli search --query "upload files"
92
+
ocli search -q "list messages" --limit 5
93
+
94
+
# Regex pattern matching
95
+
ocli search --regex "admin.*get"
96
+
ocli search -r "messages" -n 3
97
+
```
98
+
99
+
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.
100
+
46
101
### Installation and usage via npm and npx
47
102
48
103
To use `ocli` locally without installing it globally you can rely on `npx`:
repositories GET /repositories List public repositories
56
+
installation_repositories GET /installation/repositories List repositories accessible to the app installation
57
+
user_migrations_migration_id_repositories GET /user/migrations/{migration_id}/repositories List repositories for a user migration
58
+
user_installations_installation_id_repositories GET /user/installations/{installation_id}/repositories List repositories accessible to the user access token
59
+
orgs_org_migrations_migration_id_repositories GET /orgs/{org}/migrations/{migration_id}/repositories List repositories in an organization migration
repos_owner_repo_pulls_pull_number_reviews_get GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews List reviews for a pull request
68
+
repos_owner_repo_pulls_pull_number_reviews_post POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews Create a review for a pull request
69
+
repos_owner_repo_pulls_pull_number_reviews_review_id_get GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id} Get a review for a pull request
70
+
repos_owner_repo_pulls_pull_number_reviews_review_id_put PUT /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id} Update a review for a pull request
71
+
repos_owner_repo_pulls_pull_number_reviews_review_id_delete DELETE /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id} Delete a pending review for a pull request
repos_owner_repo_issues_issue_number_comments_post POST /repos/{owner}/{repo}/issues/{issue_number}/comments Create an issue comment
80
+
repos_owner_repo_issues_issue_number_reactions_post POST /repos/{owner}/{repo}/issues/{issue_number}/reactions Create reaction for an issue
81
+
repos_owner_repo_issues_post POST /repos/{owner}/{repo}/issues Create an issue
82
+
repos_owner_repo_issues_comments_comment_id_reactions_post POST /repos/{owner}/{repo}/issues/comments/{comment_id}/reactions Create reaction for an issue comment
83
+
repos_owner_repo_issues_issue_number_get GET /repos/{owner}/{repo}/issues/{issue_number} Get an issue
orgs_org_actions_permissions_workflow_get GET /orgs/{org}/actions/permissions/workflow Get default workflow permissions for an organization
92
+
orgs_org_actions_permissions_workflow_put PUT /orgs/{org}/actions/permissions/workflow Set default workflow permissions for an organization
93
+
repos_owner_repo_actions_permissions_workflow_get GET /repos/{owner}/{repo}/actions/permissions/workflow Get default workflow permissions for a repository
94
+
repos_owner_repo_actions_permissions_workflow_put PUT /repos/{owner}/{repo}/actions/permissions/workflow Set default workflow permissions for a repository
95
+
repos_owner_repo_actions_workflows_workflow_id_runs GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs List workflow runs for a workflow
96
+
```
97
+
98
+
### `ocli search --regex "gist" --limit 5`
99
+
100
+
```
101
+
Found 5 command(s):
102
+
103
+
gists_get GET /gists List gists for the authenticated user
104
+
gists_post POST /gists Create a gist
105
+
gists_public GET /gists/public List public gists
106
+
gists_starred GET /gists/starred List starred gists
0 commit comments