GitHub代码库分析MCP服务器使用说明

项目简介

GitHub代码库分析MCP服务器(github-chat-mcp)是一个基于Model Context Protocol (MCP) 构建的后端服务,旨在帮助大型语言模型(LLM)理解和分析GitHub代码仓库。它通过集成 GitHub Chat API,提供了对GitHub仓库的索引和查询能力,使得LLM可以基于代码库的内容进行更深入的对话和分析。

主要功能点

  • GitHub仓库索引:允许用户指定GitHub仓库URL,服务器将索引该仓库的代码内容,为后续的查询分析做准备。
  • 代码库问答:用户可以针对已索引的GitHub仓库提出问题,服务器将利用LLM和索引数据,返回关于代码库的解答和相关代码片段出处。

安装步骤

  1. 安装 'github-chat-mcp' 包

    可以使用 'pip' 或 'uv' 包管理器进行安装。推荐使用 'uv',安装速度更快。

    • 使用 'pip' 安装:

      pip install github-chat-mcp
    • 使用 'uv' 安装:

      uv install github-chat-mcp

    如果还没有安装 'uv',请先根据 https://astral.sh/uv/install.sh 的指引安装 'uv'。

  2. 获取 GitHub Chat API 密钥

    访问 https://github-chat.com 获取 GitHub Chat API 密钥。这是使用该 MCP 服务器的必要条件。

服务器配置

要将 'github-chat-mcp' 配置为 MCP 服务器供客户端(例如 Claude)使用,您需要编辑客户端的配置文件(例如 Claude Desktop 的 'claude_desktop_config.json')。在配置文件中添加 'mcpServers' 字段,并配置 'github-chat' 服务器。

以下是配置示例,您需要将 'YOUR_API_KEY_HERE' 替换为您实际的 GitHub Chat API 密钥。

{
  "mcpServers": {
    "github-chat": {
      "command": "github-chat-mcp",  // MCP 服务器的启动命令,通常是安装的包名或可执行文件
      "env": {
        "GITHUB_API_KEY": "YOUR_API_KEY_HERE" // 环境变量,用于传递 GitHub Chat API 密钥
      }
    }
  }
}

配置说明

  • '"github-chat"': 服务器名称,可以自定义,用于在客户端中引用。
  • '"command": "github-chat-mcp"': 指定启动 MCP 服务器的命令。安装 'github-chat-mcp' 包后,'github-chat-mcp' 命令应该已经添加到您的系统路径中。
  • '"env": { "GITHUB_API_KEY": "YOUR_API_KEY_HERE" }': 设置环境变量。'GITHUB_API_KEY' 是 'github-chat-mcp' 服务器需要的 GitHub Chat API 密钥,请替换为您的真实密钥。

基本使用方法

配置完成后,您可以在支持 MCP 的客户端中使用 'github-chat-mcp' 服务器。

  1. 索引 GitHub 仓库

    首先,需要使用索引工具索引您想要分析的 GitHub 仓库。在客户端中,可以使用如下指令:

    '"Use github-chat-mcp to index the GitHub repository at https://github.com/用户名/仓库名"'

    例如: '"Use github-chat-mcp to index the GitHub repository at https://github.com/facebook/react"'

  2. 查询 GitHub 仓库

    仓库索引完成后,就可以向它提问关于代码库的问题了。例如:

    '"Use github-chat-mcp to ask about the architecture of the React repository"'

    或者更具体的问题:

    '"Use github-chat-mcp to query the React repository and ask: What is the core component of React's rendering process?"'

    服务器会返回基于代码库内容的答案和相关代码出处。

注意事项

  • 确保您已正确安装 'github-chat-mcp' 包并配置了 GitHub Chat API 密钥。
  • 首次使用前需要先索引目标 GitHub 仓库。
  • 可以通过设置环境变量 'FASTMCP_LOG_LEVEL' 调整日志级别,例如 'FASTMCP_LOG_LEVEL="ERROR"'。

信息

分类

开发者工具