R

Ryan0204

@Ryan0204/github-repo-mcp
0 Stars 310 次浏览 Ryan0204 更新于 2026-08-23

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

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

服务介绍

GitHub Repo MCP

smithery badge

目录

✨ 主要功能

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

开始使用

前提条件

安装服务器需要您的系统具备以下条件:

  • Node.js 18+
  • npm 或 yarn

第一步:安装

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

MacOS

bash
npx github-repo-mcp

Windows NPX

bash
cmd /c npx -y github-repo-mcp

Windows NPX 通过 .cursor/mcp.json

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

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

bash

首先找到 npx 的完整路径

which npx

json
{
"mcpServers": {
"github-repo-mcp": {
"command": "wsl",
"args": [
"bash",
"-c",
" /home/[username]/.nvm/versions/node/v20.18.0/bin/npx github-repo-mcp "
],
"enabled": true
}
}
}

通过 Smithery 安装

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

bash
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 中的环境变量:

json
{
"mcpServers": {
"github-repo-mcp": {
"command": "...",
"args": [
...
],
"env": {
"GITHUB_TOKEN": "Your_Github_Token"
},
"enabled": true,
}
}
}

功能概览

仓库浏览工具

服务器提供了三个主要工具来与 GitHub 仓库进行交互:

1. getRepoAllDirectories

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

  • 参数:
    • repoUrl: GitHub 仓库的 URL(例如:"https://github.com/owner/repo")

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 仓库中创建一个问题。


祝您使用愉快!☺️

相关 MCP 服务