GitHub MCP(Model Context Protocol)服务器提供了与 GitHub 平台交互的功能,可用于代码搜索、问题跟踪、仓库管理等操作,能有效辅助开发、管理项目、实现自动化工作流以及促进团队协作。
运行以下命令安装必要的依赖:
npm install @github/mcp-server --save
创建并运行以下配置文件 mcp-config.json
:
{
"servers": {
"github": {
"url": "https://api.github.com",
"token": "your-personal-access-token"
}
}
}
GitHub MCP 服务器支持以下操作:
创建 GitHub 个人访问令牌:
repo
权限的令牌(推荐使用 public_repo
权限处理公开仓库)将以下配置添加到 claude_desktop_config.json
:
{
"mcpServers": {
"github": {
"type": "docker",
"containerName": "github-mcp-server",
"imageName": "ghcr.io/your-org/github-mcp:latest"
}
}
}
{
"mcpServers": {
"github": {
"type": "direct",
"endpoint": "http://localhost:3000",
"token": "your-personal-access-token"
}
}
}
使用 npm 包管理器安装:
npm install -g @github/mcp-cli
mcp login --token your-personal-access-token
mcp search "node.js" --language=typescript
mcp create-repo my-new-repo
通过以下语法可以实现精确的代码搜索:
language:javascript
:按编程语言筛选repo:owner/name
:指定仓库范围path:app/src
:按文件路径筛选extension:js
:按文件扩展名筛选q: "import express" language:typescript path:src/
通过以下语法可以实现问题和拉取请求的搜索:
is:issue
或 is:pr
:按类型筛选is:open
或 is:closed
:按状态筛选label:bug
:按标签筛选author:username
:按作者筛选q: "memory leak" is:issue is:open label:bug
通过以下语法可以实现用户或组织的搜索:
type:user
或 type:org
:按账户类型筛选followers:>1000
:按关注者数量筛选location:London
:按地理位置筛选q: "fullstack developer" location:London followers:>100
请参考GitHub 官方文档。
repo
权限)本项目遵循 MIT 协议,具体内容如下:
MIT License
Copyright (c) [年份] [作者姓名]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
通过以上指南,您可以轻松地将 GitHub MCP 服务器集成到您的开发流程中,并提升团队协作效率。