Repo Map 标志

Repo Map

社区
pdavis68

A tool to produce a map of a codebase within a git repository. Based entirely on the "Repo Map" functionality in Aider.chat

发布者pdavis68
代码仓库RepoMapper
语言Tree-sitter Query
复刻数
41
星标数
209
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    Repo Map 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 209 个 Star 和 41 个 Fork。

RepoMap - Command-Line Tool and MCP Server

RepoMap is a powerful tool designed to help, primarily LLMs, understand and navigate complex codebases. It functions both as a command-line application for on-demand analysis and as an MCP (Model Context Protocol) server, providing continuous repository mapping capabilities to other applications. By generating a "map" of the software repository, RepoMap highlights important files, code definitions, and their relationships. It leverages Tree-sitter for accurate code parsing and the PageRank algorithm to rank code elements by importance, ensuring that the most relevant information is always prioritized.

Table of Contents


Aider

RepoMap is 100% based on Aider's Repo map functionality, but I don't believe it shares any code with it. Allow me to explain.

My original effort was to take the RepoMap class from Aider, remove all the aider-specific dependencies, and then make it into a command-line tool. Python isn't my native language and I really struggled to get it to work.

So a few hours ago, I had a different idea. I took the RepoMap and some of its related code from aider and I fed it to an LLM (Either Claude or Gemini 2.5 Pro, can't remember) and had it create specifications for this, basically, from aider's implementation. So it generated a very detailed specification for this application (minus the MCP bits) and then I fed that to, well, Aider with Claude 3.7, and it built the command-line version of this.

I then used a combination of Aider w/Claude 3.7, Cline w/Gemini 2.5 Pro Preview & Gemini 2.5 Flash Preview, and Phind.com, and Gemini.com and Claude.com and ChatGPT.com and after a few hours, I finally got the MCP server sorted out. Again, keeping in mind, Python isn't really my native tongue.


Example Output

> python repomap.py . --chat-files repomap_class.py
Chat files: ['/mnt/programming/RepoMapper/repomap_class.py']
repomap_class.py:
(Rank value: 10.8111)

  36: CACHE_VERSION = 1
  39: TAGS_CACHE_DIR = os.path.join(os.getcwd(), f".repomap.tags.cache.v{CACHE_VERSION}")
  40: SQLITE_ERRORS = (sqlite3.OperationalError, sqlite3.DatabaseError)
  43: Tag = namedtuple("Tag", "rel_fname fname line name kind".split())
  46: class RepoMap:
  49:     def __init__(
  93:     def load_tags_cache(self):
 102:     def save_tags_cache(self):
 459:     def get_ranked_tags_map_uncached(
 483:         def try_tags(num_tags: int) -> Tuple[Optional[str], int]:
 512:     def get_repo_map(

utils.py:
(Rank value: 0.2297)

  18: Tag = namedtuple("Tag", "rel_fname fname line name kind".split())
  21: def count_tokens(text: str, model_name: str = "gpt-4") -> int:
  35: def read_text(filename: str, encoding: str = "utf-8", silent: bool = False) -> Optional[str]:

importance.py:
(Rank value: 0.1149)

   8: IMPORTANT_FILENAMES = {
  27: IMPORTANT_DIR_PATTERNS = {
  34: def is_important(rel_file_path: str) -> bool:
  56: def filter_important_files(file_paths: List[str]) -> List[str]:

    ...
    ...
    ...

Features

  • Smart Code Analysis: Uses Tree-sitter to parse source code and extract function/class definitions
  • Relevance Ranking: Employs PageRank algorithm to rank code elements by importance
  • Token-Aware: Respects token limits to fit within LLM context windows
  • Caching: Persistent caching for fast subsequent runs
  • Multi-Language: Supports Python, JavaScript, TypeScript, Java, C/C++, Go, Rust, and more
  • Important File Detection: Automatically identifies and prioritizes important files (README, requirements.txt, etc.)

Installation

bash
pip install -r requirements.txt

Usage

Basic Usage

bash
# Map current directory
python repomap.py .

# Map specific directory with custom token limit
python repomap.py src/ --map-tokens 2048

# Map specific files
python repomap.py file1.py file2.py

# Specify chat files (higher priority) vs other files
python repomap.py --chat-files main.py --other-files src/

# Specify mentioned files and identifiers
python repomap.py --mentioned-files config.py --mentioned-idents "main_function"

# Enable verbose output
python repomap.py . --verbose

# Force refresh of caches
python repomap.py . --force-refresh

# Specify model for token counting
python repomap.py . --model gpt-3.5-turbo

# Set maximum context window
python repomap.py . --max-context-window 8192

# Exclude files with Page Rank 0
python repomap.py . --exclude-unranked

The tool prioritizes files in the following order:

  1. --chat-files: These files are given the highest priority, as they're assumed to be the files you're currently working on.
  2. --mentioned-files: These files are given a high priority, as they're explicitly mentioned in the current context.
  3. --other-files: These files are given the lowest priority and are used to provide additional context.

Advanced Options

bash
# Enable verbose output
python repomap.py . --verbose

# Force refresh of caches
python repomap.py . --force-refresh

# Specify model for token counting
python repomap.py . --model gpt-3.5-turbo

# Set maximum context window
python repomap.py . --max-context-window 8192

# Exclude files with Page Rank 0
python repomap.py . --exclude-unranked

# Mention specific files or identifiers for higher priority
python repomap.py . --mentioned-files config.py --mentioned-idents "main_function"

How It Works

  1. File Discovery: Scans the repository for source files
  2. Code Parsing: Uses Tree-sitter to parse code and extract definitions/references
  3. Graph Building: Creates a graph where files are nodes and symbol references are edges
  4. Ranking: Applies PageRank algorithm to rank files and symbols by importance
  5. Token Optimization: Uses binary search to fit the most important content within token limits
  6. Output Generation: Formats the results as a readable code map

Output Format

The tool generates a structured view of your codebase showing:

  • File paths and important code sections
  • Function and class definitions
  • Key relationships between code elements
  • Prioritized based on actual usage and references

Dependencies

  • tiktoken: Token counting for various LLM models
  • networkx: Graph algorithms (PageRank)
  • diskcache: Persistent caching
  • grep-ast: Tree-sitter integration for code parsing
  • tree-sitter: Code parsing framework
  • pygments: Syntax highlighting and lexical analysis

Caching

The tool uses persistent caching to speed up subsequent runs:

  • Cache directory: .repomap.tags.cache.v1/
  • Automatically invalidated when files change
  • Can be cleared with --force-refresh

Supported Languages

Currently supports languages with Tree-sitter grammars:

  • arduino
  • chatito
  • commonlisp
  • cpp
  • csharp
  • c
  • dart
  • d
  • elisp
  • elixir
  • elm
  • gleam
  • go
  • javascript
  • java
  • lua
  • ocaml_interface
  • ocaml
  • pony
  • properties
  • python
  • racket
  • r
  • ruby
  • rust
  • solidity
  • swift
  • udev
  • c_sharp
  • hcl
  • kotlin
  • php
  • ql
  • scala

License

This implementation is based on the RepoMap design from the Aider project.


Running as an MCP Server

RepoMap can also be run as an MCP (Model Context Protocol) server, allowing other applications to access its repository mapping capabilities.

Setup

  1. The RepoMap MCP server uses STDIO (standard input/output) for communication. No additional configuration is required for the transport layer.
  2. To set up RepoMap as an MCP server with Cline (or similar tools like Roo), add the following configuration to your Cline settings file (e.g., cline_mcp_settings.json):
json
{
  "mcpServers": {
    "RepoMapper": {
      "disabled": false,
      "timeout": 60,
      "type": "stdio",
      "command": "/usr/bin/python3",
      "args": [
        "/absolute/path/to/repomap_server.py"
      ]
    }
  }
}
  • Replace "/absolute/path/to/repomap_server.py" with the actual path to your repomap_server.py file.

Usage

  1. Run the repomap_server.py script:
bash
python repomap_server.py
  1. The server will start and listen for requests via STDIO.
  2. Other applications can then use the repo_map tool provided by the server to generate repository maps. They must specify the project_root parameter as an absolute path to the project they want to map.

Changelog

7/13/2025 - Removed the project.json dependency. Fixed the MCP server to be a little easier for the LLM to work with in terms of filenames.

将 Repo Map MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Repo Map 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Repo Map 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Repo Map MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "repomapper": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Repo Map MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Repo Map MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Repo Map 帮我完成这项任务吗?
Repo Map
当然。我已阅读。
以下是我使用 Repo Map 得到的结果。

常见问题

Repo Map MCP 服务器有什么用途?

Repo Map 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Repo Map MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Repo Map,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Repo Map MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Repo Map 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Repo Map MCP 连接到 TypingMind?

Repo Map 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Repo Map MCP 在 TypingMind 中提供哪些工具?

Repo Map 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Repo Map MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Repo Map 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