token-filter-mcp

token-filter-mcp

An MCP server that intelligently filters and compresses tool outputs to reduce context window usage, saving up to 90% of tokens by removing noise such as passing tests and redundant information.

Category
Visit Server

README

<div align="center">

๐Ÿงน token-filter-mcp

Your LLM is wasting 80% of its context window on noise.<br> This fixes that.

npm version license node MCP

<br>

<img src="https://img.shields.io/badge/test_runners-92%25_savings-success?style=for-the-badge" alt="test runners 92% savings"/> <img src="https://img.shields.io/badge/file_reads-94%25_savings-success?style=for-the-badge" alt="file reads 94% savings"/> <img src="https://img.shields.io/badge/git_ops-89%25_savings-success?style=for-the-badge" alt="git ops 89% savings"/>

<br><br>

An MCP server that sits between your AI coding assistant and its tools,<br> intelligently compressing outputs before they consume your precious context.<br> Longer sessions. Better reasoning. Lower costs.

</div>


<br>

๐Ÿ’ธ The Problem Nobody Talks About

Every time your AI assistant runs a command, it dumps the entire raw output into its context window:

+ โœ“ src/auth.test.ts (14 tests)          โ† you don't need this
+ โœ“ src/utils.test.ts (8 tests)          โ† or this
+ โœ“ src/payments.test.ts (12 tests)      โ† or this
+ โœ“ src/users.test.ts (10 tests)         โ† or this
- โœ— src/orders.test.ts (3 tests)         โ† THIS is what matters
-   โ— should validate quantity > 0
-     Expected: error
-     Received: success

The vast majority of tool output is noise: tests that pass, git headers, resolution trees, progress bars, whitespace. ~80% of what goes into the context window is information the LLM will never act on.

That noise eats your context window, degrades reasoning quality, and costs you money.

<br>

โšก The Solution

<table> <tr> <td width="50%">

โŒ Without token-filter-mcp

  • Context fills up fast
  • LLM loses track of conversation
  • Paying for tokens it ignores
  • Sessions hit context limit early
  • Reads 14 lines to find 1 failure

</td> <td width="50%">

โœ… With token-filter-mcp

  • Context stays lean
  • LLM maintains coherence longer
  • Only paying for useful tokens
  • Sessions last significantly longer
  • Reads exactly the failure, acts immediately

</td> </tr> </table>

token-filter-mcp intercepts every tool output and applies intelligent, context-aware filtering โ€” returning only what the LLM actually needs to make decisions.

No configuration needed. No changes to your workflow. Just plug it in.

<br>

๐ŸŽฏ Real Results

<table> <tr> <th>Scenario</th> <th>Without filter</th> <th>With filter</th> <th>Savings</th> </tr> <tr> <td><code>npm test</code> (57 tests, all pass)</td> <td>295 chars / 14 lines</td> <td>23 chars / 1 line</td> <td><b>๐ŸŸข 92%</b></td> </tr> <tr> <td><code>npm test</code> (3 failures)</td> <td>~5,200 chars</td> <td>~480 chars</td> <td><b>๐ŸŸข 91%</b></td> </tr> <tr> <td>File read (signatures mode)</td> <td>7,992 chars / 243 lines</td> <td>483 chars / 9 lines</td> <td><b>๐ŸŸข 94%</b></td> </tr> <tr> <td>20 repeated log lines</td> <td>312 chars / 22 lines</td> <td>33 chars / 2 lines</td> <td><b>๐ŸŸข 89%</b></td> </tr> <tr> <td>Long unknown command (150 lines)</td> <td>3,492 chars / 151 lines</td> <td>2,342 chars / 101 lines</td> <td><b>๐ŸŸก 33%</b></td> </tr> </table>

Average savings across real-world tool outputs: 60-90% fewer tokens consumed

<br>

๐Ÿง  How It Works

flowchart LR
    A[๐Ÿค– LLM Agent] -->|tool call| B[๐Ÿงน token-filter-mcp]
    B -->|execute| C[๐Ÿ’ป System]
    C -->|raw output| B
    B -->|filtered output| A

    style B fill:#7c3aed,stroke:#5b21b6,color:#fff
    style A fill:#2563eb,stroke:#1d4ed8,color:#fff
    style C fill:#059669,stroke:#047857,color:#fff

<table> <tr> <td>

1๏ธโƒฃ Detect โ€” Identifies what command was run (test runner? git? linter?)

2๏ธโƒฃ Execute โ€” Runs the command and captures full output

3๏ธโƒฃ Filter โ€” Applies the optimal strategy for that command type

4๏ธโƒฃ Verify โ€” Ensures no errors or actionable info was removed

5๏ธโƒฃ Return โ€” Sends compressed output to the LLM

</td> </tr> </table>

๐ŸŽจ Contextual Detection

The server doesn't blindly truncate. It understands what you ran and applies the right strategy:

It detects... And does this...
๐Ÿงช Test runners (jest, vitest, pytest, cargo test, go test) Strips passing tests. Shows only failures with location + expected/received
๐Ÿ“Š git status Converts to M 3 | A 1 | D 0 | ? 2 + file list
๐Ÿ“ git diff Removes repeated headers, keeps only hunks with ยฑ3 context
๐Ÿ“œ git log One-liner: abc1234 feat: add auth (2h ago) ร— 15 max
๐Ÿ” Linters (tsc, eslint, biome, ruff) Groups errors by rule/file, omits clean files
๐Ÿ“ฆ Package installs Returns ok + 847 packages instead of the resolution tree
โ“ Unknown commands Conservative: deduplicate + truncate to 100 lines

๐Ÿ›ก๏ธ Zero Information Loss

