mcp-token-optimizer
Uses a local Ollama model to summarize oversized MCP tool responses, with configurable model and parameters, a hard latency budget, and a fact-coverage guard; code and file reads are never summarized.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mcp-token-optimizer
Stop paying for tool-response noise.
A self-hosted proxy between your AI agent and its MCP servers that shrinks every tool response: pruning, TOON encoding and local-LLM summarization, without changing what the agent can do.
Quick start ยท How it works ยท Docs ยท Testing ยท Contributing
Why
Every token an MCP tool returns is paid for, and fills the model's context window. Real tool output is mostly noise: null fields, hypermedia URLs, avatar and node ids, the same block repeated in two fields, ANSI and progress-bar spam, boilerplate prose. mto removes that noise before the model sees it, keeps an exact copy of anything it removed, and tells the agent how to get it back.
Local only, always.
mtotalks only to your own MCP servers and to a local Ollama on127.0.0.1. No telemetry, no cloud model providers, nothing leaves your machine. The dashboard and its API bind to loopback, need a per-run token, and cannot run arbitrary commands. See Security and privacy.
Related MCP server: Delta-MCP
Results
Measured, reproducible, no LLM involved (npm run smoke, TESTING.md). Token counts are a model-agnostic estimate.
Tool response | Original | Sent to the agent | Saved |
GitHub issue list (40 issues, REST JSON) | 37,355 | 13,244 | 64.5% |
Kubernetes describe + manifest (duplicated content) | 3,637 | 1,935 | 46.8% |
CI build log (ANSI, repeated lines) | 4,926 | 78 | 98.4% |
HTML runbook page | 1,198 | 863 | 28.0% |
Real Kubernetes ConfigMap through a live MCP server, Copilot A/B run | 24,616 | 12,617 | 48.7% |
In that live A/B run, the three files the agent wrote from the optimized result were byte-identical to the original data (checked against a pre-optimization capture).
Highlights
๐งพ Lossless first | JSON โ TOON is emitted only after a verified round-trip; duplicate blocks become pointers; the canonical copy is never touched |
๐ Fail-open, never bigger | any error, timeout or Ollama outage forwards the original; an optimized result is used only if it is strictly cheaper |
๐ | notes name exactly what was pruned; the agent can fetch the exact original (outline, JSON path, grep) on demand |
๐ Shadow mode | measure real savings while forwarding the originals, so you can roll out with zero risk |
๐ Any MCP client | stdio wrapper and local HTTP/SSE proxy; installs into VS Code Copilot, Claude, Cursor, Windsurf, Gemini CLI, Cline, Roo (JSONC-safe, reversible) |
๐ง Local summarization | your Ollama model, your parameters, a hard latency budget and a fact-coverage guard; code and file reads are never summarized |
๐ Private by design | binds to |
๐ฅ๏ธ Local dashboard |
|
๐งช Measurable | capture, bench, compare and stats built in; 89 tests and a 24-check end-to-end smoke test |
Quick start
npm install -g @shubhamcodess/mcp-token-optimizer # or clone and build; see the install guide
mto doctor # checks config, Ollama and model
mto discover # lists the MCP servers it found (read-only)
mto init --only <server> --apply # wrap one server; undo: mto uninstall --applyNo agent handy? npm run demo shows a tool call through the optimizer with sample data.
Roll out safely: set
mode: shadowfirst. The proxy then measures savings but forwards the original responses, so nothing changes for your agent until you switch toactive.
Full walkthrough: Getting started.
Documentation
Guide | What is in it |
๐ Getting started | Install, wire your agent, try it without an agent |
๐ง How it works | The pipeline, operating modes, stdio vs HTTP, |
๐๏ธ Tuning | Profiles, output formats, local summarization, capture and bench |
๐ Reference | Every config key, CLI command, file and environment variable |
๐ฅ๏ธ Dashboard | What each page shows and what it can change |
๐ Troubleshooting | Symptoms, causes and fixes |
๐ Security and privacy | Threat model, what is stored, redaction, reporting a vulnerability |
๐งช Testing | Automated tests, benchmarks, live A/B procedure, verification status |
๐ค Contributing | Dev setup, code layout, checks, pull request checklist |
๐ Code of conduct | Expected behaviour in this project |
๐ Changelog | Release history |
Contributing
Contributions of all sizes are welcome: bug reports, docs, benchmark results, new agent integrations, pipeline improvements. Start with CONTRIBUTING.md and please read the Code of Conduct. Security issues: SECURITY.md.
License
Apache-2.0. Uses the official @toon-format/toon library for TOON, and Ollama for optional local summarization.
This server cannot be deployed
Maintenance
Related MCP Connectors
Multiple MCP tools, persistent graph memory, token-saving data pointers, and more.
Stateless agentic tools over MCP: concept extraction, long-context, knowledge graph, planning.
Compress coding-agent context ~64%. Hosted Neural Keep MCP for Cursor/Claude/Codex.
Reduces AI Agent token usage by 40% via three-stage SOP workflow.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceAn adaptive tiny-model layer that sits between an LLM and its MCP tools, compressing verbose tool outputs to reduce token usage by up to two orders of magnitude.1Apache 2.0
- AlicenseNot gradedqualityCmaintenanceToken-efficient MCP reimplementation with progressive tool discovery, result handling, and compact wire encoding, reducing token usage by up to 89% on tool definitions.1MIT
- AlicenseAqualityCmaintenanceMCP proxy that compresses tool schemas on the fly. Up to 98% token reduction, 100% signal preserved verified after every compression. Zero LLM calls, fully deterministic.53MIT
- AlicenseNot gradedqualityCmaintenanceDeterministic context compression for MCP agents, reducing token usage via 11 tools for prompts, history, shell output, file deltas, and code navigation without ML or GPU.9MIT