MCP File Compaction

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.

Category
访问服务器

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:

  1. Implement ptr.rs (2KB) → Context: 2KB
  2. Implement raw_page.rs using ptr.rs (3KB) → Context: 5KB
  3. Implement paged_pool.rs using 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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选