Skip to main content
Glama
shubhamcodess

mcp-token-optimizer

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.

CI License: Apache-2.0 Node Local LLM Protocol PRs welcome Unique visitors

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. mto talks only to your own MCP servers and to a local Ollama on 127.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

๐Ÿ”Ž mto_expand

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 127.0.0.1, no telemetry, credentials forwarded but never stored, optional secret redaction

๐Ÿ–ฅ๏ธ Local dashboard

mto ui: overview, live traffic, connections, config editor, eval history, advisor and drift warnings, served by the daemon, no CDN (dashboard guide)

๐Ÿงช 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 --apply

No agent handy? npm run demo shows a tool call through the optimizer with sample data.

Roll out safely: set mode: shadow first. The proxy then measures savings but forwards the original responses, so nothing changes for your agent until you switch to active.

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, mto_expand

๐ŸŽ›๏ธ 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.

Maintenance

ActivityMaintained
ResponsivenessSlow

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    An 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.
    1
    Apache 2.0
  • A
    license
    Not graded
    quality
    C
    maintenance
    Token-efficient MCP reimplementation with progressive tool discovery, result handling, and compact wire encoding, reducing token usage by up to 89% on tool definitions.
    1
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    MCP 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.
    5
    3
    MIT