DEV Community

MCP Token Saver
MCP Token Saver

Posted on

I measured MCP token waste. Then I wrote a CLI to fix it.

I use MCP servers with Claude Code every day. Last week I counted the tokens.

5 servers, 96 tools. The JSON tool listing: 2,034 tokens. Before I've typed a single character.

Then 20 tool calls, each response wrapped in {"content":[{"type":"text","text":"..."}]} - 40,000 tokens of brackets, quotes, and repeated {"type":"object","properties": declarations. The actual useful content was maybe 8,000 tokens.

The format

I wrote mcptoon - a CLI that outputs TOON (Token-Optimized Object Notation) instead of JSON:

{"name":"search","count":3} -> name:search|count:3
[1, 2, 3] -> 1 2 3
Enter fullscreen mode Exit fullscreen mode

Pipes for object properties. Spaces for array items. No braces, no quotes, no commas.

Important: An earlier version replaced true/false with T/F and null with a special char. HN commenters correctly pointed out that these substitutions actually increased token count in most tokenizers. v0.3.0 keeps true, false, and null as-is. All savings come from removing JSON structural syntax, verified with tiktoken's o200k_base encoding.

Measured results (tiktoken-verified)

Operation JSON tokens mcptoon tokens Saved
Tool discovery (96 tools) 2,034 340 83%
Tool result (structured) 812 354 56%
Real session (5 servers, 20 calls) 47,200 12,100 74%

The savings come from stripping repeated JSON schema declarations and structural syntax - braces, brackets, quotes, commas - not from abbreviating primitives.

Does the LLM understand it?

Tested with Claude, GPT-4, and Gemini. All three parse TOON correctly. The format is deterministic - pipes separate key-value pairs, spaces separate array items. No ambiguity in parsing.

The LLM doesn't need JSON syntax to understand structure. It needs consistent, recoverable formatting. TOON provides that.

Usage

pip install mcptoon
mcptoon init
mcptoon add fetch --stdio npx -y @modelcontextprotocol/server-fetch
mcptoon manifest --toon
mcptoon call fetch fetch '{"url":"https://example.com"}' --toon
Enter fullscreen mode Exit fullscreen mode

It's a CLI, not a library. Any agent that runs shell commands can use it - Claude Code, Cursor, Codex, OpenCode. Zero dependencies, 50KB, Python 3.10+, Apache 2.0.

Safety features

  • Credential leak detection (scans output for API keys, tokens)
  • Tool poisoning guard (blocks suspicious tool names)
  • Dangerous operation blocking (delete, drop, purge)
  • No telemetry, no network calls, no post-install hooks

GitHub: https://github.com/activeing123/mcptoon

What I learned from HN feedback

Posting on Hacker News taught me a lot:

  1. Don't conflate character counts with token counts - always verify with the actual tokenizer (tiktoken)
  2. Don't replace things that are already 1 token - true, false, null are each 1 token in modern tokenizers
  3. Be honest about numbers - my original "97% savings" was really 83% after proper tiktoken verification

The benchmark scripts are in the repo under /tests/ if anyone wants to verify or challenge the numbers.

Curious if others have measured their MCP token overhead.

Top comments (0)