ContextCache MCP

ContextCache MCP

A local MCP server that indexes TypeScript/JavaScript projects and returns budget-aware, dependency-optimized context packs for AI coding assistants.

Category
访问服务器

README

ContextCache MCP

Budget-aware context packs for AI coding assistants.
Stop sending entire codebases to your LLM. Send only what matters — within a token budget you control.

Node MCP License: MIT TypeScript

ContextCache is a local MCP server that indexes your TypeScript/JavaScript project and returns Context Packs — minimal, dependency-aware file sets optimized for a specific task.

Works with Cursor, Claude Code, Codex CLI, and any MCP-compatible client.


Why use ContextCache?

Without ContextCache With ContextCache
AI reads 200–500 files blindly AI receives 5–15 ranked files
50k+ tokens per request 2k–8k tokens within your budget
Misses UserRepository.ts behind AuthService.ts Dependency graph expands related files
No visibility into context cost token_metrics + relevance_score on every pack

Example: task "fix login bug" on a 500-file repo → returns AuthService.ts, JwtMiddleware.ts, and their dependencies — not your entire src/ tree.


Features

  • Budget-aware selection — set budget_tokens; engine stops before exceeding it
  • Dependency graph — BFS expansion from seed files (not flat keyword search)
  • AST-based indexing — TypeScript Compiler API extracts classes, functions, imports, exports
  • Incremental index — skips unchanged files via content_hash
  • Query cache — instant responses for repeated tasks (auto-invalidated on reindex)
  • Relevance score — 0.0–1.0 signal strength on every pack
  • 100% local — SQLite on disk, no cloud, no API keys, no embeddings required
  • Two MCP toolsget_context_pack, get_file_summary

Quick start

Prerequisites

  • Node.js 20+
  • A TypeScript or JavaScript project to index

1. Clone & build

git clone https://github.com/YOUR_USERNAME/contextcache-mcp.git
cd contextcache-mcp
npm install
npm run build

2. Index your project

# From your project root:
node /path/to/contextcache-mcp/apps/indexer/dist/cli.js init
node /path/to/contextcache-mcp/apps/indexer/dist/cli.js index
node /path/to/contextcache-mcp/apps/indexer/dist/cli.js stats

3. Add MCP server to your AI client

Cursor — create or edit .cursor/mcp.json in your project:

{
  "mcpServers": {
    "contextcache": {
      "command": "node",
      "args": ["/absolute/path/to/contextcache-mcp/apps/server/dist/index.js"],
      "env": {
        "CONTEXTCACHE_ROOT": "${workspaceFolder}"
      }
    }
  }
}

Claude Desktop — edit claude_desktop_config.json with the same block.

See mcp-config.example.json for a template.

4. Use it

Ask your assistant to call get_context_pack at the start of a coding task:

{
  "task": "fix authentication bug in login flow",
  "budget_tokens": 4000,
  "mode": "cursor"
}

Sample response:

{
  "relevance_score": 0.84,
  "budget_used": 2300,
  "budget_remaining": 1700,
  "summary": "3 core files, 2 dependencies via graph.",
  "files": [
    {
      "path": "src/auth/AuthService.ts",
      "score": 0.92,
      "summary": "Classes: AuthService. Exports: login, authenticate",
      "token_estimate": 340
    }
  ],
  "dependencies": [
    { "path": "src/repos/UserRepository.ts", "relation": "imported_by", "depth": 1 }
  ],
  "token_metrics": {
    "full_project_tokens": 58000,
    "selected_tokens": 2300,
    "saved_tokens": 55700,
    "reduction_percent": 96.0
  }
}

MCP tools

get_context_pack

Builds a complete context pack for a task.

Parameter Type Default Description
task string required What you want to accomplish
budget_tokens number 8000 Maximum tokens for the pack
mode "json" | "text" | "cursor" "json" text/cursor returns markdown
use_snapshot boolean false Compare against manual snapshot baseline
skip_cache boolean false Bypass query cache

get_file_summary

Returns structured metadata for a single file.

{ "path": "src/auth/AuthService.ts" }

CLI

npm run contextcache -- <command>
Command Description
init [path] Create .contextcache/ in a project
index [paths...] Index TS/JS files (incremental)
stats Index stats, token totals, relevance averages
snapshot Save a manual baseline snapshot
pack <task> Generate a context pack from terminal
# Human-readable pack
npm run contextcache -- pack "fix login bug" -b 4000 -m text

# JSON pack
npm run contextcache -- pack "fix login bug" -b 4000 -m json

How it works

Your task + budget_tokens
         │
         ▼
   QueryCache ── hit? ──► return cached pack
         │ miss
         ▼
   HeuristicRanker ──► rank files by symbols, paths, imports
         │
         ▼
   DependencyGraph ──► expand related files (BFS, 2 hops)
         │
         ▼
   TokenBudgetManager ──► select files until budget is full
         │
         ▼
   Context Pack + relevance_score + token_metrics

Ranking signals: symbol match · path match · graph proximity · import match


Benchmarks

npm run benchmark
npm run benchmark:report   # saves benchmarks/results/latest.json

Tracks relevance_score, precision, reduction_percent, and generation_time_ms against fixture projects.


Project structure

contextcache-mcp/
├── apps/
│   ├── shared/     # ContextEngine, DependencyGraph, indexer
│   ├── indexer/    # CLI (contextcache)
│   └── server/     # MCP server (stdio)
├── benchmarks/
├── mcp-config.example.json
└── ARCHITECTURE.md

Each indexed project gets a .contextcache/ folder:

your-project/.contextcache/
├── config.json
└── contextcache.db

What it is NOT

  • Not a RAG / vector search tool
  • Not a cloud service
  • Not a flat file finder — it builds coherent packs via dependency graph
  • Not dependent on paid embedding APIs (MVP)

Roadmap

  • [ ] Python & C# parsers (tree-sitter)
  • [ ] Optional semantic search (local embeddings)
  • [ ] get_related_files tool
  • [ ] npm global install (npx contextcache)

Requirements

Requirement Version
Node.js 20+
Languages (MVP) TypeScript, JavaScript

Contributing

Issues and PRs welcome. See ARCHITECTURE.md for technical details.

  1. Fork the repo
  2. Create a branch (git checkout -b feature/my-feature)
  3. Run npm run build && npm run benchmark
  4. Open a PR

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选