# token-optimizer-mcp

This MCP server compresses request content and can move blocks it cannot compress into a file. It can help when logs, search results, or repeated reads fill an agent’s context.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 560
- Author: ooples
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/ooples/token-optimizer-mcp
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/mcp/token-optimizer-mcp

## What it does

The server compresses blocks in a request without moving their contents. In proxy mode, it can also move a block that resists compression into a file and leave a marker with its path. The README compares these as separate modes against HeadRoom using test corpora.

In Claude Code, add the server with `claude mcp add` and run it through `npx`. To configure a cache directory, the command accepts `TOKEN_OPTIMIZER_CACHE_DIR`. Node.js 22 or newer is required. Without the proxy mode, blocks stay in the request and are handled through compression.

## Requirements
- Needs: Node.js (commands run via npx)
- Environment variables: `TOKEN_OPTIMIZER_CACHE_DIR` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add --env TOKEN_OPTIMIZER_CACHE_DIR=<TOKEN_OPTIMIZER_CACHE_DIR> --transport stdio token-optimizer-mcp -- npx -y @ooples/token-optimizer-mcp
```
Replace <…> with your own values

### Codex

**Platform CLI**
```bash
codex mcp add token-optimizer-mcp --env TOKEN_OPTIMIZER_CACHE_DIR=<TOKEN_OPTIMIZER_CACHE_DIR> -- npx -y @ooples/token-optimizer-mcp
```
Replace <…> with your own values

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "token-optimizer-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "@ooples/token-optimizer-mcp"
            ],
            "env": {
                "TOKEN_OPTIMIZER_CACHE_DIR": "<TOKEN_OPTIMIZER_CACHE_DIR>"
            }
        }
    }
}
```
Replace <…> with your own values

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "token-optimizer-mcp": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "@ooples/token-optimizer-mcp"
            ],
            "env": {
                "TOKEN_OPTIMIZER_CACHE_DIR": "<TOKEN_OPTIMIZER_CACHE_DIR>"
            }
        }
    }
}
```
Replace <…> with your own values

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e TOKEN_OPTIMIZER_CACHE_DIR=<TOKEN_OPTIMIZER_CACHE_DIR> token-optimizer-mcp npx -y @ooples/token-optimizer-mcp
```
Replace <…> with your own values

## When to use it
- compress long build logs before asking an agent to inspect them
- reduce repeated-read content in an agent request
- move an incompressible block to a file and keep its path
- shrink context containing search results

## Example prompts
- Compress the build output before analyzing the errors.
- Process these code search results and trim unnecessary context.
- Move the large block that cannot be compressed into a file and keep its path.

## Similar
- [REA](https://affpapa.org/en/nevibecode/mcp/rea.md) — MCP server · ★ 386989
- [GitHub](https://affpapa.org/en/nevibecode/mcp/github.md) — MCP server · ★ 33918
- [Netdata](https://affpapa.org/en/nevibecode/mcp/netdata.md) — MCP server · ★ 81115
- [browser-use](https://affpapa.org/en/nevibecode/mcp/browser-use.md) — MCP server · ★ 119160
- [Codebase Memory](https://affpapa.org/en/nevibecode/mcp/codebase-memory.md) — MCP server · ★ 47392
- [mcp-server](https://affpapa.org/en/nevibecode/mcp/mcp-server.md) — MCP server · ★ 43872

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
