使用说明

项目简介

Repository Analyzer MCP Server 是一个基于 Model Context Protocol (MCP) 构建的应用后端,旨在为大型语言模型(LLM)客户端提供代码仓库分析能力。它特别针对分析代码仓库而设计,并增强了对 Nostr 和 NDK(Nostr Development Kit)项目的分析功能。通过此 MCP 服务器,LLM 客户端可以便捷地获取代码仓库的结构、组件、依赖关系以及版本控制历史等信息,从而更好地理解和处理代码相关任务。

主要功能点

  • 代码结构分析: 分析代码文件的结构,包括代码行数、函数、类等信息。
  • 组件分析: 识别代码中的组件,例如 React 组件、Hooks 使用情况等。
  • 依赖分析: 列出代码文件中的导入和依赖项。
  • 变更分析: 展示代码文件的 Git 历史和最近的变更记录。
  • 代码搜索: 在代码仓库中搜索特定的文本模式。
  • Git 历史: 检索整个仓库或特定文件的 Git 提交历史。
  • 文件和目录访问: 允许读取仓库中的文件内容和列出目录内容。
  • NDK 仓库分析: 提供专门用于分析 Nostr Development Kit (NDK) 仓库的工具,包括 NDK 实现和迁移分析。
  • Nostr 协议分析: 提供分析 Nostr 协议仓库的工具,例如分析事件类型和实现。

安装步骤

  1. 克隆仓库
    git clone https://github.com/DocNR/repo-analyzer-mcp.git
    cd repo-analyzer-mcp
  2. 安装依赖
    npm install
  3. 构建项目
    npm run build

服务器配置

要将此 MCP 服务器连接到 MCP 客户端(例如 Claude Desktop),您需要配置客户端以指向此服务器。以下是配置 Claude Desktop 的示例 JSON 配置,您需要将其添加到 Claude Desktop 的配置文件中。

{
  "mcpServers": {
    "repo-analyzer": {
      "command": "node",
      "args": [
        "/absolute/path/to/repo-analyzer-mcp/dist/index.js"
      ],
      "env": {
        "REPO_PATH": "/path/to/default/repository/to/analyze"
      }
    }
  }
}
  • server name: '"repo-analyzer"' (用户自定义的服务器名称,在 Claude Desktop 中用于标识此服务器)
  • command: '"node"' (运行服务器的命令,这里是 Node.js)
  • args: 启动命令的参数数组:
    • '"/absolute/path/to/repo-analyzer-mcp/dist/index.js"': (请替换为 repo-analyzer-mcp 项目 'dist/index.js' 文件的绝对路径,这是服务器的入口文件)
  • env: 服务器运行所需的环境变量:
    • '"REPO_PATH"': '"/path/to/default/repository/to/analyze"' (可选,请替换为您希望服务器默认分析的代码仓库的绝对路径。如果留空,服务器将默认分析其运行目录。)

注意: 请确保将 '/absolute/path/to/repo-analyzer-mcp' 替换为您实际的 'repo-analyzer-mcp' 仓库的安装路径。

基本使用方法

配置完成后,在 MCP 客户端中,您可以使用自然语言指令来调用服务器提供的工具和资源,以分析代码仓库。

工具示例:

  • 分析代码结构: 'Analyze the code structure of src/index.ts'
  • 搜索代码: 'Search the code for "addEventListener" in .js files'
  • 查看 Git 历史: 'Show me the git history for README.md, limit to 5 commits'
  • 分析 NDK 实现: 'Analyze NDK implementation at /path/to/ndk-repo'
  • 分析 Nostr 协议事件: 'Analyze Nostr Protocol events at /path/to/nips-repo with focus on social context'

资源示例:

  • 读取文件内容: 'Show me the content of the package.json file'
  • 列出目录内容: 'List the directory contents of src'

对于需要指定仓库路径的工具(例如 'analyze-ndk', 'analyze-nostr-protocol', 'analyze-ndk-files'),您可以在指令中直接包含仓库路径,以覆盖默认的 'REPO_PATH' 环境变量设置。例如: 'Analyze NDK implementation at /path/to/another-ndk-repo'.

信息

分类

开发者工具