large-repo-mcp-server

large-repo-mcp-server

A stdio-based MCP server for fast, bounded search and navigation of large code repositories using ripgrep, with tools for project-wide search, symbol lookup, file listing, and code reading.

Category
访问服务器

README

Large Repo MCP Server

Stdio-based Model Context Protocol server designed as a standard toolkit for large and complex repositories. Uses ripgrep for fast, bounded search across codebases of any size.

Architecture

┌─────────────────────────────────────────────────────────────────┐
│  MCP Client (Codex CLI / Claude Desktop / Claude Code)          │
│                                                                 │
│   tools/call ──►  JSON-RPC 2.0 request                          │
│                   Content-Length: N\r\n\r\n{...}                │
└─────────────┬───────────────────────────────────▲───────────────┘
              │ stdin                              │ stdout
              ▼                                    │
┌─────────────────────────────────────────────────────────────────┐
│  large-repo-mcp server                                          │
│                                                                 │
│  ┌──────────┐    ┌────────────┐    ┌──────────────────────┐     │
│  │  Frame   │───►│  JSON-RPC  │───►│    Tool Dispatch     │     │
│  │  Parser  │    │  Router    │    │                      │     │
│  │          │    │            │    │  project_search_rg   │     │
│  │ Content- │    │ initialize │    │  symbol_search       │     │
│  │ Length   │    │ tools/list │    │  read_range          │     │
│  │ framing  │    │ tools/call │    │  list_files          │     │
│  └──────────┘    │ ping       │    └──────────┬───────────┘     │
│                  └────────────┘               │                 │
│                                               │                 │
│  ┌────────────────────────────────────────────▼──────────┐      │
│  │  Security Layer                                       │      │
│  │                                                       │      │
│  │  • Path confinement (resolve + realpath + root check) │      │
│  │  • Command allowlist (rg only, shell: false)          │      │
│  │  • Request size limit (1 MB)                          │      │
│  │  • Response size limit (200 KB)                       │      │
│  │  • Null-byte rejection                                │      │
│  └───────────────────────────┬───────────────────────────┘      │
│                              │                                  │
│                              ▼                                  │
│                     ┌─────────────────┐                         │
│                     │  rg (ripgrep)   │                         │
│                     │  subprocess     │                         │
│                     │                 │                         │
│                     │  • 15s timeout  │                         │
│                     │  • JSON output  │                         │
│                     │  • Streaming    │                         │
│                     └─────────────────┘                         │
│                                                    stderr ──►   │
│                                          structured JSON logs   │
└─────────────────────────────────────────────────────────────────┘

Request Flow

Client                          Server                         ripgrep
  │                               │                               │
  │  Content-Length: N\r\n\r\n    │                               │
  │  {"jsonrpc":"2.0",            │                               │
  │   "method":"tools/call",...}  │                               │
  │──────────────────────────────►│                               │
  │                               │  validate request size (≤1MB) │
  │                               │  parse JSON-RPC frame         │
  │                               │  validate tool + arguments    │
  │                               │  resolve & confine paths      │
  │                               │                               │
  │                               │  spawn rg --json ...          │
  │                               │──────────────────────────────►│
  │                               │                               │
  │                               │  stream results (line-by-line)│
  │                               │◄──────────────────────────────│
  │                               │                               │
  │                               │  enforce match/byte limits    │
  │                               │  kill rg if limit reached     │
  │                               │                               │
  │  Content-Length: M\r\n\r\n    │                               │
  │  {"jsonrpc":"2.0",            │                               │
  │   "result":{...}}             │                               │
  │◄──────────────────────────────│                               │
  │                               │                               │

Safety Guarantees

Guarantee Mechanism Limit
Fast, bounded search ripgrep with match caps 500 max matches
Response size cap Byte-level output budget 200 KB
Subprocess timeout setTimeout + child.kill() 15 seconds
Path confinement path.resolve + realpath + root prefix check repo root only
Symlink escape prevention fs.realpath() resolves then re-validates double-checked
Command execution Allowlist (rg only) + shell: false no shell injection
Request size limit Frame-level rejection before parse 1 MB
Input sanitization Null-byte rejection, type validation all tool inputs
Child process cleanup Tracked set, killed on shutdown signals SIGTERM/SIGINT/exit

