Git仓库分析工具

一个基于MCP协议的Git仓库管理工具,提供代码搜索、跨仓库分析和缓存系统等功能,适用于开发效率提升和代码研究。

  • by DocNR
  • TypeScript
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 DocNR/repo-explorer

使用说明

回购资源管理器

一个强大的MCP(模型上下文协议)服务器,提供无缝探索、搜索和分析Git存储库的工具。

特性

  • 库管理:克隆、更新和管理参考存储库
  • 高级代码搜索:快速查找多个文件中的模式
  • 缓存系统:高效存储搜索结果以提高性能
  • 跨存储库分析:比较多个项目中的代码模式
  • 可配置的存储库结构:轻松自定义您的参考库
  • 独立于平台:适用于macOS、Linux和Windows

安装

先决条件

  • Node.js 18.x或更高版本
  • Git

快速开始

  1. 克隆存储库:
git clone https://github.com/DocNr/repo-explorer.git
cd repo-explorer
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build
  1. 添加到MCP配置中(请参阅 设置和配置 在......下面

工具

回购资源管理器提供了几个MCP工具:

  • repo_status:获取所有存储库或特定存储库的状态
  • clone_repo:克隆特定存储库
  • update_repo:更新(拉取)特定存储库
  • create_reference_repos:创建参考仓库结构
  • search_code:跨存储库搜索代码

配置系统

repo资源管理器使用一个配置系统,允许您:

  • 自定义参考存储库的位置
  • 定义您自己的存储库类别和存储库
  • 跨会话维护设置

默认配置

首次运行时,repoexplorer会在以下位置创建一个配置文件 ~/.repo-explorer.json 使用默认设置。这包括按类别组织的一系列流行存储库:

{
  "repoBaseDir": "~/referencerepos",
  "repositories": {
    "nostr": {
      "ndk": {
        "url": "https://github.com/nostr-dev-kit/ndk",
        "description": "Nostr Development Kit"
      },
      "ndk-mobile": {
        "url": "https://github.com/nostr-dev-kit/ndk-mobile",
        "description": "NDK for mobile platforms"
      },
      "nips": {
        "url": "https://github.com/nostr-protocol/nips",
        "description": "Nostr Implementation Possibilities"
      }
    },
    "databases": {
      "watermelondb": {
        "url": "https://github.com/Nozbe/WatermelonDB",
        "description": "High-performance reactive database for React & React Native"
      }
    },
    "react-native": {
      "core": {
        "url": "https://github.com/facebook/react-native",
        "description": "React Native core"
      },
      "paper": {
        "url": "https://github.com/callstack/react-native-paper",
        "description": "Material Design for React Native"
      },
      "navigation": {
        "url": "https://github.com/react-navigation/react-navigation",
        "description": "Navigation for React Native"
      },
      "expo": {
        "url": "https://github.com/expo/expo",
        "description": "Expo SDK"
      }
    },
    "state-management": {
      "xstate": {
        "url": "https://github.com/statelyai/xstate",
        "description": "State management with state machines"
      },
      "react-query": {
        "url": "https://github.com/TanStack/query",
        "description": "TanStack Query (React Query)"
      },
      "react-hook-form": {
        "url": "https://github.com/react-hook-form/react-hook-form",
        "description": "Form management for React"
      }
    }
  }
}

自定义配置

要自定义配置,请执行以下操作:

  1. 编辑 ~/.repo-explorer.json 文件直接
  2. 根据需要添加、删除或修改类别和存储库
  3. 更改 repoBaseDir 到您首选的存储库位置

缓存系统

repoexplorer实现了一个高级缓存系统,显著提高了重复操作的性能,特别是在代码搜索方面。

性能优势

  • 搜索结果缓存:存储以前搜索的结果以消除冗余文件扫描
  • 存储库结构缓存:维护存储库文件结构的索引,以加快模式匹配
  • 智能缓存无效:更新存储库时自动刷新缓存
  • 结果限制控制:配置最大结果和上下文行以防止上下文窗口溢出

效率增益

缓存系统在不同存储库大小之间提供了显著的性能改进:

存储库大小 文件 无缓存 有缓存 改进
小(~10MB) 100 1.2s 0.05s 96%
中等(~100MB) 1000 5.8s 0.1s 98%
大容量(约1GB) 10000 35秒 0.2秒 99%
非常大(5GB+) 50000+ 3min+ 0.5s 99.7%

*在配备SSD存储的标准开发机器上进行的测试

实现细节

缓存系统使用多级方法:

  • 内存缓存:存储最近的搜索结果以供立即访问
  • 持久缓存:在会话之间维护存储库信息
  • 缓存失效:监控Git更新以确保缓存新鲜度
  • 基于模式的优化:重复使用类似搜索模式的部分结果

设置和配置

适用于Claude桌面应用程序

将repo资源管理器添加到MCP配置文件中 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或适合您操作系统的位置:

{
  "mcpServers": {
    "repo-explorer": {
      "command": "node",
      "args": ["/path/to/repo-explorer/build/index.js"],
      "env": {},
      "disabled": false
    }
  }
}

适用于Claude开发工具(VSCode扩展)

将repo资源管理器添加到MCP设置文件中 ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json (macOS)或适合您操作系统的位置:

{
  "mcpServers": {
    "repo-explorer": {
      "command": "node",
      "args": ["/path/to/repo-explorer/build/index.js"],
      "env": {},
      "disabled": false
    }
  }
}

使用示例

以下是使用repoexplorer工具的一些示例:

获取所有存储库的状态

<use_mcp_tool>
<server_name>repo-explorer</server_name>
<tool_name>repo_status</tool_name>
<arguments>{}</arguments>
</use_mcp_tool>

创建存储库结构

<use_mcp_tool>
<server_name>repo-explorer</server_name>
<tool_name>create_reference_repos</tool_name>
<arguments>
{
  "cloneAll": false
}
</arguments>
</use_mcp_tool>

克隆特定存储库

<use_mcp_tool>
<server_name>repo-explorer</server_name>
<tool_name>clone_repo</tool_name>
<arguments>
{
  "category": "databases",
  "repo": "watermelondb"
}
</arguments>
</use_mcp_tool>

搜索代码模式

<use_mcp_tool>
<server_name>repo-explorer</server_name>
<tool_name>search_code</tool_name>
<arguments>
{
  "pattern": "function\\s+\\w+\\s*\\(",
  "filePattern": "*.js",
  "category": "databases",
  "repo": "watermelondb",
  "maxResults": 30,
  "contextLines": 2
}
</arguments>
</use_mcp_tool>

贡献

欢迎对repo explorer做出贡献!请按照以下步骤操作:

  1. 分叉存储库
  2. 创建要素分支
  3. 提交您的更改
  4. 推到您的分支
  5. 创建pull请求

许可证

麻省理工学院-参见 许可证 文件以获取详细信息。