返回市场
github仓库mcp

github仓库mcp

作者:Ryan020420 星标更新:2025-04-26

项目介绍

GitHub Repo MCP

smithery 徽章

<p class="center-text"> <strong>GitHub Repo MCP 是一个开源的 MCP 服务器,允许您的 AI 助手浏览 GitHub 存储库、探索目录并查看文件内容。</strong> </p> <a href="https://glama.ai/mcp/servers/@Ryan0204/github-repo-mcp"> <img width="380" height="200" src="https://gips2.baidu.com/it/u=1041333677,3058597385&fm=3081&app=3281&f=PNG?w=760&h=400" alt="github-repo-mcp MCP 服务器" /> </a>

目录

<p class="center-text"> <a href="#开始使用">开始使用</a> • <a href="#功能概述">功能概述</a> </p>

✨ 主要功能

  • 💻 兼容 Cursor、Windsurf、Claude Desktop 和其他支持 stdio 协议的 MCP 客户端
  • 🔎 浏览任何公共 GitHub 存储库的内容
  • 📂 导航存储库目录及其子目录
  • 📝 查看代码和文本文件的内容
  • 📦 通过包管理器轻松安装

开始使用

预备条件

安装服务器需要在系统上满足以下条件:

  • Node.js 18+
  • npm 或 yarn

第一步:安装

您可以使用 Smithery、NPX 或在 IDE 的 mcp.json 中设置来安装和运行 GitHub Repo MCP:

MacOS

npx github-repo-mcp

Windows NPX

cmd /c npx -y github-repo-mcp

Windows NPX 通过 .cursor/mcp.json

{
  "mcpServers": {
    "github-repo-mcp": {
      "command": "wsl",
      "args": [
        "bash",
        "-c",
        "cmd /c npx -y github-repo-mcp"
      ],
      "enabled": true
    }
  }
}

Windows NPX 通过 .cursor/mcp.json(如果路径未设置)

# 首先找到 npx 的完整路径
which npx
{
  "mcpServers": {
    "github-repo-mcp": {
      "command": "wsl",
      "args": [
        "bash",
        "-c",
        "'/home/[用户名]/.nvm/versions/node/v20.18.0/bin/npx github-repo-mcp'"
      ],
      "enabled": true
    }
  }
}

通过 Smithery 安装

要通过 Smithery 自动为 Claude Desktop 安装 GitHub Repo MCP:

npx -y @smithery/cli install @Ryan0204/github-repo-mcp --client claude

等待几秒钟或点击刷新按钮几次,如果它没有注册。如果仍然无法注册,请确保您输入了正确的命令。

第二步:配置

GitHub Repo MCP 服务器可以使用 GitHub 令牌以更高的速率限制访问 GitHub API。

环境变量

变量必需默认值描述
GITHUB_TOKEN您的 GitHub 个人访问令牌,用于提高速率限制

设置 GitHub 令牌(可选)

虽然服务器可以在没有身份验证的情况下工作,但 GitHub API 对未认证请求的速率限制较低。为了增加您的速率限制:

  1. https://github.com/settings/tokens 创建个人访问令牌
  2. 将令牌作为环境变量设置在 mcp.json 中:
{
  "mcpServers": {
    "github-repo-mcp": {
      "command": "...",
      "args": [
        ...
      ],
      "env": {
        "GITHUB_TOKEN": "您的_Github_令牌"
      },
      "enabled": true,
    }
  }
}

功能概述

存储库浏览工具

该服务器提供了三种主要工具与 GitHub 存储库进行交互:

1. getRepoAllDirectories

列出 GitHub 存储库根目录下的所有文件和目录。

2. getRepoDirectories

列出 GitHub 存储库中特定目录的内容。

  • 参数
    • repoUrl:GitHub 存储库的 URL
    • path:要获取的目录路径(例如:"src")

3. getRepoFile

检索并显示来自 GitHub 存储库的特定文件内容。

  • 参数
    • repoUrl:GitHub 存储库的 URL
    • path:要获取的文件路径(例如:"src/index.js")

使用示例

这里有一些如何使用这些工具与 AI 助手交互的例子:

  1. 浏览存储库根目录: 让您的 AI 助手“显示 https://github.com/Ryan0204/github-repo-mcp 存储库的内容”

  2. 探索特定目录: 询问“https://github.com/Ryan0204/github-repo-mcp 的 src 目录中有哪些文件?”

  3. 查看文件: 询问“显示 https://github.com/Ryan0204/github-repo-mcp 的 README.md 文件”

限制

  • 速率限制:未经身份验证时,GitHub API 有严格的速率限制(每小时 60 次请求)
  • 私有存储库:只能访问公共存储库,除非提供具有适当权限的令牌
  • 二进制文件:服务器检测常见的二进制文件扩展名,并不会显示其内容
  • 大文件:GitHub API 对可检索文件的大小有限制

故障排除

这里是一些常见问题及其解决方案:

  • 超出速率限制:按照配置部分所述设置 GitHub 令牌
  • 找不到命令:确保全局安装了该包
  • 连接错误:检查您的互联网连接和 GitHub API 状态

如果您遇到任何问题,请检查输出中的错误消息或在 GitHub 存储库中创建一个问题。


祝您使用愉快! ☺️