コンテンツにスキップ

GitHub MCP Server 設定例

基本設定(環境変数ファイル使用 - 推奨)

1. .env ファイルを作成

D:\Kazuma_Teramachi\MyLab\Credentials\.env

# GitHub Personal Access Token
GITHUB_PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2. MCP設定ファイル

%APPDATA%\Code\User\mcp.json または ~\.gemini\antigravity\mcp_config.json

{
  "mcpServers": {
    "github": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "envFile": "D:\\Kazuma_Teramachi\\MyLab\\Credentials\\.env"
    }
  }
}

特定リポジトリに限定する設定

{
  "mcpServers": {
    "github-mylab": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github",
        "--owner", "YourGitHubUsername",
        "--repo", "MyLab"
      ],
      "envFile": "D:\\Kazuma_Teramachi\\MyLab\\Credentials\\.env"
    }
  }
}

複数リポジトリの設定

{
  "mcpServers": {
    "github-all": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "envFile": "D:\\Kazuma_Teramachi\\MyLab\\Credentials\\.env"
    },
    "github-mylab": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github",
        "--owner", "YourUsername",
        "--repo", "MyLab"
      ],
      "envFile": "D:\\Kazuma_Teramachi\\MyLab\\Credentials\\.env"
    },
    "github-work": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github",
        "--owner", "CompanyName",
        "--repo", "WorkProject"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_different_token_for_work"
      }
    }
  }
}

システム環境変数を使用する設定

1. 環境変数を設定(Windowsコマンドプロンプト)

setx GITHUB_PERSONAL_ACCESS_TOKEN "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

2. MCP設定ファイル

{
  "mcpServers": {
    "github": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"]
    }
  }
}

完全な実用例(複数MCPサーバー統合)

{
  "mcpServers": {
    "filesystem": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "D:\\Kazuma_Teramachi\\MyLab"
      ]
    },
    "github": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "envFile": "D:\\Kazuma_Teramachi\\MyLab\\Credentials\\.env"
    },
    "github-mylab": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github",
        "--owner", "Kazuma_Teramachi",
        "--repo", "MyLab"
      ],
      "envFile": "D:\\Kazuma_Teramachi\\MyLab\\Credentials\\.env"
    }
  }
}

Personal Access Token の必要な権限(Scopes)

GitHub で Personal Access Token を作成する際、以下の権限を選択してください:

最小限の権限(読み取り専用)

  • public_repo - パブリックリポジトリへのアクセス

推奨権限(フル機能)

  • repo - プライベートリポジトリを含む完全なアクセス
  • repo:status
  • repo_deployment
  • public_repo
  • repo:invite
  • security_events
  • workflow - GitHub Actions ワークフローの更新
  • write:discussion - ディスカッションの読み書き
  • read:org - 組織とチームメンバーシップの読み取り

使用例

設定完了後、以下のような操作が可能になります:

# リポジトリ情報の取得
"MyLabリポジトリの最新コミットを教えて"

# ファイル操作
"GitHubのREADME.mdを読んで内容を要約して"
"このファイルをGitHubにコミットして"

# Issue管理
"Issue #42 の内容を確認して"
"新しいIssueを作成: タイトル'MCP統合のテスト'"

# プルリクエスト
"最新のプルリクエスト一覧を表示"
"feature/mcp-integrationブランチからPRを作成"

# 検索
"このリポジトリで'MCP'を含むファイルを検索"

セキュリティチェックリスト

  • .env ファイルを .gitignore に追加済み
  • Personal Access Token をパスワードマネージャーにバックアップ
  • トークンに必要最小限の権限のみ付与
  • トークンの有効期限を設定(推奨: 90日)
  • 設定ファイルにトークンを直接記述していない

詳細な設定手順は MCP_GITHUB_SETUP.md を参照してください。