mcp-diet
<div align="center">
<p>
<a href="README.md"><strong>English</strong></a> · <a href="README.ru.md">Русский</a>
</p>
<img src="assets/hero-banner.svg" alt="mcp-diet hero banner" width="900" />
<br/><br/>




**Lazy MCP meta-proxy, response trimmer with spillover cache, and token-tax auditor.**
Works with Claude Code, Cursor, Windsurf, Codex CLI, and Antigravity.
</div>
Every MCP server you enable dumps its full tool schemas into the prompt before turn one. Connect three or four servers (GitHub, Postgres, browser automation, Sentry) and an agent starts the session with 10,000 to 35,000 tokens already spent on JSON parameter definitions it may never call. Then one `list_issues` or SQL dump adds another 10,000 tokens of raw JSON.
`mcp-diet` sits in front of your existing stdio MCP servers and exposes four small tools costing **516 tokens** total: `search_tools`, `describe_tool`, `call_tool`, and `read_cached_output`. Upstream servers stay stopped until an agent actually calls one of their tools, and oversized outputs are trimmed into a local LRU spillover cache that supports JSON dot/bracket path reads.
## Measured benchmark
Reproduce these numbers on your machine with `node ./bin/mcp-diet.mjs benchmark --markdown` (3 mock stdio servers exposing 60 realistic tools, estimated at `bytes / 3.8` chars per token):
| Server | Tools | Startup Tokens | Status |
| --- | ---: | ---: | --- |
| `github` | 20 | 3,824 tok | ok |
| `browser` | 20 | 3,083 tok | ok |
| `postgres` | 20 | 3,015 tok | ok |
| **Direct total (3 servers)** | **60** | **9,922 tok** | zero-turn context cost |
| **With mcp-diet** | **4** | **516 tok** | **-94.8% saved** |
| Measurement | Before | After `mcp-diet` | Reduction |
| --- | ---: | ---: | --- |
| Startup schemas (60 tools across 3 MCPs) | 9,922 tok | 516 tok | **-94.8%** |
| Large tool output (`github:list_issues_large (60 issues)`) | 9,576 tok | 609 tok | **-93.6%** |
## Quick start
Requires Node.js `>= 22.5.0` with zero npm packages to install.
### 1. Audit your current MCP token tax
`mcp-diet audit` discovers MCP configs from `mcp-diet.json`, `.mcp.json`, `.cursor/mcp.json`, Antigravity, Codex, and Claude Desktop, then measures the schema cost of every server:
```bash
npx -y github:keenfolk1-lgtm/mcp-diet audit
```
### 2. Wrap your config
Generate a standalone `mcp-diet.json` backend file and a wrapped editor config pointing to `mcp-diet`:
```bash
npx -y github:keenfolk1-lgtm/mcp-diet wrap --from ./.mcp.json --write
```
Or run `mcp-diet` directly in any client (`claude mcp add mcp-diet -- npx -y github:keenfolk1-lgtm/mcp-diet serve --config ./mcp-diet.json`) or with `mcp.json`:
```json
{
"mcpServers": {
"mcp-diet": {
"command": "npx",
"args": ["-y", "github:keenfolk1-lgtm/mcp-diet", "serve", "--config", "./mcp-diet.json"]
}
}
}
```
### 3. Verify the local setup
```bash
node ./bin/mcp-diet.mjs doctor
```
## Proxy tools
| Tool | Purpose |
| --- | --- |
| `search_tools` | BM25 search across upstream tool names, descriptions, and argument keys. |
| `describe_tool` | Returns the full `inputSchema` for a single `server:tool` id on demand. |
| `call_tool` | Spawns the target upstream server lazily, executes the call, and trims large payloads. |
| `read_cached_output` | Reads a specific JSON path (such as `items[12].title`) or text slice from the spillover cache. |
## Protocol and config details
`mcp-diet` supports both newline-delimited JSON-RPC and `Content-Length` framed stdio servers, expanding `${ENV_VAR}` placeholders in configured server `env` blocks at spawn time. Responses above `trimThresholdChars` (default `6000` characters) are stored in an in-memory 50-slot LRU cache and summarized in place (JSON arrays collapse to total count, item keys, first 2 items, and last item). Pass `raw: true` to `call_tool` when you need an untrimmed response.
## Limitations
`mcp-diet` manages stdio MCP servers (`command` + `args`) and skips remote SSE or Streamable HTTP server entries during config discovery. The spillover cache lives in process memory for the lifetime of the proxy session, so `cacheId` handles expire when the proxy restarts. Indexing upstream catalogs on the first `search_tools` call starts each enabled server once to fetch `tools/list`, then closes idle connections until `call_tool` invokes one.
## License
[MIT](LICENSE)
Related tools: [skill-guard](https://github.com/keenfolk1-lgtm/skill-guard) · [blast-radius-mcp](https://github.com/keenfolk1-lgtm/blast-radius-mcp) · [flight-recorder-mcp](https://github.com/keenfolk1-lgtm/flight-recorder-mcp) · [agent-undo](https://github.com/keenfolk1-lgtm/agent-undo) · [dotagents](https://github.com/keenfolk1-lgtm/dotagents)
TDQS
Scored across 4 tools
Each tool occupies a distinct stage of the lazy-invocation workflow: discovery (search_tools), inspection (describe_tool), execution (call_tool), and post-execution inspection (read_cached_output). The descriptions make the handoff between stages explicit, so an agent can tell exactly which tool to reach for.
All four names follow a clean snake_case verb_noun pattern (search_tools, describe_tool, call_tool, read_cached_output) with no convention mixing. The one two-word noun (cached_output) is still readable and unambiguous.
Four tools is exactly the right scope for a context-saving proxy: one per workflow stage, with no redundancy or filler. Nothing here feels like it could be collapsed into another tool without losing clarity.
The search → describe → call → read-cache loop is closed and covers the core purpose of lazily invoking upstream tools. Minor gaps remain: no way to enumerate configured upstream servers or manage/clear the spillover cache (list or evict cacheIds), which agents may need when a cacheId is lost or the cache grows.