Skip to main content
Glama
mcp-server-repo-context

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.

CI License: MIT Python 3.10+ Dependencies: none MCP

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+):

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

claude mcp add repo-context -- mcp-server-repo-context serve --root .

Cursor (.cursor/mcp.json in your project)

{
  "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:

mcp-server-repo-context pack --budget 8000 > context.md   # paste into any LLM

Related MCP server: TokenSaver MCP

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:

<!-- ~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:

> {"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 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

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 and the good first issues. Questions or ideas? Open a discussion. Please follow the Code of Conduct.

License

MIT © 2026 Sangram More

More from metraflaxtech-png

  • agent-toolbelt: ready-to-use skills, rules, and prompts for AI coding agents (Claude Code, Cursor, AGENTS.md)

  • prompttest: regression-test LLM prompts with YAML suites in CI

  • agents-md-sync: one source for AGENTS.md, CLAUDE.md, Cursor rules, and Copilot instructions

Available Tools

5 tools
estimate_tokensA

Estimate how many LLM tokens a file or directory would cost before you load it.

Inputs: path, exclude, include.

pack_repoB

Pack the repo tree plus the most important files into one markdown document that fits a token budget. Skipped files are listed, never truncated silently.

Inputs: path, exclude, include, budget_tokens.

read_fileC

Read one text file by repo-relative path, optionally a line range.

Inputs: path (required), end_line, start_line.

repo_treeA

Show the repository directory tree (respects .gitignore). Use first to orient yourself in an unfamiliar codebase.

Inputs: path, exclude, include.

search_codeC

Search the repository for a text or regex query; returns path, line number, and the matching line.

Inputs: query (required), regex, exclude, include, +1 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 5 tools

    Disambiguation5/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Provides AI agents with secure, read-only file system access to analyze and understand project codebases, enabling multi-repository context aggregation and cross-project code tracing.
      5
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables coding agents to get a compact, token-budgeted map of any repository in one call, including file tree, language stats, entry points, and key symbols, so they read only what they need.
      4
      1
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables AI coding agents to retrieve focused, bounded repository context locally and read-only, reducing token usage while never modifying the repository or executing its code.
      -
    • A
      license
      B
      quality
      A
      maintenance
      Enables coding agents to query a repository's code graph and project memory through cited excerpts, navigate symbols and dependencies, and optionally inspect pull requests, all within a configurable token budget.
      22
      641
      Apache 2.0