Supported Clients

Requirements

  • Node.js 18+
  • ripgrep (rg) on PATH
    • symbol_search requires PCRE2 support (most official packages include it)

Verify ripgrep:

rg --version        # should show version
rg --pcre2-version  # should show PCRE2 version

Install ripgrep:

Platform Command
macOS brew install ripgrep
Ubuntu/Debian sudo apt-get install ripgrep
Fedora sudo dnf install ripgrep
Windows winget install BurntSushi.ripgrep.MSVC
Cargo cargo install ripgrep --features pcre2

Install

npm install
npm run build

Run

npm start

Default repo root behavior:

  • If REPO_ROOT is unset, repo root is current working directory (process.cwd()).
  • Set REPO_ROOT to override explicitly.

PowerShell:

$env:REPO_ROOT = "C:\absolute\path\to\repo"
npm start

MCP Configuration

Codex (Global)

Add to ~/.codex/config.toml:

[mcp_servers.large_repo_mcp]
command = "node"
args = ["C:/absolute/path/to/mcp/dist/server.js"]
startup_timeout_sec = 30

[mcp_servers.large_repo_mcp.env]
REPO_ROOT = "."

Codex (Project-Local)

Add to .codex/config.toml in a project:

[mcp_servers.large_repo_mcp]
command = "node"
args = ["C:/absolute/path/to/mcp/dist/server.js"]
startup_timeout_sec = 30

[mcp_servers.large_repo_mcp.env]
REPO_ROOT = "."

Claude Desktop

Add to Claude Desktop MCP config:

{
  "mcpServers": {
    "large_repo_mcp": {
      "command": "node",
      "args": ["C:/absolute/path/to/mcp/dist/server.js"],
      "env": {
        "REPO_ROOT": "C:/absolute/path/to/target-repo"
      }
    }
  }
}

Claude Code

Add to .mcp.json in a project or ~/.claude/mcp.json globally:

{
  "mcpServers": {
    "large_repo_mcp": {
      "command": "node",
      "args": ["C:/absolute/path/to/mcp/dist/server.js"],
      "env": {
        "REPO_ROOT": "."
      }
    }
  }
}

Environment Variables

Variable Default Description
REPO_ROOT process.cwd() Repository root directory
LARGE_REPO_MCP_LOG_LEVEL error Log level: error, warn, info, debug
LARGE_REPO_MCP_DEBUG Set to 1 to force debug logging

Tools

project_search_rg

Search the repository with ripgrep. Supports regex patterns and optional glob filters.

┌──────────────────────────────────────────────────────┐
│  project_search_rg                                   │
│                                                      │
│  Input                          Output               │
│  ─────                          ──────               │
│  pattern (string, required)     matches[]            │
│  globs (string[], max 50)         .path              │
│  maxMatches (1-500, def 100)      .line              │
│                                   .column            │
│                                   .text              │
│                                   .submatches[]      │
│                                 truncated            │
│                                 truncateReason       │
│                                 timedOut             │
│                                 serverVersion        │
│                                 durationMs           │
└──────────────────────────────────────────────────────┘

Example call:

{
  "name": "project_search_rg",
  "arguments": {
    "pattern": "TODO|FIXME",
    "globs": ["*.ts", "*.tsx"],
    "maxMatches": 50
  }
}

symbol_search

Search for an exact symbol using word-boundary matching (\b...\b). Auto-detects project type (TypeScript or Python) and scopes file types accordingly.

┌──────────────────────────────────────────────────────┐
│  symbol_search                                       │
│                                                      │
│  Input                          Output               │
│  ─────                          ──────               │
│  symbol (string, required)      projectType          │
│  maxMatches (1-500, def 100)    matchMode            │
│                                 matches[]            │
│                                   .path              │
│  Detection logic:                 .line              │
│  ┌────────────────────┐          .column             │
│  │ tsconfig.json?     │          .text               │
│  │   yes → typescript │          .submatches[]       │
│  │   no → check files │                              │
│  │   .py only → python│                              │
│  │   .ts only → ts    │                              │
│  │   fallback → ts    │                              │
│  └────────────────────┘                              │
└──────────────────────────────────────────────────────┘

Example call:

