Skip to main content
Glama

⚡ RepoContext

CI npm version License: MIT MCP Compatible TypeScript

面向 AI 编码代理和 IDE 的下一代 AST 代码库地图、Token 压缩与上下文打包引擎。

English | 中文说明


🌟 为什么选择 RepoContext?

在将代码库输入现代 AI 编码助手(Claude CodeCursorWindsurfOpenAI CodexAntigravityCline)时,开发者面临三大关键瓶颈:

  1. 💥 Token 爆炸与高昂 API 成本:原始代码转储会迅速超出上下文限制,或每次查询花费数十美元。

  2. 📉 信噪比低:80% 的代码行都是常规实现细节。LLM 只需要语义 API 表面(签名、类型、接口、文档字符串)。

  3. 🔓 安全泄露:在提示词中意外暴露 .env 凭据、API 密钥和数据库 URI。

RepoContext 通过智能 AST 大纲剪枝、任务聚焦的语义文件排序、自动凭据脱敏以及原生 Model Context Protocol (MCP) 集成,一举解决以上三大问题。


Related MCP server: AtlasMemory

🚀 核心特性

  • AST 代码库地图与骨架化:将源文件压缩 70%~85%,同时保留 100% 的接口、类型、函数和 JSDoc/文档字符串。

  • 🎯 任务导向的相关性剪枝:传入你的提示词查询(例如 repocontext pack -q "修复 JWT 认证令牌过期问题"),自动排序并只打包最关键的代码文件。

  • 🛡️ 自动密钥扫描与脱敏:内置熵和正则扫描器,可检测并遮蔽 OpenAI 密钥、GitHub 令牌、AWS 密钥、JWT 和数据库 URI。

  • 🔌 原生 Model Context Protocol (MCP) 服务器:通过标准 MCP 工具直接集成 Claude Desktop、Cursor、Windsurf 和 Antigravity。

  • 📑 多格式导出:生成包含目录树的干净 Markdown、针对 Claude 优化的 XML(<documents>)或结构化 JSON。

  • 📊 多模型 Token 与成本分析:实时 Token 计数器,支持 GPT-4o、GPT-5、Claude 3.5 Sonnet 和 Gemini 1.5 Pro 的成本估算。


📦 快速开始

1. 通过 npx 免安装运行

# Pack entire repository into an optimized Markdown prompt
npx repocontext pack

# Pack only files relevant to a specific task prompt
npx repocontext pack -q "Implement Stripe payment webhook handler" -o prompt.md

# Generate lightweight AST skeleton map (75%+ token reduction)
npx repocontext map -o codebase-map.md

2. 全局安装

npm install -g repocontext

🛠️ CLI 用法与选项

repocontext pack [dir] [options]

Options:
  -m, --mode <mode>         Packing mode: full | ast | relevant | hybrid (default: "full")
  -q, --query <query>       Filter and rank files relevant to a coding task prompt
  -f, --format <format>     Output format: markdown | xml | json (default: "markdown")
  -o, --output <file>       Output file path (default: "repocontext-output.md")
  -t, --max-tokens <number> Maximum token budget ceiling (default: 80000)
  --no-security             Disable secret scanning and auto-redaction
  -h, --help                Display help for command

🔌 Model Context Protocol (MCP) 集成

RepoContext 内置 MCP 服务器支持。将其添加到你的 claude_desktop_config.json 或 Cursor/Windsurf 的 MCP 设置中:

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

暴露的 MCP 工具:

  • get_codebase_map:返回代码库的 AST 符号大纲地图。

  • extract_relevant_context:剪枝代码库,仅返回提示词所需的文件。

  • read_file_outline:读取单个文件的压缩 AST 骨架。


📊 基准与对比

功能特性

原始拼接

Repomix

RepoContext

AST 骨架剪枝

❌ 否

❌ 否

是(节省 80% Token)

任务相关性排序

❌ 否

❌ 否

是(查询引导剪枝)

密钥自动脱敏

❌ 否

⚠️ 基础

是(10+ 安全规则)

原生 MCP 服务器

❌ 否

❌ 否

是(Claude / Cursor / Windsurf)

多模型成本估算

❌ 否

❌ 否

是(GPT-4o/5、Claude、Gemini)


🤝 参与贡献

欢迎提交贡献、Issue 和功能请求!欢迎查看问题页面

📄 许可证

本项目采用 MIT 许可证。

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Provides intelligent code context and analysis through semantic compression, AST parsing, and multi-language support. Offers 60-80% token reduction while enabling AI assistants to understand codebases through local analysis, OpenAI-enhanced insights, and GitHub repository integration.
    6
    12
    3
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Turn any codebase into an AI-readable neural map — with proof. Every claim linked to code anchors (line + SHA-256 hash), every context window optimized with greedy token budgeting, every session protected by drift detection. Tree-sitter indexing across 11 languages, cross-session learning, AI enrichment, and 28 MCP tools. Zero config — just connect and your AI agent remembers everything.
    45
    13
    GPL 3.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    Make any LLM a codebase expert instantly. Provides deep code intelligence through semantic search, architecture mapping, security analysis, and smart context that fits perfectly in token windows.
    MIT

View all related MCP servers

Related MCP Connectors

  • Deterministic context layer for your codebase: change impact, blast radius, answers with receipts.

  • Give your AI agent a persistent map of your project's structure, dependencies, and bugs.

  • Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ILoveMyJay/repocontext'

If you have feedback or need assistance with the MCP directory API, please join our Discord server