转到github mcp
Go中的模型上下文协议(MCP)服务器实现,为Claude提供GitHub集成。\ 本项目展示了如何使用 包裹。
______________________________________________________________________
特性
- 列出拉取请求:通过按状态(打开、关闭、全部)过滤来获取您编写的拉取请求
- 获取未解决的评论:使用智能预览检索未解决的审核评论
- 获取完整评论:访问内容完整且无截断的完整评论线程
- GitHub身份验证:基于令牌的安全身份验证
- GraphQL集成:使用GitHub的GraphQL API高效获取数据
______________________________________________________________________
安装
先决条件
- 转到1.19或更高版本
- 具有适当权限的GitHub个人访问令牌
- Claude CLI或兼容的MCP客户端
建筑
- 克隆存储库:
git clone
cd gogithub- 安装依赖项:
go mod tidy- 构建MCP服务器:
go build -o github-mcp-server______________________________________________________________________
配置
1.GitHub令牌设置
创建具有以下权限的GitHub个人访问令牌:
repo--完全控制私有存储库read:user--读取个人资料访问权限
将令牌设置为环境变量:
export GITHUB_TOKEN=your_github_token_here______________________________________________________________________
2.克劳德MCP配置
将MCP服务器添加到Claude配置文件中:
~/.克劳德。
{
"mcpServers": {
"my-github-tools": {
"command": "/path/to/your/gogithub/github-mcp-server",
"env": {
"GITHUB_TOKEN": "your_github_token_here"
}
}
}
}替换 /path/to/your/gogithub/github-mcp-server 使用构建二进制文件的绝对路径。______________________________________________________________________
3.重启克劳德
重新启动Claude CLI以加载新的MCP服务器配置。
______________________________________________________________________
用法
配置后,您可以在Claude中使用以下工具。
列出拉取请求
list my open pull requests参数:
state(可选):"open","closed",或"all"(默认值:"open")
______________________________________________________________________
获取未解决的评论
get unresolved comments from https://github.com/owner/repo/pull/123参数:
pull_request_url(必填):完整的GitHub PR URL
______________________________________________________________________
获取完整评论
get full comments from https://github.com/owner/repo/pull/123参数:
pull_request_url(必填):完整的GitHub PR URLunresolved_only(可选):"true"或"false"(默认值:"false")
______________________________________________________________________
工作流示例
- 查找您的PR:
list my open prs- 检查未解决的注释:
get unresolved comments from the first open PR- 获取完整的评论详细信息:
get full comments from this PR- 向克劳德寻求帮助:
help me fix those comments step by step______________________________________________________________________
建筑
项目结构
gogithub/
├── main.go # MCP server setup and tool registration
├── github_service.go # GitHub API integration and handlers
├── go.mod # Go module dependencies
├── go.sum # Dependency checksums
└── README.md # This file关键组件
- MCP服务器 --使用
github.com/mark3labs/mcp-go/mcp - GitHub REST API --通过搜索发现拉取请求
- GitHub GraphQL API --高效的评论线程检索
- OAuth2身份验证 --安全的GitHub令牌处理
______________________________________________________________________
代码示例
工具注册
listPRsTool := mcp.NewTool(
"list_pull_requests",
mcp.WithDescription("Lists pull requests authored by the authenticated user."),
mcp.WithString(
"state",
mcp.Description("The state of the pull requests to list (open, closed, or all). Defaults to 'open'."),
mcp.Enum("open", "closed", "all"),
),
)
s.AddTool(listPRsTool, ghService.listPullRequestsHandler)处理程序实现
func (s *githubService) listPullRequestsHandler(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
state := req.GetString("state", "open")
// GitHub API integration
query := strings.Join(queryParts, " ")
result, resp, err := s.restClient.Search.Issues(ctx, query, opts)
// Return formatted results
return mcp.NewToolResultText(responseBuilder.String()), nil
}______________________________________________________________________
