展示HN:CLI-use – 一条命令将任何MCP服务器转变为CLI

1作者: justvugg5 天前原帖
大家好, 我开发了 cli-use,这是一个小型的 Python 工具,可以将任何 MCP 服务器转变为原生的命令行界面(CLI)。 这个想法很简单: HTTP 有 curl,Docker 有 docker,Kubernetes 有 kubectl —— MCP 也应该有一个原生的客户端。 我为什么要做这个: MCP 很有用,但通过代理使用时存在一些开销: - 每个会话都需要支付模式发现的成本 - 每次调用都带有 JSON-RPC 的封装 - 响应通常是冗长的 JSON,而有用的输出往往只是一两行 cli-use 将这些转换为简洁的命令行界面,使工具可以像普通的 shell 命令一样被调用。 示例: ``` pip install cli-use cli-use add fs /tmp cli-use fs list_directory --path /tmp ``` 之后,MCP 服务器的行为就像一个常规的命令行界面: - 代理可以使用 - 人类可以使用 - 可以通过脚本 / subprocess.run 使用 - 可以与 grep、head、xargs 等工具组合使用 示例: ``` cli-use fs search_files --path /tmp --pattern "*.md" | head cli-use fs read_text_file --path /tmp/notes.md | grep TODO ``` 我非常关注代理的易用性。 每次添加操作都会生成一个 SKILL.md 文件以及一个指向 AGENTS.md 的指针,因此在一个仓库中工作的代理可以自动发现并使用 CLI。 一些细节: - 纯 Python 标准库 - 零运行时依赖 - 持久别名 - 兼容 npm、pip、pipx 和本地 MCP 服务器 - 内置常见 MCP 服务器的注册表 我还对真实的 @modelcontextprotocol/server-filesystem 服务器(14 个工具)进行了基准测试。根据会话大小,令牌节省约为 60%–80%,主要是通过消除模式开销和冗长的请求/响应封装。 它仍处于 alpha 阶段,但已经可以使用。 仓库链接: [https://github.com/JustVugg/cli-use](https://github.com/JustVugg/cli-use)
查看原文
Hi everyone,<p>I built cli-use, a small Python tool that turns any MCP server into a native CLI.<p>The idea is simple: HTTP has curl, Docker has docker, Kubernetes has kubectl — MCP should have a shell-native client too.<p>Why I made it:<p>MCP is useful, but using it through agents has overhead:<p>every session pays schema discovery cost every call carries JSON-RPC framing responses are often verbose JSON when the useful output is just a line or two<p>cli-use converts that into a terse CLI so tools can be called like normal shell commands.<p>Example:<p>pip install cli-use cli-use add fs &#x2F;tmp cli-use fs list_directory --path &#x2F;tmp<p>After that, the MCP server behaves like a regular CLI:<p>usable by agents usable by humans usable from scripts &#x2F; subprocess.run composable with grep, head, xargs, etc.<p>Example:<p>cli-use fs search_files --path &#x2F;tmp --pattern &quot;*.md&quot; | head cli-use fs read_text_file --path &#x2F;tmp&#x2F;notes.md | grep TODO<p>One thing I cared about a lot is agent ergonomics.<p>Every add also emits a SKILL.md plus an AGENTS.md pointer, so agents working in a repo can discover and use the CLI automatically.<p>A few details:<p>pure Python stdlib zero runtime deps persistent aliases works with npm, pip, pipx, and local MCP servers built-in registry for common MCP servers<p>I also benchmarked it against the real @modelcontextprotocol&#x2F;server-filesystem server (14 tools). Depending on session size, token savings were around 60–80%, mostly by removing schema overhead and verbose request &#x2F; response framing.<p>It’s still alpha, but already usable.<p>Repo: <a href="https:&#x2F;&#x2F;github.com&#x2F;JustVugg&#x2F;cli-use" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;JustVugg&#x2F;cli-use</a>