展示 HN:Mcptoon – 高效令牌的 MCP 命令行客户端
Show HN: Mcptoon – Token-efficient MCP CLI client

原始链接: https://github.com/activeing123/mcptoon

**mcptoon** 是一款轻量级、无依赖的命令行工具,旨在大幅削减模型上下文协议(MCP)产生的海量 Token 开销。 标准的 MCP 客户端往往仅因 JSON 语法就占用了 AI 上下文窗口 40%–60% 的空间。mcptoon 通过输出 **TOON(Token-Optimized Object Notation,Token 优化对象表示法)** 来解决这一问题。这是一种既适合人类阅读又适合 AI 处理的紧凑格式,它用轻量级的替代方案取代了冗长的 JSON 语法(如花括号、引号和冒号)。这使得工具发现过程可节省高达 **98%** 的 Token,工具结果可节省 **40–60%** 的 Token,从而为您保留更多的上下文窗口用于实际的逻辑推理。 **核心功能:** * **通用兼容性:** 可与任何支持运行 Shell 命令的智能体(Claude Code、Cursor、Codex 等)配合使用。 * **零依赖:** 纯 Python 编写,体积约 50KB,无任何第三方导入。 * **安全至上:** 内置针对破坏性命令(如 `drop`、`delete`)的防护机制。 * **灵活易用:** 支持 `stdio` 和 `HTTP` 两种 MCP 服务器,并提供本地使用统计和架构缓存功能。 通过简单地将 JSON 替换为 TOON,开发者可以显著提升智能体的性能与效率。立即从 GitHub 安装,找回您的 Token 预算并优化 AI 智能体的工作流。

这篇 Hacker News 帖子介绍了“Mcptoon”,这是一个旨在优化模型上下文协议(MCP)工具发现过程的命令行客户端,号称可减少 97% 的 Token 用量。该项目旨在通过用简写符号替换冗长的架构,使大型工具集对大语言模型(LLM)而言更高效。 该公告在评论区引发了即时争论。批评者质疑该项目的压缩方法是否有效,特别是用非常见符号替换“null”和换行符等标准字符的做法,认为这些改动对节省 Token 价值甚微,且可能牺牲架构的清晰度。其他用户则对该项目在处理具有庞大功能集应用(如视频编辑工具)时的底层机制表示了兴趣,同时也指出目前的文件记录依赖于字符计数而非 Token 分析,这使得其声称的效率指标难以得到验证。
相关文章

原文

MCP tool discovery costs 10,000+ tokens. mcptoon costs 350.

One MCP client for every AI agent. Cross-platform. Zero dependencies.

Python 3.10+ License: Apache 2.0 Zero Dependencies PyPI version Tests

If this saves you tokens, please star the repo — it helps others discover it.

English | 中文文档 | Report Bug | Request Feature


Every MCP-enabled conversation burns tokens on syntax, not data:

  • Your agent connects to 5 MCP servers. Listing their tools: ~10,000 tokens of JSON.
  • Your agent calls 20 tools. Each returns 500-3,000 tokens wrapped in {"content":[{"type":"text","text":"..."}]}.
  • Total MCP overhead: 40,000-70,000 tokens before any actual thinking happens.

On a 128K context window, that's 30-55% gone. Not on work. On syntax.

mcptoon is a CLI client that connects to any MCP server (stdio or HTTP) and outputs TOON (Token-Optimized Object Notation) instead of JSON.

Operation JSON tokens mcptoon tokens Savings
Tool discovery (96 tools) ~2,000 ~60 97%
Tool result (structured data) ~800 ~350 56%
Tool result (raw HTML/text) ~1,000 ~900 10%

Zero dependencies. Pure Python. 50KB. Works with every AI agent — Claude Code, Codex, OpenCode, Cursor, CatPaw, anything that runs shell commands.

JSON (287 tokens) — what every other MCP client returns:

[
  {"name": "search_web", "description": "Search the web for information",
   "inputSchema": {"type": "object", "properties": {"query": {"type": "string", "description": "Search query"}, "num_results": {"type": "number", "default": 5}}, "required": ["query"]}},
  {"name": "fetch_url", "description": "Fetch content from a URL",
   "inputSchema": {"type": "object", "properties": {"url": {"type": "string"}}, "required": ["url"]}}
]

TOON (5 tokens) — what mcptoon returns:

98% reduction for tool discovery, 60% for full schema, zero information lost.

Zero dependencies. 50KB. Python 3.10+. Windows, macOS, Linux.

mcptoon init                          # Sample config: ~/.mcptoon/config.json
mcptoon add fetch --stdio npx -y @modelcontextprotocol/server-fetch
mcptoon manifest --toon               # -> fetch:fetch
mcptoon call fetch fetch '{"url":"https://example.com"}' --toon
mcptoon call fetch fetch '{"url":"https://example.com"}' --json   # when you need JSON
JSON TOON Why
{"name":"search","count":3} name:search|count:3 Pipes replace braces + quotes + colon
[1, 2, 3] 1 2 3 Spaces replace brackets + commas
true / false T / F 1 char vs 4-5
null 1 symbol vs 4 chars
"line1\nline2" line1↲line2 ↲ replaces escape sequence
{"a":{"b":[1,2]}} a:b:1_2 Recursive compaction
Flag What you get Token footprint
--toon Compact notation, full semantics 40-60% less than JSON
--compact Tool names only, space-separated 97% less than JSON
--json Standard JSON (for scripts, CI) Baseline
--raw Raw response, no parsing Full size
--head N First N items only Variable
--max-chars N Hard truncate at N chars Variable
--full Disable the default 4000-char truncation Full size