The #1 design principle: never hide an error.

โœ… Lines matching error patterns (FAIL, Error:, TypeError, panic...) โ†’ NEVER removed
โœ… Non-zero exit codes โ†’ full error output preserved
โœ… Parser can't understand format โ†’ returns raw output
โœ… passthrough mode available for when you need everything

<br>

๐Ÿš€ Installation

<details open> <summary><b>Using npx (recommended, zero install)</b></summary>

Add this to your MCP client config โ€” that's it:

{
  "mcpServers": {
    "token-filter": {
      "command": "npx",
      "args": ["-y", "token-filter-mcp"]
    }
  }
}

</details>

<details> <summary><b>Global install</b></summary>

npm install -g token-filter-mcp
{
  "mcpServers": {
    "token-filter": {
      "command": "token-filter-mcp"
    }
  }
}

</details>

<br>

๐Ÿ“ Where does the config go?

Client Config file
Kiro .kiro/settings/mcp.json or ~/.kiro/settings/mcp.json
Claude Desktop claude_desktop_config.json
Cursor .cursor/mcp.json
Any MCP client Wherever it reads mcpServers config

<br>

๐Ÿ”ง 5 Tools, One Purpose

<details open> <summary><h3>โšก <code>filtered_shell</code> โ€” Run anything, get only what matters</h3></summary>

{ "command": "npm test", "filter_level": "normal" }
Level Behavior
normal Smart filtering with sensible defaults
aggressive 50% additional reduction for tight context budgets
passthrough Raw output when you need everything (capped at 200KB)

</details>

<details> <summary><h3>๐Ÿ“– <code>filtered_read</code> โ€” Read files without the bloat</h3></summary>

{ "path": "src/app.ts", "mode": "signatures" }
Mode What it returns
full Content minus blank blocks, license headers, grouped imports
signatures Only declarations โ€” no implementation bodies
relevant Only sections matching focus pattern with ยฑ10 lines context

Supports: TypeScript, JavaScript, Python, Rust, Go

</details>

<details> <summary><h3>๐Ÿ” <code>filtered_grep</code> โ€” Search without the wall of text</h3></summary>

{ "pattern": "useState", "path": "src", "group_by": "file", "max_results": 20 }

Results grouped by file, deduplicated, with context lines. Uses ripgrep when available.

</details>

<details> <summary><h3>๐Ÿงช <code>smart_test</code> โ€” Tests that report only what broke</h3></summary>

{ "command": "npm test" }

All pass:

[PASS] 47/47 tests passed (3.2s)

Failures:

[PASS] 44/47 tests passed
[FAIL] 3 failures:

1. src/auth.test.ts:42 โ€” "should refresh token"
   Expected: 200
   Received: 401

2. src/payments.test.ts:89 โ€” "should validate 3DS"
   TypeError: Cannot read property 'status' of undefined
   at processPayment (src/payments.ts:156)

Auto-detects: Jest, Vitest, pytest, cargo test, go test

</details>

<details> <summary><h3>๐ŸŒฟ <code>smart_git</code> โ€” Git without the verbosity</h3></summary>

{ "operation": "status" }
Operation What you get
status M 3 | A 1 | D 0 | ? 2 + file list
diff Only hunks with changes, no header spam
log abc1234 feat: add auth (2h ago) ร— 15
commit ok abc1234
push ok main โ†’ origin/main
pull ok +3 files, 47 insertions

</details>

<br>

โš™๏ธ Configuration (Optional)

Works great out of the box. Customize only if you want to.

<details> <summary><b>Per-project config</b> โ€” <code>.token-filter.json</code></summary>

{
  "defaults": {
    "max_output_lines": 100,
    "test_show_passes": false,
    "git_log_max": 15,
    "diff_context_lines": 3,
    "dedup_threshold": 3
  },
  "commands": {
    "my-custom-script.sh": { "filter_level": "passthrough" }
  },
  "metrics": { "enabled": true }
}

</details>

<details> <summary><b>Global config</b> โ€” <code>~/.config/token-filter-mcp/config.json</code></summary>

Same schema. Project config overrides global. Global overrides built-in defaults.

</details>

<br>

๐Ÿ“Š Built-in Observability

<details> <summary>View metrics details</summary>

When enabled, every invocation is logged to ~/.config/token-filter-mcp/metrics.jsonl:

{
  "tool": "smart_test",
  "command": "npm test",
  "rawChars": 5200,
  "filteredChars": 480,
  "savingsPercent": 90.7,
  "strategy": "test_result_filter",
  "filterDurationMs": 3,
  "timestamp": "2026-06-30T15:30:00Z"
}

Auto-rotated at 5MB, max 5 history files.

What it tracks:

  • Real savings per tool and command type
  • Which filters are most effective
  • Passthrough re-invocations (signal that a filter might be too aggressive)

</details>

<br>

๐Ÿ›ก๏ธ Guarantees

Guarantee Detail
๐Ÿ”’ Zero loss Errors, test failures, and changes are never filtered out
โšก < 50ms overhead Filtering adds negligible latency vs raw execution
๐Ÿช‚ Safe fallback Unknown commands get conservative treatment, not silence
๐Ÿ”Œ No lock-in Standard MCP protocol โ€” works with any compliant client
๐Ÿ  No network Everything runs locally over stdio. Your code never leaves your machine

<br>

๐Ÿ› ๏ธ Development

git clone https://github.com/VMexicano/token-filter-mcp
cd token-filter-mcp
npm install
npm run build
npm test        # 57 tests, all passing

<br>


<div align="center">

The best token is the one you never spend.

<br>

Made with ๐Ÿ’– by Victor Mexicano

</div>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured