MCP File Compaction
Reduces Claude's context window costs by automatically summarizing inactive files to their public interfaces using AST parsing, keeping only the full contents of the currently active file.
README
MCP File Compaction
An MCP server that reduces Claude context window costs by automatically summarizing files to their public interfaces.
The Problem
When Claude works on large tasks across multiple files, the context window grows continuously. Each API request costs based on the full size of the context, not just new tokens. This leads to quadratic cost growth:
- Implement
ptr.rs(2KB) → Context: 2KB - Implement
raw_page.rsusingptr.rs(3KB) → Context: 5KB - Implement
paged_pool.rsusing both (4KB) → Context: 9KB
After finishing a file, Claude doesn't need the full implementation—just the public interface (structs, functions, traits).
The Solution
This MCP server:
- Tracks the "active" file — the one you're currently editing (full contents)
- Auto-summarizes inactive files — when you switch files, the previous one is summarized to just its public API
- Uses AST parsing — deterministic, fast, no LLM calls for summarization
- Handles unsupported languages gracefully — returns full contents without tracking
Installation
From GitHub (recommended)
npx github:YOUR_USERNAME/mcp-file-compaction
Local development
git clone https://github.com/YOUR_USERNAME/mcp-file-compaction.git
cd mcp-file-compaction
npm install
npm run build
Configuration
Add to your Claude Code MCP settings:
{
"mcpServers": {
"file-compaction": {
"command": "npx",
"args": ["github:YOUR_USERNAME/mcp-file-compaction"]
}
}
}
Or for local development:
{
"mcpServers": {
"file-compaction": {
"command": "node",
"args": ["/path/to/mcp-file-compaction/dist/index.js"]
}
}
}
Add to your CLAUDE.md:
## File Operations
Use the file-compaction MCP server for file operations:
- `read_file` instead of `Read` when you need full file contents
- `peek_file` when you only need to check interfaces
- `edit_file` instead of `Edit` for modifications
- `write_file` instead of `Write` for new files
- `file_status` to see tracked files and context savings
This reduces context window size by keeping only summaries of inactive files.
Tools
read_file
Read a file and mark it as the active file. When you switch to a different file, the previous file is automatically summarized.
{ "path": "src/lib.rs" }
peek_file
Get a summary of a file's public interface without changing the active file. Useful for checking APIs.
{ "path": "src/ptr.rs" }
edit_file
Edit a file by replacing a specific string. The file becomes (or remains) the active file.
{
"path": "src/lib.rs",
"old_string": "fn old_name(",
"new_string": "fn new_name("
}
write_file
Write content to a file, creating it if needed. The file becomes the active file.
{
"path": "src/new_module.rs",
"content": "//! New module\n\npub fn hello() {}\n"
}
file_status
Show all tracked files with size comparison and savings.
Context Status
==============
Active: src/paged_pool.rs (full, 4.2 KB)
Cached Summaries:
src/ptr.rs 312 B (was 2.1 KB, saved 1.8 KB)
src/raw_page.rs 428 B (was 3.4 KB, saved 3.0 KB)
Total Context: 5.2 KB
Without Compaction: 11.5 KB
Savings: 6.3 KB (55%)
forget_file
Remove a file from tracking entirely.
{ "path": "src/old_file.rs" }
Supported Languages
Currently supported for summarization:
- Rust (.rs) — extracts public structs, enums, traits, functions, type aliases, constants, and re-exports
Unsupported file types are read/edited normally without tracking—they won't interfere with compaction.
How Summaries Work
For a Rust file like:
//! Type-safe pointer wrappers.
use std::marker::PhantomData;
#[derive(Debug, Clone)]
pub struct Ptr<T> {
raw: *mut T,
_marker: PhantomData<T>,
}
impl<T> Ptr<T> {
pub fn new(raw: *mut T) -> Self {
Self { raw, _marker: PhantomData }
}
pub fn is_null(&self) -> bool {
self.raw.is_null()
}
// Private helper
fn internal_check(&self) -> bool {
!self.raw.is_null()
}
}
The summary becomes:
// Purpose: Type-safe pointer wrappers.
#[derive(Debug, Clone)]
pub struct Ptr<T> { ... }
impl<T> Ptr<T> {
pub fn new(raw: *mut T) -> Self;
pub fn is_null(&self) -> bool;
}
Private items, implementation details, and doc comments are condensed—only the public interface remains.
License
MIT
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.