通过CLI降低MCP的成本
Making MCP cheaper via CLI

原始链接: https://kanyilmaz.me/2026/02/23/cli-vs-mcp.html

使用Anthropic的MCP(托管定制计划)的AI代理可能由于工具加载方式导致API成本超支。MCP会在每个会话开始时预加载*所有*工具定义(作为冗长的JSON模式),消耗大量token。使用CLI工具和CLIHub展示了一种更有效的方法——“延迟加载”,仅在需要时加载工具详情。 CLI使用轻量级的技能列表,而不是大量的预加载模式。虽然通过“--help”命令发现工具用法最初会消耗token,但总体使用量显著减少。测试表明,即使与Anthropic较新的“工具搜索”功能相比(该功能提供了一些改进,但仍然在获取工具时加载完整的模式),CLI使用的token最多可减少94%。 CLIHub提供现有CLI的目录,并提供转换器,可以轻松地从MCP定义生成CLI,为管理代理工具提供了一种更便宜、与模型无关的替代方案,优于MCP和工具搜索。

一个 Hacker News 的讨论围绕着如何通过命令行界面 (CLI) 方法,使多调用编程 (MCP)——一种 LLM 与工具交互的方法——更具成本效益。核心思想是用更简单的 CLI 工具取代依赖模式的 MCP,从而可能减少 token 使用量和成本。 用户们争论着利弊。虽然 CLI 可能更便宜,尤其是在使用不太强大的模型时,但人们担心会丢失上下文以及需要详细的工具描述。一些人举例说明了 Playwright-CLI 与 Playwright-MCP 的区别,以及 MCPorter 等工具提供的类似功能。 一个关键点是“推 vs. 拉”的动态——LLM 是请求信息 (MCP),还是工具主动提供信息 (CLI)。 还有关于 JSON 格式的讨论,一些人认为它是一种浪费 token 的做法。 最终,这次讨论强调了寻找有效方法,为 LLM 代理提供执行任务所需的必要信息。
相关文章

原文

Every AI agent using MCP is quietly overpaying. Not on the API calls themselves - those are fine. The tax is on the instruction manual.

Before your agent can do anything useful, it needs to know what tools are available. MCP’s answer is to dump the entire tool catalog into the conversation as JSON Schema. Every tool, every parameter, every option.

CLI does the same job but cheaper.

I took an MCP server and generated a CLI from it using CLIHub. Same tools, same OAuth, same API underneath. Two things change: what loads at session start, and how the agent calls a tool.

The numbers below assume a typical setup: 6 MCP servers, 14 tools each, 84 tools total.

1. Session start

MCP dumps every tool schema into the conversation upfront. CLI uses a lightweight skill listing - just names and locations. The agent discovers details when it needs them.1

MCP loads this (~185 tokens * 84 = 15540):
{
  "name": "notion-search",
  "description": "Search for pages and databases",
  "inputSchema": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "The search query text"
      },
      "filter": {
        "type": "object",
        "properties": {
          "property": { "type": "string", "enum": ["object"] },
          "value": { "type": "string", "enum": ["page", "database"] }
        }
      }
    }
  },
  {
  "name": "notion-fetch",
  ...
  }
  ... (84 tools total)
}
CLI loads this (~50 tokens * 6 = 300):
<available_tools>
  <tool>
    <name>notion</name>
    <description>CLI for Notion</description>
    <location>~/bin/notion</location>
  </tool>
  <tool>
    <name>linear</name>
    ...
  </tool>
  ... (6 tools total)
</available_tools>

2. Tool call

Once the agent knows what’s available, it still needs to call a tool.

MCP tool call (~30 tokens):
{
  "tool_call": {
    "name": "notion-search",
    "arguments": {
      "query": "my search"
    }
  }
}
CLI tool call (~610 tokens):
# Step 1: Discover tools (~4 + ~600 tokens)

$ notion --help
notion search <query> [--filter-property ...]
  Search for pages and databases
notion create-page <title> [--parent-id ID]
  Create a new page
... 12 more tools

------------------------------------------------

# Step 2: Execute (~6 tokens)

$ notion search "my search"

MCP’s call is cheaper because definitions are pre-loaded. CLI pays at discovery time - --help returns the full command reference (~600 tokens for 14 tools), then the agent knows what to execute.

Tools used MCP CLI Savings
Session start ~15,540 ~300 98%
1 tool ~15,570 ~910 94%
10 tools ~15,840 ~964 94%
100 tools ~18,540 ~1,504 92%

CLI uses ~94% fewer tokens overall.

Anthropic launched Tool Search which loads a search index instead of every schema then uses fetch tools on demand. It typically drops token usage by 85%.

Same idea as CLI’s lazy loading. But when Tool Search fetches a tool, it still pulls the full JSON Schema.2

Tools used MCP TS CLI Savings vs TS
Session start ~15,540 ~500 ~300 40%
1 tool ~15,570 ~3,530 ~910 74%
10 tools ~15,840 ~3,800 ~964 75%
100 tools ~18,540 ~12,500 ~1,504 88%

Tool Search is more expensive, and it’s Anthropic-only. CLI is cheaper and works with any model.

CLIHub

I struggled finding CLIs for many tools so built CLIHub a directory of CLIs for agent use.

Open sourced the converter - one command to create CLIs from MCPs.


联系我们 contact @ memedata.com