{
  "name": "symbol_search",
  "arguments": {
    "symbol": "handleRequest",
    "maxMatches": 20
  }
}

read_range

Read a specific line range from a file. Path must be relative and resolve inside the repo root.

┌──────────────────────────────────────────────────────┐
│  read_range                                          │
│                                                      │
│  Input                          Output               │
│  ─────                          ──────               │
│  path (relative, required)      path (normalized)    │
│  startLine (int, required)      requestedLines       │
│  endLine (int, required)        returnedLines        │
│                                 lines[]              │
│  Constraints:                     .line              │
│  • max 500 lines per call         .text              │
│  • path confined to repo root   truncated            │
│  • symlinks resolved + checked  truncateReason       │
└──────────────────────────────────────────────────────┘

Example call:

{
  "name": "read_range",
  "arguments": {
    "path": "src/server.ts",
    "startLine": 1,
    "endLine": 50
  }
}

list_files

List repository files using ripgrep --files with optional glob filters. Excludes .git, node_modules, dist, build, and coverage by default.

┌──────────────────────────────────────────────────────┐
│  list_files                                          │
│                                                      │
│  Input                          Output               │
│  ─────                          ──────               │
│  globs (string[], max 50)       files[] (paths)      │
│  maxResults (1-500, def 500)    returned             │
│                                 truncated            │
│  Auto-excluded dirs:            truncateReason       │
│  .git, node_modules, dist,      timedOut             │
│  build, coverage                                     │
└──────────────────────────────────────────────────────┘

Example call:

{
  "name": "list_files",
  "arguments": {
    "globs": ["src/**/*.ts"],
    "maxResults": 100
  }
}

Project Type Detection

The server auto-detects whether a repository is TypeScript or Python to scope symbol_search file types. Detection runs once per process and is cached.

                    ┌─────────────────────┐
                    │  tsconfig.json      │
                    │  exists?            │
                    └──────┬──────────────┘
                     yes   │         no
                ┌──────────┘         │
                ▼                    ▼
         ┌──────────┐    ┌────────────────────┐
         │TYPESCRIPT│    │ Python project     │
         └──────────┘    │ file exists?       │
                         │ (pyproject.toml,   │
                         │  requirements.txt, │
                         │  setup.py, etc.)   │
                         └──────┬─────────────┘
                          yes   │         no
                     ┌──────────┤          │
                     ▼          │          ▼
              ┌────────────┐   │  ┌──────────────────┐
              │package.json│   │  │ package.json     │
              │  exists?   │   │  │ exists?          │
              └─────┬──────┘   │  └──────┬───────────┘
               yes  │     no   │    yes  │       no
                │   │      │   │     │   │        │
                ▼   │      ▼   │     ▼   │        ▼
          ┌────────┐│ ┌──────┐ │ ┌──────────┐ ┌──────────────┐
          │  Both  ││ │PYTHON│ │ │TYPESCRIPT│ │ Count .ts vs │
          │  scan  ││ └──────┘ │ └──────────┘ │ .py files    │
          │ files  │▼          ▼              └──────┬───────┘
          └───┬────┘     ┌──────────┐          more  │  more
              │          │ No pkg,  │          .py   │  .ts
              ▼          │ has py   │           │    │
       ┌────────────┐    │ file →   │           ▼    ▼
       │ .py only → │    │ PYTHON   │      ┌──────┐ ┌──┐
       │   PYTHON   │    └──────────┘      │PYTHON│ │TS│
       │ .ts only → │                      └──────┘ └──┘
       │   TS       │
       │ fallback → │
       │   TS       │
       └────────────┘

Dev Workflow

npm run typecheck    # type-check without emitting
npm test             # build + run unit & integration tests
npm run lint         # run ESLint
npm run format:check # check Prettier formatting

Troubleshooting

Problem Solution
rg not found Install ripgrep and ensure it is on PATH
symbol_search PCRE2 error Install ripgrep with PCRE2 support (most official packages include it)
Request exceeds 1048576 bytes Split large requests; max inbound JSON-RPC frame body is 1 MB
truncated: true Increase maxMatches/maxResults (up to bounds), narrow your query, or add globs
No results from symbol_search Check projectType in response — detection may have picked the wrong language; use project_search_rg as a fallback

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

官方
精选