repomap-mcp

repomap-mcp

An MCP server that generates ranked, token-budgeted code structure maps using Tree-sitter AST analysis and PageRank, enabling AI agents to quickly understand unfamiliar codebases.

Category
访问服务器

README

repomap-mcp

<p align="center"> <img src="public/cover.jpg" alt="repomap-mcp" width="100%" /> </p>

<p align="center"> <a href="https://www.npmjs.com/package/repomap-mcp"><img src="https://img.shields.io/npm/v/repomap-mcp.svg" alt="npm version" /></a> <a href="https://github.com/fl0w1nd/repomap-mcp/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/repomap-mcp.svg" alt="license" /></a> <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/repomap-mcp.svg" alt="node" /></a> </p>

中文文档

An MCP server and CLI tool that generates ranked, token-budgeted code structure maps using Tree-sitter AST analysis and PageRank. Designed for AI agents that need to quickly understand unfamiliar codebases.

Inspired by aider's repo map, reimplemented in TypeScript via RepoMapper.

Why repomap-mcp?

AI coding agents face a fundamental problem: large codebases don't fit in a context window. Without structural awareness, agents resort to guessing file paths, reading irrelevant code, or asking the user to point them to the right place.

Without repomap-mcp With repomap-mcp
Codebase understanding Blindly cat files one by one Get a ranked structural overview in one call
Finding related code Grep for strings, miss semantic connections PageRank surfaces cross-file dependencies
Token efficiency Read entire files, blow context budget Token-budgeted output, only the important parts
Multi-language repos Regex-based hacks per language 40+ languages via Tree-sitter AST, zero config
Task-specific focus Same flat file listing every time Personalized ranking based on focus files and identifiers

Key Features

  • Semantic, not textual — uses Tree-sitter AST to extract real definitions and references, not string matching
  • PageRank ranking — files that are heavily referenced across the codebase rank higher, just like important web pages
  • Neighbor propagation — when focusing on a type definition file, code that uses those types also gets boosted
  • Token-budgeted — binary search automatically selects the maximum amount of relevant code that fits your budget
  • Context-aware rendering — shows parent scopes (class/function signatures) around each definition, not raw line dumps
  • Disk cache — parsed tags are cached per-file with mtime invalidation; subsequent runs are near-instant
  • Zero config — auto-detects MCP mode, respects .gitignore, discovers languages by extension

How It Works

Source files ──scan──▶ Tree-sitter AST ──extract──▶ Definitions & References
                                                            │
                                                            ▼
                                                  Cross-file ref graph
                                                            │
                                                            ▼
Token-budgeted output ◀──select── Ranked definitions ◀──PageRank──┘
  1. File discovery — recursive scan respecting .gitignore
  2. AST parsing — Tree-sitter (WASM) with Aider's SCM queries, 40+ languages
  3. Graph construction — cross-file reference edges (file A references identifier defined in file B → A→B)
  4. PageRank — personalized ranking with neighbor propagation for focus/priority files
  5. Token budgeting — binary search to fit the most relevant definitions within a token limit
  6. Context rendering — code snippets with parent scope context and elision

Quick Start

As an MCP Server

Add to your MCP client config (Claude Desktop, Cursor, Windsurf, etc.):

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

The server auto-detects MCP mode when stdin is piped — no flags needed.

As a CLI Tool

# Generate a repo map for the current directory
npx repomap-mcp --root .

# With token limit and verbose report
npx repomap-mcp --root /path/to/repo --map-tokens 4096 --verbose

# Focus on known files, boost specific identifiers
npx repomap-mcp --root . --focus-files src/db.ts --priority-idents "UserService"

Use Cases

1. Explore an unfamiliar codebase

"I just cloned this repo. Give me a structural overview."

The agent calls repo_map with just projectRoot. The output is a ranked list of the most important definitions across the entire codebase — entry points, core types, key functions — all within the token budget.

2. Investigate code around a known file

"I've read src/lib/db.ts. What else should I look at?"

The agent sets focusFiles: ["src/lib/db.ts"]. The map now centers around db.ts — files that import its types, functions that call its exports — while db.ts itself is excluded since the agent already has it.

