← back

How to Configure and Use GitHub MCP Server: A Complete Step-by-Step Guide (Vs Code)

How to configure a MCP Server

Introduction

The GitHub Model Context Protocol (MCP) server enables seamless integration between AI assistants and GitHub repositories. This guide will walk you through the complete process of setting up and using the GitHub MCP server to enhance your development workflow.

Prerequisites

Before starting, ensure you have the following:

  • Node.js (version 16 or higher) installed on your system
  • A GitHub account with appropriate repository access
  • Basic familiarity with command line operations
  • Git installed on your local machine

Step 1: Install the GitHub MCP Server

Begin by installing the GitHub MCP server package using npm:

npm install -g @modelcontextprotocol/server-github

Alternatively, you can install it locally in your project:

npm install @modelcontextprotocol/server-github

Step 2: Generate a GitHub Personal Access Token

To authenticate with GitHub's API, you'll need a personal access token:

  1. Navigate to GitHub.com and log into your account
  2. Click on your profile picture in the top-right corner
  3. Select "Settings" from the dropdown menu
  4. Scroll down and click "Developer settings" in the left sidebar
  5. Click "Personal access tokens" then "Tokens (classic)"
  6. Click "Generate new token" and select "Generate new token (classic)"
  7. Provide a descriptive note for the token (e.g., "MCP Server Access")
  8. Select appropriate scopes based on your needs:
    • repo - Full repository access
    • read:user - Read user profile information
    • user:email - Access user email addresses
  9. Click "Generate token"
  10. Copy the generated token immediately (it won't be shown again)

Step 3: Set Up Environment Variables

Create environment variables to securely store your GitHub credentials:

On Windows:

set GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here

On macOS/Linux:

export GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here

For persistent storage, add the export command to your shell configuration file (.bashrc, .zshrc, etc.).

Step 4: Create the MCP Configuration File

Create a configuration file to define your MCP server settings. Create a file named mcp-config.json:

{
  "mcpServers": {
    "github": {
      "command": "node",
      "args": [
        "path/to/github-mcp-server/dist/index.js"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
      }
    }
  }
}

Step 5: Initialize the GitHub MCP Server

Start the GitHub MCP server using the following command:

npx @modelcontextprotocol/server-github

If you installed it globally:

github-mcp-server

Step 6: Configure GitHub MCP Server in VS Code

VS Code now natively supports GitHub MCP server integration through Copilot's Agent Mode. Here's how to set it up:

Prerequisites for VS Code Integration:

  • VS Code version 1.99 or later
  • GitHub Copilot extension installed
  • Active GitHub Copilot subscription (Free, Pro, Business, or Enterprise)
  • Docker installed and running (for the easiest setup method)

Method 1: One-Click Installation (Recommended)

The easiest way to set up the GitHub MCP server in VS Code is through the built-in installation process:

  1. Open VS Code and ensure you're signed in to GitHub
  2. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P)
  3. Type "MCP: Add Server" and select the command
  4. Choose "GitHub" from the available server options
  5. VS Code will automatically handle the Docker setup and configuration
  6. When prompted, enter your GitHub Personal Access Token

Method 2: Manual Configuration

For more control over the setup, you can manually configure the server:

  1. Open VS Code Settings by pressing Ctrl+Shift+P (Cmd+Shift+P on Mac)
  2. Type "Preferences: Open User Settings (JSON)" and select it
  3. Add the following configuration to your settings.json file:
{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "github_token",
        "description": "GitHub Personal Access Token",
        "password": true
      }
    ],
    "servers": {
      "github": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "-e",
          "GITHUB_PERSONAL_ACCESS_TOKEN",
          "ghcr.io/github/github-mcp-server"
        ],
        "env": {
          "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
        }
      }
    }
  }
}

Method 3: Workspace-Specific Configuration

To share the configuration with your team, create a workspace-specific setup:

  1. In your project root, create a `.vscode` folder if it doesn't exist
  2. Create a file named `mcp.json` inside the `.vscode` folder
  3. Add the following configuration (note: no "mcp" wrapper needed):
{
  "inputs": [
    {
      "type": "promptString",
      "id": "github_token",
      "description": "GitHub Personal Access Token",
      "password": true
    }
  ],
  "servers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
      }
    }
  }
}

Step 7: Enable Agent Mode in VS Code

To use the GitHub MCP server, you need to enable Copilot's Agent Mode:

  1. Open VS Code and navigate to Settings (File > Preferences > Settings)
  2. Search for "chat.agent.enabled" in the settings search bar
  3. Enable the "Chat: Agent Enabled" setting
  4. Alternatively, you can add this to your settings.json: "chat.agent.enabled": true
  5. Reload VS Code if prompted
  6. Open the Chat view (Ctrl+Shift+I or via the sidebar)
  7. Sign in to GitHub if you haven't already
  8. In the Chat mode dropdown, select "Agent"

