CC逆引きリファレンス

GitHub MCP を使いたい

7. MCP(Model Context Protocol)

コマンド / 機能

claude mcp add github -- npx @anthropic/mcp-github

公式サーバー

概要

Anthropic 公式の GitHub MCP サーバーです。リポジトリ、Issue、Pull Request、ファイル内容の取得・作成・更新など、GitHub API の主要機能を提供します。

設定例

# GitHub Personal Access Token を使用して追加
claude mcp add -s user \
  -e GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx \
  github -- npx -y @anthropic/mcp-github

# トークン取得方法
# 1. GitHub → Settings → Developer settings
# 2. Personal access tokens → Fine-grained tokens
# 3. Generate new token で必要なスコープを選択
#    - repo: リポジトリ操作
#    - issues: Issue 操作
#    - pull_requests: PR 操作

# 利用可能なツール例
# - github_get_repository: リポジトリ情報取得
# - github_list_issues: Issue 一覧
# - github_create_issue: Issue 作成
# - github_list_pull_requests: PR 一覧
# - github_get_file_contents: ファイル内容取得
# - github_search_code: コード検索

こんな時に使う

  • GitHub の PR やイシューを操作したい時
  • リポジトリ情報を取得したい時

使い方

  1. 1GitHub で Personal Access Token を生成
  2. 2必要なスコープ(repo, issues など)を付与
  3. 3claude mcp add で GITHUB_TOKEN を環境変数として設定
  4. 4/tools で利用可能なツールを確認

Tips

  • Fine-grained token を使うと必要最小限の権限に制限できます
  • トークンの有効期限を設定しておくと安全です
  • ユーザースコープ(-s user)で追加すると全プロジェクトで使用可能
  • Claude Code 組み込みの gh コマンドも併用できます