GitHub集成服务器

一个基于FastMCP的GitHub集成服务器,提供用户管理、仓库管理、文件管理、Pull Request和问题管理等功能,支持AI代理如Claude和Cursor通过GitHub API进行操作。

  • by HyunjunGil
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 hyunjungil/mcp-github-server

使用说明

GitHub MCP服务器

使用FastMCP的完整GitHub集成MCP服务器。帮助Claude、Cursor等AI代理轻松使用GitHub API。

🌟 主要功能

  • 用户管理:查看GitHub用户信息,查看存储库列表
  • 存储库管理:创建存储库、查询信息、查看文件列表、创建分支
  • 文件管理:查看、创建、修改、删除文件内容
  • 拉取请求:PR创建和列表查询
  • 问题管理:创建、查询、修改、结束问题
  • 双通信支持:stdio模式(Claude/Cursor)+HTTP模式(Web API)

🚀 快速入门

1.安装依赖性

pip install -r requirements.txt

2.GitHub个人访问令牌생성

  1. GitHub→ 设置→ 开发人员设置→ 个人访问令牌→ 代币(经典)
  2. “生成新令牌(经典)”클릭
  3. 选择所需权限:
    • repo (访问整个存储库)
    • read:user (读取用户信息)
  4. 创建和复制令牌

3.设置环境变量

# .env 파일 생성 (env.example을 참고)
cp env.example .env

# .env 파일 편집
GITHUB_TOKEN=your_github_token_here
LOG_LEVEL=INFO
HTTP_HOST=0.0.0.0
HTTP_PORT=8080

4.运行服务器

stdio模式(用于Claude/Cursor)

python run_stdio.py

HTTP模式(用于Web API)

python run_http.py

📋 可用工具

与用户相关

  • get_user_info:查看当前用户信息
  • get_user_repos:查看用户存储库列表

与存储库相关

  • create_repository:创建新存储库
  • get_repository_info:查看存储库信息
  • list_repository_contents:查看存储库文件列表
  • create_branch:创建新分支

文件相关

  • get_file_content:查看文件内容
  • create_file:创建新文件
  • update_file:修改现有文件
  • delete_file:删除文件

拉取请求관련

  • create_pull_request:创建新PR
  • list_pull_requests:浏览PR列表

话题相关

  • create_issue:创建新问题
  • list_issues:查看问题列表
  • update_issue:修改问题
  • close_issue:关闭问题

🔧 Cursor/Claude设置

Cursor MCP设置

~/.cursor/mcp.json 在文件中添加以下设置:

{
  "mcpServers": {
    "github-mcp-server": {
      "command": "python",
      "args": ["run_stdio.py"],
      "cwd": "/path/to/mcp-github-server"
    }
  }
}

重要:将GitHub令牌设置为环境变量:

# ~/.zshrc 또는 ~/.bashrc에 추가
export GITHUB_TOKEN="your_github_token_here"

# 또는 Cursor 실행 전에 환경변수 설정
export GITHUB_TOKEN="your_github_token_here"
/Applications/Cursor.app/Contents/MacOS/Cursor

📁 项目结构

mcp-github-server/
├── src/
│   └── github_mcp_server/
│       ├── __init__.py
│       ├── server.py            # FastMCP 서버 메인
│       ├── github_client.py     # GitHub API 클라이언트
│       ├── config.py            # 설정 관리
│       └── tools/               # MCP 도구들
│           ├── __init__.py
│           ├── user_tools.py    # 사용자 정보 조회
│           ├── repo_tools.py    # 리포지토리 관리
│           ├── file_tools.py    # 파일 수정
│           ├── pr_tools.py      # Pull Request 관리
│           └── issue_tools.py   # 이슈 관리
├── run_stdio.py                 # stdio 모드 실행
├── run_http.py                  # HTTP 모드 실행
├── requirements.txt
├── env.example                  # 환경변수 템플릿
├── .gitignore
└── README.md

🔐 安全注意事项

  • 安全管理GitHub Personal Access Token
  • .env 将文件从版本控制中排除(已包括在.gitignore中)
  • 请只授予所需的最低权限。
  • 建议为令牌设置过期日期

🛠️ 开发

以开发模式运行

# stdio 모드
python src/github_mcp_server/server.py

# HTTP 모드
python src/github_mcp_server/server.py --http

MCP协议手动初始化测试

服务器运行后直接初始化JSON-RPC 2.0调用:

# 1단계: 서버 실행
export GITHUB_TOKEN="your_github_token_here"
python run_stdio.py

服务器运行后,按顺序输入以下JSON-RPC调用:

// 1. 초기화 요청 (initialize)
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}

// 2. 초기화 완료 알림 (notifications/initialized)
{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}}

// 3. 도구 목록 조회 (tools/list)
{"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}

// 4. 사용자 정보 조회 테스트
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "get_user_info", "arguments": {}}}

// 5. 리포지토리 목록 조회 테스트
{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_user_repos", "arguments": {"per_page": 5}}}

重要:每个JSON请求后,服务器必须双击Enter才能识别。

📄 许可证

MIT许可证

🤝 贡献

欢迎Pull Request和问题提交!

📞 支持

如果有问题或问题,请创建GitHub问题。