Step 8: Configure Toolsets (Optional)

You can control which GitHub API capabilities are available by configuring toolsets. This helps reduce context size and improves tool selection:

Available Toolsets:

  • repos - Repository operations (files, branches, commits)
  • issues - Issue management (create, read, update, comment)
  • users - User-related operations
  • pull_requests - Pull request operations
  • code_security - Security scanning and alerts
  • experiments - Experimental features (beta)

To configure specific toolsets, modify your Docker configuration:

{
  "servers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "-e",
        "GITHUB_TOOLSETS=repos,issues,pull_requests",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
      }
    }
  }
}

Step 9: Using GitHub MCP Server in VS Code

Once configured, you can interact with GitHub directly through Copilot Chat in Agent Mode:

Basic Usage Examples:

  • "Show me my private repos"
  • "Create a new issue in my repository about fixing the login bug"
  • "List all open pull requests in the main branch"
  • "Get the contents of the README.md file"
  • "Create a new branch called 'feature/user-authentication'"
  • "Search for repositories related to machine learning"

Managing Tools:

In Agent Mode, you can control which tools are active:

  1. Look for the Tools button in the Chat view
  2. Toggle specific GitHub tools on/off as needed
  3. This helps focus the AI's attention on relevant capabilities

Step 10: Alternative Setup Without Docker

If you prefer not to use Docker, you can build and run the GitHub MCP server directly:

Building from Source:

  1. Clone the GitHub MCP server repository
  2. Navigate to the cmd/github-mcp-server directory
  3. Build the binary: go build -o github-mcp-server
  4. Configure VS Code to use the built executable:
{
  "mcp": {
    "servers": {
      "github": {
        "command": "/path/to/github-mcp-server",
        "args": ["stdio"],
        "env": {
          "GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
        }
      }
    }
  }
}

Step 11: Testing Your VS Code Setup

Customize your GitHub MCP server with additional settings:

Repository Filtering:

Configure which repositories the server can access:

{
  "github": {
    "allowedRepositories": [
      "username/repo1",
      "organization/repo2"
    ],
    "excludedRepositories": [
      "username/private-repo"
    ]
  }
}

Rate Limiting:

Set up rate limiting to comply with GitHub API limits:

{
  "github": {
    "rateLimiting": {
      "requestsPerHour": 5000,
      "burstLimit": 100
    }
  }
}

Step 9: Testing Your Setup

Verify your configuration works correctly:

  1. Test basic connectivity by listing your repositories
  2. Try reading a file from one of your repositories
  3. Create a test issue to verify write permissions
  4. Check the server logs for any error messages

Step 10: Security Best Practices

Follow these security guidelines:

  • Store your personal access token securely using environment variables
  • Regularly rotate your GitHub personal access tokens
  • Use principle of least privilege when setting token scopes
  • Monitor API usage to detect unusual activity
  • Keep the MCP server software updated to the latest version

Troubleshooting Common Issues

Authentication Errors:

  • Verify your personal access token is correctly set
  • Check that the token has appropriate scopes
  • Ensure the token hasn't expired

Connection Issues:

  • Confirm your internet connection is stable
  • Check if GitHub is experiencing service issues
  • Verify firewall settings aren't blocking connections

Permission Errors:

  • Ensure you have appropriate access to the target repositories
  • Verify organization settings allow personal access tokens
  • Check if two-factor authentication is properly configured

Monitoring and Maintenance

Keep your GitHub MCP server running smoothly:

  • Set up logging to track server activity and errors
  • Monitor API rate limit usage to avoid throttling
  • Regularly update the MCP server to the latest version
  • Review and rotate access tokens periodically
  • Back up important configuration files

Conclusion

The GitHub MCP server provides a powerful bridge between AI assistants and GitHub repositories, enabling automated workflows and enhanced productivity. By following this step-by-step guide, you should now have a fully functional GitHub MCP server that can interact with your repositories safely and efficiently.

Remember to keep your setup secure, monitor usage regularly, and stay updated with the latest features and security patches. The GitHub MCP server opens up numerous possibilities for automating development tasks and improving collaboration workflows.

Additional Resources

  • GitHub API Documentation: https://docs.github.com/en/rest
  • Model Context Protocol Specification
  • GitHub Personal Access Token Best Practices
  • MCP Server Community Examples and Templates
How to Configure and Use GitHub MCP Server: A Complete Step-by-Step Guide (Vs Code) | Hernán Nadotti