mcp-context

mcp-context

A plugin that intercepts large MCP tool outputs, indexes them into a local FTS5 knowledge base, and replaces them with summaries, enabling searchable retrieval to save context window space.

Category
访问服务器

README

mcp-context

Keep MCP tool output out of context. Search it instead.

License: MIT Node

A Claude Code plugin that intercepts large MCP tool outputs via a PostToolUse hook, indexes them into a local FTS5 knowledge base, and replaces the context-window payload with a ~200-byte summary. The full content stays searchable on demand.

This plugin does not make network calls, move credentials, nor execute commands — minimal security exposure.

How It Works

MCP tool returns 47 KB OpenAPI spec
        │
        ▼
┌──────────────────┐
│  PostToolUse     │──► Below 5 KB? → pass through unchanged
│  Hook            │
│  (posttooluse.   │──► Above 5 KB? ─┐
│   mjs)           │                 │
└──────────────────┘                 │
                                     ▼
                          ┌────────────────────┐
                          │  ContentStore       │
                          │  (SQLite FTS5)      │
                          │                     │
                          │  1. Detect type     │
                          │  2. Chunk content   │
                          │  3. Index chunks    │
                          │  4. Extract vocab   │
                          └────────┬───────────┘
                                   │
                                   ▼
                          Context receives:
                          ~200 B summary +
                          "call search() to
                           retrieve details"
                                   │
                                   ▼
                          ┌────────────────────┐
                          │  MCP Server        │
                          │  search · index ·  │
                          │  stats             │
                          │                    │
                          │  Returns snippets  │
                          │  around matches    │
                          └────────────────────┘

Install

From the Marketplace (recommended)

/plugin marketplace add byliu-labs/mcp-context
/plugin install mcp-context@mcp-context

Restart Claude Code after installing.

From a Local Clone

git clone https://github.com/byliu-labs/mcp-context.git
cd mcp-context
npm install && npm run build
claude plugin:install .

Manual MCP Server Only

Add to your Claude Code MCP config (hook not included):

{
  "mcpServers": {
    "mcp-context": {
      "command": "node",
      "args": ["/path/to/mcp-context/build/server.js"]
    }
  }
}

The Problem

MCP tools return large outputs — accessibility snapshots, API responses, test results, documentation. Every byte enters the context window and counts against the token limit.

A single Playwright snapshot is 26 KB. An OpenAPI spec is 47 KB. A page of server logs is 60 KB. In a session with 20+ tool calls, you burn through context fast.

Architecture

Three components, one SQLite database:

PostToolUse Hook (hooks/posttooluse.mjs) — Intercepts MCP tool output after execution. If output exceeds the byte threshold (default 5 KB), indexes it and replaces it with a summary. Only intercepts mcp__ prefixed tools; built-in tools (Bash, Read, Grep) pass through.

ContentStore (src/store.ts) — FTS5 knowledge base with content-aware chunking and multi-layer search. Shared between hook and server via a deterministic DB path (/tmp/output-indexer-{pid}.db). SQLite WAL mode handles concurrent access.

MCP Server (src/server.ts) — Exposes search, index, and stats tools. The LLM calls search() to retrieve specific content on demand instead of having the full output in context.

Chunking Strategies

Content is detected and chunked by type:

Type Strategy Example
JSON Split by top-level keys, recurse if value > 5 KB API responses, configs
Stack trace Keep error + trace as single unit Node.js, Python, Go panics
Markdown Split by headings with breadcrumb hierarchy Documentation, READMEs
Plain text 50-line groups with 5-line overlap Logs, test output

Search

Three-layer fallback ensures matches even with typos:

  1. Porter stemming — FTS5 with porter unicode61 tokenizer. Handles plurals, tenses.
  2. Trigram substring — Matches partial words and identifiers like handleClick.
  3. Levenshtein fuzzy — Corrects misspellings (edit distance 1-3 based on word length), then re-searches via layers 1-2.

Results return 300-character snippet windows around match positions (using FTS5 highlight() markers), not full chunks — so even search results are compact.

Throttling — Search is rate-limited to prevent the LLM from dumping all indexed content back into context. After 5 calls in a 2-minute window, results are reduced to 1 per query. After 10 calls, search is blocked until the window resets.

The Numbers

Real benchmarks from npm run benchmark — generates realistic data, indexes via ContentStore, measures original bytes vs summary + search results:

Scenario Original Summary Search (top 3) Context used Saved
Playwright snapshot 26.0 KB ~200 B 6.1 KB 6.3 KB 76%
GitHub API (issues) 16.2 KB ~200 B 4.1 KB 4.3 KB 73%
Jest test output 9.7 KB ~200 B 4.4 KB 4.6 KB 53%
OpenAPI spec 47.1 KB ~200 B 1.6 KB 1.8 KB 96%
Node.js stack trace 2.8 KB ~200 B 1.6 KB 1.8 KB 37%
Markdown docs 3.6 KB ~200 B 868 B 1.0 KB 71%
Server access log 60.2 KB ~200 B 18.1 KB 18.2 KB 70%

Summary = hook replacement message (~200 B). Search = top 3 results via searchWithFallback.

Outputs below the 5 KB threshold pass through unchanged — no overhead for small results.

Tools

search

Search indexed content with multi-layer fallback.

search({ queries: ["error database connection", "retry logic"], source: "stack-trace-1", limit: 3 })
  • Batch all queries in one call (array)
  • Use source to scope results to a specific indexed output
  • Returns snippet windows, not full chunks

index

Manually index content into the knowledge base.

index({ content: "...", source: "my-docs" })

Useful for indexing content that didn't come through the hook (e.g., file contents, clipboard data).

stats

Session statistics: bytes indexed, bytes returned to context, savings ratio, per-tool breakdown.

Configuration

Variable Default Description
OUTPUT_INDEXER_THRESHOLD 5120 Byte threshold for indexing (outputs below this pass through)

Set via environment variable:

OUTPUT_INDEXER_THRESHOLD=10240 claude

The SQLite database is created at /tmp/output-indexer-{pid}.db and cleaned up on exit. Stale databases from crashed sessions are garbage-collected on startup (>24h old or dead PID).

Requirements

  • Node.js 18+
  • Claude Code CLI

Contributing

See CONTRIBUTING.md for development setup, testing, and PR guidelines.

License

MIT

Acknowledgments

Search patterns and FTS5 architecture inspired by mksglu/claude-context-mode (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 模型以安全和受控的方式获取实时的网络信息。

官方
精选