PyGithub MCP サーバー
PyGithubを介してGitHub APIとやり取りするためのツールを提供するモデルコンテキストプロトコルサーバー。このサーバーにより、AIアシスタントは課題、リポジトリ、プルリクエストの管理といったGitHub操作を実行できるようになります。
特徴
モジュラーツールアーキテクチャ:
有効化/無効化できる設定可能なツールグループ
ドメイン固有の組織(問題、リポジトリなど)
ファイルまたは環境変数による柔軟な設定
モジュール設計による明確な関心の分離
一貫したパターンによる簡単な拡張
完全な GitHub の問題管理:
スマートなパラメータ処理:
堅牢な実装:
Related MCP server: GitHub Enterprise MCP Server
ドキュメント
包括的なガイドは、docs/guides ディレクトリで入手できます。
error-handling.md: エラーの種類、処理パターン、ベストプラクティス
security.md: 認証、アクセス制御、コンテンツセキュリティ
tool-reference.md: 例を含む詳細なツールドキュメント
PyGithub MCP サーバーの使用に関する詳細については、これらのガイドを参照してください。
使用例
発行業務
問題の作成
{
"owner": "username",
"repo": "repository",
"title": "Issue Title",
"body": "Issue description",
"assignees": ["username1", "username2"],
"labels": ["bug", "help wanted"],
"milestone": 1
}
問題の詳細を取得する
{
"owner": "username",
"repo": "repository",
"issue_number": 1
}
問題の更新
{
"owner": "username",
"repo": "repository",
"issue_number": 1,
"title": "Updated Title",
"body": "Updated description",
"state": "closed",
"labels": ["bug", "wontfix"]
}
コメント操作
コメントを追加する
{
"owner": "username",
"repo": "repository",
"issue_number": 1,
"body": "This is a comment"
}
リストコメント
{
"owner": "username",
"repo": "repository",
"issue_number": 1,
"per_page": 10
}
コメントの更新
{
"owner": "username",
"repo": "repository",
"issue_number": 1,
"comment_id": 123456789,
"body": "Updated comment text"
}
ラベル操作
ラベルの追加
{
"owner": "username",
"repo": "repository",
"issue_number": 1,
"labels": ["enhancement", "help wanted"]
}
ラベルの削除
{
"owner": "username",
"repo": "repository",
"issue_number": 1,
"label": "enhancement"
}
すべての操作はオプションのパラメータをインテリジェントに処理します。
API呼び出しには提供されたパラメータのみが含まれます
プリミティブ型を GitHub オブジェクトに変換します (例: マイルストーン番号をマイルストーン オブジェクトに変換)
無効なパラメータに対して明確なエラーメッセージを表示します
該当する場合はページ区切りを自動的に処理します
インストール
仮想環境を作成してアクティブ化します。
uv venv
source .venv/bin/activate
依存関係をインストールします:
構成
基本構成
サーバーを MCP 設定 (例: claude_desktop_config.jsonまたはcline_mcp_settings.json ) に追加します。
{
"mcpServers": {
"github": {
"command": "/path/to/repo/.venv/bin/python",
"args": ["-m", "pygithub_mcp_server"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your-token-here"
}
}
}
}
ツールグループの構成
サーバーは、設定を通じてツールグループを個別に有効化または無効化できます。これは以下の2つの方法で設定できます。
1. 設定ファイル
JSON 構成ファイル (例: pygithub_mcp_config.json ) を作成します。
{
"tool_groups": {
"issues": {"enabled": true},
"repositories": {"enabled": true},
"pull_requests": {"enabled": false},
"discussions": {"enabled": false},
"search": {"enabled": true}
}
}
次に、環境でこのファイルを指定します。
export PYGITHUB_MCP_CONFIG=/path/to/pygithub_mcp_config.json
2. 環境変数
または、環境変数を使用してツール グループを構成します。
export PYGITHUB_ENABLE_ISSUES=true
export PYGITHUB_ENABLE_REPOSITORIES=true
export PYGITHUB_ENABLE_PULL_REQUESTS=false
デフォルトでは、 issuesツールグループのみが有効になっています。詳細な設定オプションについては、 README.config.mdご覧ください。
発達
テスト
このプロジェクトには包括的なテスト スイートが含まれています。
# Run all tests
pytest
# Run tests with coverage report
pytest --cov
# Run specific test file
pytest tests/test_operations/test_issues.py
# Run tests matching a pattern
pytest -k "test_create_issue"
注: 現在、多くのテストが失敗しており、調査中です。これは既知の問題であり、現在積極的に取り組んでいます。
MCP Inspectorによるテスト
MCP インスペクターを使用して開発中に MCP ツールをテストします。
source .venv/bin/activate # Ensure venv is activated
npx @modelcontextprotocol/inspector -e GITHUB_PERSONAL_ACCESS_TOKEN=your-token-here uv run pygithub-mcp-server
MCP Inspector の Web UI を使用して次の操作を行います。
利用可能なツールを試してみる
実際のGitHubリポジトリでテストする
成功とエラーのケースを検証する
作業ペイロードを文書化する
プロジェクト構造
tests/
├── unit/ # Fast tests without external dependencies
│ ├── config/ # Configuration tests
│ ├── tools/ # Tool registration tests
│ └── ... # Other unit tests
└── integration/ # Tests with real GitHub API
├── issues/ # Issue tools tests
└── ... # Other integration tests
src/
└── pygithub_mcp_server/
├── __init__.py
├── __main__.py
├── server.py # Server factory (create_server)
├── version.py
├── config/ # Configuration system
│ ├── __init__.py
│ └── settings.py # Configuration management
├── tools/ # Modular tool system
│ ├── __init__.py # Tool registration framework
│ └── issues/ # Issue tools
│ ├── __init__.py
│ └── tools.py # Issue tool implementations
├── client/ # GitHub client functionality
│ ├── __init__.py
│ ├── client.py # Core GitHub client
│ └── rate_limit.py # Rate limit handling
├── converters/ # Data transformation
│ ├── __init__.py
│ ├── parameters.py # Parameter formatting
│ ├── responses.py # Response formatting
│ ├── common/ # Common converters
│ ├── issues/ # Issue-related converters
│ ├── repositories/ # Repository converters
│ └── users/ # User-related converters
├── errors/ # Error handling
│ ├── __init__.py
│ └── exceptions.py # Custom exceptions
├── operations/ # GitHub operations
│ ├── __init__.py
│ └── issues.py
├── schemas/ # Data models
│ ├── __init__.py
│ ├── base.py
│ ├── issues.py
│ └── ...
└── utils/ # General utilities
├── __init__.py
└── environment.py # Environment utilities
トラブルシューティング
サーバーの起動に失敗しました:
ビルド エラー:
uv ビルドで --no-build-isolation フラグを使用する
Python 3.10以降が使用されていることを確認する
すべての依存関係がインストールされていることを確認する
GitHub API エラー:
依存関係
Python 3.10以上
MCP Python SDK
ピダンティック
パイGitHub
UV パッケージ マネージャー
ライセンス
マサチューセッツ工科大学