mcp-server-repo-context
# mcp-server-repo-context
**MCP server (Model Context Protocol) that gives Claude Code, Cursor, and other AI coding agents token-budgeted repository context: a directory tree, the files that matter most, code search, and token estimates. Python, zero dependencies.**
[](https://github.com/metraflaxtech-png/mcp-server-repo-context/actions/workflows/ci.yml)
[](LICENSE)



AI coding agents waste tokens wandering around a repo. This MCP server lets the agent ask for exactly what it needs: *"show me the tree"*, *"pack the repo into 8,000 tokens"*, *"search for `create_app`"*, *"how many tokens is `src/`?"*. Everything is read-only and confined to the repository root.
## Quick start (under a minute)
Install straight from GitHub (needs Python 3.10+):
```bash
pipx install git+https://github.com/metraflaxtech-png/mcp-server-repo-context.git
# or: uvx --from git+https://github.com/metraflaxtech-png/mcp-server-repo-context.git mcp-server-repo-context --help
```
**Claude Code**
```bash
claude mcp add repo-context -- mcp-server-repo-context serve --root .
```
**Cursor** (`.cursor/mcp.json` in your project)
```json
{
"mcpServers": {
"repo-context": {
"command": "mcp-server-repo-context",
"args": ["serve", "--root", "."]
}
}
}
```
**Claude Desktop and other MCP clients**: use the same `command` and `args`, with an absolute path for `--root`.
No MCP client handy? Use the same engine from the terminal:
```bash
mcp-server-repo-context pack --budget 8000 > context.md # paste into any LLM
```
## Tools
| Tool | What it does |
| --- | --- |
| `repo_tree` | Directory tree, respecting `.gitignore` and skipping `node_modules`, `.git`, build output, lockfiles, binaries |
| `pack_repo` | Tree plus the most important files in one markdown document that fits `budget_tokens`. README and manifests first, tests last. Files that do not fit are listed, never silently truncated |
| `read_file` | One file by repo-relative path, optional line range, with line numbers |
| `search_code` | Case-insensitive text or regex search returning `path:line: text` |
| `estimate_tokens` | Estimated token cost of a file or directory before you load it |
`include` / `exclude` glob lists (for example `["*.py"]`) work on `repo_tree`, `pack_repo`, `search_code`, and `estimate_tokens`.
## Example output
`mcp-server-repo-context pack --budget 300` on a small project:
````text
<!-- ~98 tokens, 4 files included, 0 skipped -->
# Repository: demo
## Tree
```
├── src/
│ └── app.py
├── tests/
│ └── test_app.py
├── README.md
└── pyproject.toml
```
## File: README.md
```
# Demo API
A tiny Flask-style demo.
```
...
````
A `search_code` call over stdio:
```text
> {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_code","arguments":{"query":"create_app"}}}
< {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"src/app.py:1: def create_app():"}],"isError":false}}
```
## FAQ
**What is an MCP server?**
The [Model Context Protocol](https://modelcontextprotocol.io) is an open standard for connecting AI assistants to tools and data. An MCP server exposes tools; clients such as Claude Code and Cursor call them.
**How do I add an MCP server to Claude Code?**
`claude mcp add <name> -- <command> <args>`. For this server: `claude mcp add repo-context -- mcp-server-repo-context serve --root .`
**How do I add an MCP server to Cursor?**
Add an entry under `mcpServers` in `.cursor/mcp.json`, as shown in the quick start.
**How are tokens counted?**
With a fast, dependency-free estimate (roughly 4 characters per token). It is an estimate, not your model's exact tokenizer, so leave some headroom.
**Is it safe to point at a private repo?**
It is read-only, runs locally over stdio, makes no network calls, and rejects any path that escapes the root (including via symlinks). It does not read files over 256 KB or binary files. Still, whatever the agent reads goes to your model provider, so scope `--root` and `exclude` globs accordingly.
**Does it work with other agents?**
Any client that speaks MCP over stdio should work. It implements `initialize`, `ping`, `tools/list`, and `tools/call` (protocol versions 2025-06-18, 2025-03-26, 2024-11-05).
**Does it respect .gitignore?**
Yes, for common patterns: names, globs, trailing-slash directories, and anchored paths. Negation (`!pattern`) is not supported yet; see the open issues.
## Development
```bash
python3 -m pip install -e ".[dev]"
python3 -m pytest
```
CI runs the tests on Python 3.10–3.13 plus a real stdio smoke test. See [CONTRIBUTING.md](CONTRIBUTING.md) and the [good first issues](https://github.com/metraflaxtech-png/mcp-server-repo-context/labels/good%20first%20issue). Questions or ideas? Open a [discussion](https://github.com/metraflaxtech-png/mcp-server-repo-context/discussions). Please follow the [Code of Conduct](CODE_OF_CONDUCT.md).
## License
[MIT](LICENSE) © 2026 Sangram More
## More from metraflaxtech-png
- [agent-toolbelt](https://github.com/metraflaxtech-png/agent-toolbelt): ready-to-use skills, rules, and prompts for AI coding agents (Claude Code, Cursor, AGENTS.md)
- [prompttest](https://github.com/metraflaxtech-png/prompttest): regression-test LLM prompts with YAML suites in CI
- [agents-md-sync](https://github.com/metraflaxtech-png/agents-md-sync): one source for AGENTS.md, CLAUDE.md, Cursor rules, and Copilot instructions
TDQS
Scored across 5 tools
Each tool targets a clearly distinct operation: tree orientation (repo_tree), bulk packing (pack_repo), single-file read (read_file), content search (search_code), and cost pre-checking (estimate_tokens). The only near-overlap is repo_tree vs pack_repo, but descriptions make it clear one is a listing and the other a budgeted document bundle. An agent can pick correctly without guessing.
Four of five names follow a verb_noun pattern (read_file, search_code, estimate_tokens, pack_repo), all in consistent snake_case. repo_tree is a noun-only name, a minor deviation from the otherwise predictable convention.
Five tools is well-scoped for a read-only repo-context server, and each covers a distinct step in the workflow: orient, pack, read, search, budget. No tool feels redundant or missing at this size.
The surface covers the core read-only lifecycle: discover structure, estimate cost, search, read specific files, and bulk-pack under a token budget. Minor gaps remain, such as glob/filtered file listing or a lightweight existence/size check without reading content, but agents can work around these via repo_tree and search_code.