# MCP Token Optimizer | AI tooling by Shubham Prakash

> A self-hosted proxy between your AI agent and its MCP servers. It shrinks every tool response without changing what the agent can do.

Page: https://shubhamcodess.github.io/builds/mcp-token-optimizer/

## MCP Token Optimizer

A self-hosted proxy between your AI agent and its MCP servers. It shrinks every tool response without changing what the agent can do.

- Page: https://shubhamcodess.github.io/builds/mcp-token-optimizer/
- Kind: AI tooling, 2026
- Stack: TypeScript, Node.js, MCP, Ollama, TOON
- code: https://github.com/shubhamcodess/mcp-token-optimizer
- live: https://shubhamcodess.github.io/mcp-token-optimizer/
- package: https://www.npmjs.com/package/@shubhamcodess/mcp-token-optimizer

### Overview

Every token an MCP tool returns is paid for and fills the context window, and real tool output is **mostly noise**: null fields, hypermedia URLs, repeated blocks and progress-bar spam. This proxy sits between the agent and its MCP servers and shrinks each response by **pruning**, **TOON encoding** and **local summarization**. It talks only to your own MCP servers and a local Ollama.

Measured:

- 98.4%: tokens saved on a CI build log
- 64.5%: saved on a list of 40 GitHub issues
- 48.7%: saved on a live Kubernetes run

### What it does

- Works with any MCP client through a stdio wrapper or a local HTTP proxy: VS Code Copilot, Claude, Cursor, Windsurf, Gemini CLI, Cline and Roo.
- Shadow mode measures real savings while still forwarding the originals, so it can roll out with no risk.
- Notes name exactly what was pruned, and the agent can fetch the exact original on demand.
- A local dashboard shows live traffic, connections, config, eval history and drift warnings, with no CDN.

### How it is built

- Lossless first: JSON becomes TOON only after a verified round trip, and duplicate blocks become pointers.
- Fail-open and never bigger: any error, timeout or Ollama outage forwards the original, and an optimized result is used only when it is strictly cheaper.
- Quality gates for CI, a drift watcher and per-client profiles, with hot-reloaded config.
- In the live A/B run, the three files the agent wrote from the optimized result were byte-identical to the originals.

### Honest limits

- Token counts are a model-agnostic estimate.
- Numbers come from the repository benchmark, which anyone can re-run.

By Shubham Prakash: https://shubhamcodess.github.io/