3. Locate a specific symbol

"Where is handleWebSocket defined and who calls it?"

The agent calls search_identifiers with query: "handleWebSocket". Returns definition sites and all reference sites with surrounding code context.

4. Task-focused deep dive

"Refactor the authentication flow. The key types are in src/auth/types.ts and the main logic is AuthService."

The agent combines parameters:

{
  "projectRoot": "/path/to/repo",
  "focusFiles": ["src/auth/types.ts"],
  "priorityIdentifiers": ["AuthService"],
  "tokenLimit": 4096
}

The output prioritizes: code related to src/auth/types.ts (neighbor propagation), any file defining or heavily using AuthService (×10 boost), all within 4096 tokens.

Prompt Example

Here's a system prompt snippet showing how an AI agent can leverage repomap-mcp:

You have access to the `repo_map` tool. Use it to understand the codebase before
making changes:

1. On first interaction with a repo, call repo_map with just the projectRoot to
   get an overview.
2. After reading key files, pass them as focusFiles to discover related code you
   haven't seen yet.
3. When the user mentions specific functions or classes, pass them as
   priorityIdentifiers to surface their definitions and usage patterns.
4. Use search_identifiers to locate exact definition and reference sites for any
   symbol.

MCP Tools

repo_map

Generate a ranked repository map of code definitions.

Parameter Type Description
projectRoot string Required. Absolute path to the repository root
focusFiles string[] Already-known files as ranking anchor (×20). Excluded from output
additionalFiles string[] Extra files to include in analysis
priorityFiles string[] Important files to boost in ranking (×5)
priorityIdentifiers string[] Identifier names to boost in ranking (×10)
tokenLimit number Max tokens for output (default: 8192)
excludeUnranked boolean Exclude zero-PageRank files (default: false)
forceRefresh boolean Bypass tag cache (default: false)

search_identifiers

Search for code identifiers across the repository via AST analysis.

Parameter Type Description
projectRoot string Required. Absolute path to the repository root
query string Required. Identifier name (case-insensitive substring match)
maxResults number Max results (default: 50)
includeDefinitions boolean Include definition sites (default: true)
includeReferences boolean Include reference sites (default: true)

CLI Options

Option Default Description
--root <dir> . Repository root directory
--map-tokens <n> 8192 Maximum tokens for output
--focus-files <files...> — Known files; ranking anchor, excluded from output (×20)
--additional-files <files...> — Extra files to include in analysis
--priority-files <files...> — Important files to boost (×5)
--priority-idents <idents...> — Important identifiers to boost (×10)
--verbose false Print report to stderr
--force-refresh false Bypass tag cache
--exclude-unranked false Hide zero-PageRank files
--serve — Force MCP stdio server mode

Supported Languages

Python, JavaScript, TypeScript, Go, Rust, Java, C, C++, C#, Ruby, PHP, Swift, Kotlin, Scala, Dart, Lua, Elixir, Elm, OCaml, Haskell, Julia, Fortran, Clojure, R, Zig, HCL/Terraform, Solidity, and more — 40+ languages via Tree-sitter WASM grammars.

Development

git clone https://github.com/fl0w1nd/repomap-mcp.git
cd repomap-mcp
pnpm install
pnpm build

Debug with MCP Inspector

pnpm inspect

Opens a web UI at http://localhost:6274 for interactive tool testing. Config stored in mcp.json.

Architecture

src/
├── index.ts           Entry point — CLI / MCP mode dispatch
├── server.ts          MCP server and tool registration
├── cli.ts             CLI argument parsing
├── repomap.ts         Core pipeline orchestration
├── tags.ts            Tree-sitter tag extraction
├── pagerank.ts        PageRank algorithm
├── tree-context.ts    Code snippet rendering with context
├── file-discovery.ts  Recursive file scanning + .gitignore
├── languages.ts       Language detection from extensions
├── token-counter.ts   Token counting (gpt-tokenizer)
├── cache.ts           Disk-based tag cache
└── utils.ts           Shared types
queries/               Tree-sitter SCM queries (from Aider)

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

官方
精选