Skip to main content
Glama
mcp-token-optimizer

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 Node Local LLM Protocol Unique Visitors


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; 92 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.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    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