Set MCPTOON_AGENT_TYPE=claude and every call auto-selects --toon.

mcptoon mcp-cli mcporter raw MCP SDK
Token savings 97% manifest, 40-60% results 0% 0% 0%
Works with all agents yes (Claude Code, Codex, OpenCode, Cursor, any) Claude only Claude only varies
One config for all agents yes no no no
Output formats TOON + JSON + compact JSON JSON JSON
Dependencies 0 5-20 npm 3-8
Dangerous-op blocking yes no no no
Usage tracking yes (local) no no no
Schema cache yes (5min) no no no
Install size ~50KB ~50MB+ ~30MB ~10MB
Platform support Windows, macOS, Linux Linux/macOS macOS varies

mcptoon is a CLI tool. If your agent can run shell commands, it can use mcptoon.

Agent How to use
Claude Code Write mcptoon commands in SKILL.md files
Codex (OpenAI) Add mcptoon to AGENTS.md
OpenCode Use mcptoon in custom commands
Cursor Add mcptoon to .cursorrules
CatPaw Write mcptoon commands in skill files
Any agent If it runs shell commands, it can call mcptoon

Configure MCP servers once in ~/.mcptoon/config.json. Every agent shares the same servers, the same tools, the same token savings.

export MCPTOON_AGENT_TYPE=claude   # auto-select --toon
# In ~/.claude/skills/mcp-tools/SKILL.md
Search the web: mcptoon call exa search '{"query":"AI news"}'
List available tools: mcptoon manifest --toon
Fetch a URL: mcptoon call fetch fetch '{"url":"https://example.com"}'
# In AGENTS.md or system prompt
Use mcptoon to call MCP tools. It saves 60% tokens vs JSON.
- List tools: mcptoon manifest --toon
- Call a tool: mcptoon call <server> <tool> '{"args":"here"}' --toon
from mcptoon.client import MCPClient
from mcptoon.output import toon

with MCPClient(stdio=["npx", "-y", "@modelcontextprotocol/server-fetch"]) as c:
    tools = c.list_tools()
    print(toon(tools))         # compact TOON
    result = c.call_tool("fetch", {"url": "https://example.com"})
    print(toon(result))

Custom handlers — bypass MCP entirely

from mcptoon.router import register

@register("my-database", "db")
def handle_db(tool, args):
    if tool == "query":
        return {"rows": my_db.execute(args["sql"])}
    return None  # falls through to MCP
# stdio (any npx MCP server)
mcptoon add fetch --stdio npx -y @modelcontextprotocol/server-fetch
mcptoon add github --stdio npx -y @modelcontextprotocol/server-github

# HTTP
mcptoon add myapi --http http://localhost:3001/mcp --header "Authorization: Bearer xxx"

Config lives at ~/.mcptoon/config.json. Project-level override at ./.mcptoon.json.

mcptoon blocks operations that match dangerous patterns (delete, drop, purge, wipe, kill, etc.) unless you pass --destructive.

$ mcptoon call db delete_table '{"name":"users"}'
Error [CONFIRMATION_REQUIRED]: Dangerous operation needs confirmation

$ mcptoon call db delete_table '{"name":"users"}' --destructive
# runs
$ mcptoon usage
Total calls: 142
Success rate: 138/142
Tokens (est): 84,200

By server:
  fetch       89
  github      53

Stored locally at ~/.cache/mcptoon/usage.json. Never transmitted.

src/mcptoon/
├── cli.py        # CLI entry + arg parsing
├── client.py     # MCPClient — stdio + HTTP transport
├── router.py     # Tool routing, custom handlers, safety checks
├── config.py     # Server config
├── manifest.py   # Tool discovery with cache
├── output.py     # TOON / JSON / compact rendering
├── cache.py      # Schema cache (5-min TTL)
├── usage.py      # Local usage tracking
└── errors.py     # Structured error envelopes

~1,700 lines total. Zero third-party imports.

  • No telemetry. No analytics, no crash reports, no phone-home.
  • No credential storage. API keys pass through from your config or env vars.
  • No dependencies. Pure Python stdlib. No supply chain to audit.

Found a vulnerability? Email [email protected]. See SECURITY.md.

Apache 2.0. See LICENSE and NOTICE.

git clone https://github.com/activeing123/mcptoon.git
cd mcptoon
pip install -e . --no-build-isolation
pip install pytest pytest-cov
python -m pytest tests/ -v   # 98 tests, 0.09s

Zero dependencies is a hard rule. New features need tests. See CONTRIBUTING.md.


mcptoon is an independent third-party MCP client. Not affiliated with Anthropic.

Found this useful? Star the repo to help others find it.

Report Bug | Request Feature

联系我们 contact @ memedata.com