# TokenSlim MCP — verifiable token reduction for agents

> TokenSlim MCP — verifiable token reduction for agents is an open-source MCP server for developer tools. MCP server that trims and audits LLM context, reporting before/after token counts. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, Self-hosted, API
- **Repository:** https://github.com/kamalmosadegh/tokenslim-mcp
- **MCP Registry name:** io.github.kamalmosadegh/tokenslim-mcp
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-11-28

## About

Its four tools cover the usual sources of bloat in an agent's context: auditing a message list to see where tokens go, compressing a prompt to a target rate while keeping named terms, shrinking a single tool output or log to a budget, and compacting a long message history. Every result includes token counts measured the same way before and after, so the saving can be checked from the output itself.

The underlying library is deterministic and model-free, with no API keys and no network calls. Compression is heuristic: code-like lines, numbers and caller-specified terms are protected, and an ERROR line buried in a long log is kept through trimming. Compaction summarizes older turns extractively and always respects the budget.

The server is aimed at developers running MCP clients such as Claude Code, Cursor or Codex who want to reduce token spend on tool-heavy sessions. Savings depend on how much of the context is tool output, and the server is stateless in this version.

## Features

- **Context audit:** Profiles a message list by role, tool result share, largest messages and duplicate tool outputs.
- **Prompt compression:** Compresses text to a target rate while protecting caller-named terms, code lines and numbers.
- **Tool output trimming:** Cuts a log or tool output to a token budget by keeping its head, tail and highest-signal lines.
- **History compaction:** Elides old tool results and summarizes older turns while keeping recent messages verbatim.
- **Verifiable token counts:** Each result reports tokens before and after, produced by the same counter for both.
- **Offline counting option:** Falls back to a chars/4 estimator when tiktoken is unavailable or disabled by environment variable.

## Good for

- Reducing token cost of long coding-agent sessions with bulky tool output
- Trimming large build or application logs before passing them to a model
- Checking which message types consume most of an agent's context window
- Compacting a long conversation history to fit a fixed token budget
- Compressing prompts while confirming that specific terms survive

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add tokenslim-mcp -- uvx tokenslim-mcp
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add tokenslim-mcp -- uvx tokenslim-mcp
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.tokenslim-mcp]
command = "uvx"
args = ["tokenslim-mcp"]
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Or run: gemini mcp add -s user tokenslim-mcp uvx -- tokenslim-mcp

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "tokenslim-mcp": {
      "command": "uvx",
      "args": [
        "tokenslim-mcp"
      ]
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 4 names don't say. From the server's own tool labels and tool names; not verified by us.

- `tokenslim_audit`: Profile an OpenAI-style message list: where the tokens go.
- `tokenslim_compress`: Compress a prompt to a target rate, protecting caller-named terms.
- `tokenslim_trim`: Shrink one tool output or log to a token budget.
- `tokenslim_compact`: Compact a message history to a budget.

## FAQ

### Does TokenSlim MCP — verifiable token reduction for agents call an LLM or external API?

No. The library is described as zero-dependency, deterministic and model-free, with no API keys and no network calls.

### How do I install TokenSlim MCP — verifiable token reduction for agents?

Install from source with pip install . from the repository today; a PyPI release is planned. It runs over stdio and can be added to Claude Code with claude mcp add, or configured via uvx.

### Are the results repeatable?

All four tools are described as read-only and deterministic: the same input gives the same output and counts.

### Is TokenSlim MCP — verifiable token reduction for agents open source?

Yes, the server and the TokenSlim library are both released under the MIT licence.

### Is TokenSlim MCP — verifiable token reduction for agents free?

Yes. TokenSlim MCP — verifiable token reduction for agents is open source, so you can use and self-host it for free.

### How do I add TokenSlim MCP — verifiable token reduction for agents to Claude Code?

Run this command in your terminal: claude mcp add tokenslim-mcp -- uvx tokenslim-mcp

### What are the best alternatives to TokenSlim MCP — verifiable token reduction for agents?

The closest alternatives to TokenSlim MCP — verifiable token reduction for agents are slimproof, Compress-token, Token Optimizer, Token Lens and MCP Token Optimizer.

## Where this comes from

- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [slimproof](https://ai-powered.com/mcp/slimproof): slimproof is an open-source MCP server for developer tools.
- [Compress-token](https://ai-powered.com/mcp/compress-token): Compress-token is an open-source MCP server for developer tools.
- [Token Optimizer](https://ai-powered.com/mcp/token-optimizer): Token Optimizer is an open-source MCP server for developer tools.
- [Token Lens](https://ai-powered.com/mcp/token-lens-2): Token Lens is an open-source MCP server for developer tools.
- [MCP Token Optimizer](https://ai-powered.com/mcp/mcp-token-optimizer-2): MCP Token Optimizer is an open-source MCP server for developer tools.
- [Slimcontext MCP Server](https://ai-powered.com/mcp/slimcontext-mcp-server): Slimcontext MCP Server is an open-source MCP server for agent tooling.
- [Whittle MCP](https://ai-powered.com/mcp/whittle-mcp): Whittle MCP is a free MCP server for ai models and llm tooling.
- [llmtrim](https://ai-powered.com/mcp/llmtrim): llmtrim is an open-source MCP server for ai models and llm tooling.

---
Source: https://ai-powered.com/mcp/tokenslim-mcp-verifiable-token-reduction-for-agents
