repo-context-mcp
MCP server that helps AI coding agents understand a repository by providing lightweight tree/map, code search, and token-budgeted context packing tools without dumping the entire monorepo into the prompt.
README
repo-context-mcp
MCP server that helps AI coding agents understand a repository — without dumping the entire monorepo into the prompt.
Works with Codex, Claude Code, Cursor, Cline, and any client that speaks Model Context Protocol.
Why
AI agents waste tokens re-walking node_modules, missing entrypoints, or pasting random files. repo-context-mcp exposes three focused tools:
| Tool | Purpose |
|---|---|
repo_map |
Lightweight tree + manifests/entrypoints |
search_code |
Fast substring search with path:line hits |
pack_context |
Token-budgeted markdown pack for LLM prompts |
Local-only. No cloud. No telemetry. Stdio transport.
Install
# run from source
git clone https://github.com/nduc99911/repo-context-mcp.git
cd repo-context-mcp
npm install
npm run build
# or via npx (after publish)
npx -y repo-context-mcp
Requires Node.js 18+.
CLI (no MCP client)
npm run build
# repository map
node dist/cli.js map .
node dist/cli.js map examples/sample-repo
# search
node dist/cli.js search login examples/sample-repo
# token-aware pack
node dist/cli.js pack . --focus auth,api --max-tokens 8000
# JSON for scripts / CI
node dist/cli.js map . --json
node dist/cli.js pack . --focus src --json
After global install / npx:
npx repo-context-mcp map .
npx repo-context-mcp pack . --focus auth
MCP client config
Claude Desktop / Claude Code
{
"mcpServers": {
"repo-context": {
"command": "npx",
"args": ["-y", "repo-context-mcp"],
"env": {
"REPO_CONTEXT_ROOT": "/absolute/path/to/your/repo"
}
}
}
}
Cursor
Settings → MCP → add server with command npx and args ["-y", "repo-context-mcp"].
Codex / generic stdio
REPO_CONTEXT_ROOT=/path/to/repo node /path/to/repo-context-mcp/dist/server.js
From this repository after build:
npm run build
node dist/cli.js serve
# or: node dist/server.js
See also examples/mcp-config.claude.json and examples/mcp-config.local.json.
Optional env:
| Variable | Meaning |
|---|---|
REPO_CONTEXT_ROOT |
Default repository root when tools omit root |
Each tool also accepts an explicit root argument.
Tools
repo_map
root?: string
max_depth?: number # default 6
max_entries?: number # default 400
Returns a markdown tree, file count, and likely entrypoints (package.json, README.md, src/index.ts, AGENTS.md, …). Skips node_modules, .git, dist, etc.
search_code
query: string
root?: string
max_results?: number # default 50
case_sensitive?: boolean
Substring search across source-like extensions.
pack_context
root?: string
focus?: string[] # keywords / path fragments to prioritize
max_tokens?: number # default 12000 (approx)
max_files?: number # default 40
Ranks files (entrypoints + focus matches), respects a rough token budget (~4 chars/token), and returns a single markdown document ready to paste into an agent prompt or PR review.
Library API
You can use the core without MCP:
import {
buildRepoMap,
formatRepoMap,
searchCode,
packContext,
} from "repo-context-mcp";
const map = buildRepoMap({ root: process.cwd() });
console.log(formatRepoMap(map));
const hits = searchCode({ root: process.cwd(), query: "TODO" });
const pack = packContext({
root: process.cwd(),
focus: ["auth"],
maxTokens: 8000,
});
console.log(pack.markdown);
Demo (no MCP client)
npm install
npm test
npm run build
# map the sample tree
node --input-type=module -e "import { buildRepoMap, formatRepoMap } from './dist/index.js'; console.log(formatRepoMap(buildRepoMap({ root: 'examples/sample-repo' })));"
Security
- Reads files only under the requested
root. - Does not execute project code.
- Skips common vendor dirs and obvious binaries.
- Still: only point it at repositories you trust.
See SECURITY.md.
Project status
v0.1.1 — MCP server + CLI + gitignore + PR Action.
Roadmap:
- [x]
.gitignorerespect - [x] CLI (
map/search/pack) +--json - [x] GitHub Action: pack context on each PR
- [ ] Optional ripgrep backend for large monorepos
- [ ] Baseline symbol index (tree-sitter) for
find_symbol - [ ] Configurable ignore file (
.repo-contextignore)
Contributing
See CONTRIBUTING.md.
npm install
npm test
npm run lint
npm run build
License
MIT © Nguyen Duc
Built as a real maintainer / agent-tooling utility for the MCP ecosystem — not a placeholder repo. Issues and PRs welcome.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。