GitHub 存储库 MCP 服务器
此模型上下文协议 (MCP) 服务器允许 AI 模型访问 GitHub 仓库内容作为上下文。它提供工具来获取文件内容、仓库结构以及整个仓库,以用作 AI 交互的上下文。
特征
- 获取整个存储库内容作为上下文
- 从存储库获取特定文件内容
- 获取存储库结构(文件列表)
- 按扩展名过滤文件
- 排除特定路径
- 限制返回的文件数量
安装
用法
设置 GitHub 身份验证
虽然服务器无需身份验证即可处理公共仓库,但 GitHub API 对未经身份验证的请求有严格的速率限制(每小时 60 个请求)。要将此限制提高到每小时 5000 个请求,请设置GITHUB_TOKEN
环境变量:
您可以在GitHub 开发者设置中创建个人访问令牌。
与游标一起使用
要将此服务器与 Cursor 一起使用,请按照以下步骤操作:
- 打开游标设置
- 搜索“MCP”
- 点击“添加新的 MCP 服务器”
- 输入以下信息:
- 名称:github-repo-context(或您想要的任何名称)
- 类型:命令
- 命令:/path/to/your-local-repo-setup/gh.sh
- 点击“保存”
- 单击服务器名称旁边的开关来启用服务器
- 您现在应该能够在项目中使用该服务器
服务器按照 MCP 协议通过 stdin/stdout 进行通信。
可用工具
该服务器提供以下工具:
- get-repo-context :从 GitHub 存储库获取所有文件作为上下文
- 参数:
owner
:GitHub 仓库所有者/组织名称repo
:GitHub 存储库名称maxFiles
(可选):要包含的最大文件数(默认值:50)fileExtensions
(可选):要包含的文件扩展名(例如,['js','ts','md'])excludePaths
(可选):要排除的路径(默认值:['node_modules','dist','build'])
- 参数:
- get-file-content :从 GitHub 存储库获取特定文件的内容
- 参数:
owner
:GitHub 仓库所有者/组织名称repo
:GitHub 存储库名称path
:存储库中的文件路径
- 参数:
- get-repo-structure :获取 GitHub 存储库的结构
- 参数:
owner
:GitHub 仓库所有者/组织名称repo
:GitHub 存储库名称
- 参数:
例子
当与支持 MCP 的 AI 模型集成时,您可以使用以下命令:
然后,AI 将使用get-repo-structure
工具来获取并显示存储库结构。
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
使 AI 模型能够访问 GitHub 存储库内容作为上下文,并具有获取整个存储库、特定文件内容和存储库结构以用于 AI 交互的功能。
Related MCP Servers
- -securityAlicense-qualityA server that allows AI assistants to browse and read files from specified GitHub repositories, providing access to repository contents via the Model Context Protocol.Last updated -5JavaScriptMIT License
- AsecurityFlicenseAqualityA Model Context Protocol server that enables AI models to interact with GitHub's API, allowing for repository creation and management with descriptions, topics, and website URLs through natural language commands.Last updated -1JavaScript
- -securityFlicense-qualityA Model Context Protocol server that enables AI assistants to perform GitHub operations including repository management, file operations, issue tracking, and pull request creation.Last updated -1TypeScript
- -securityAlicense-qualityEnables interaction with GitHub repositories through the GitHub API, allowing file operations, repository management, issue tracking, and code search through natural language commands.Last updated -282TypeScriptMIT License