
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.
Before starting, ensure you have the following:
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
To authenticate with GitHub's API, you'll need a personal access token:
repo - Full repository accessread:user - Read user profile informationuser:email - Access user email addressesCreate environment variables to securely store your GitHub credentials:
set GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here
export GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here
For persistent storage, add the export command to your shell configuration file (.bashrc, .zshrc, etc.).
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"
}
}
}
}
Start the GitHub MCP server using the following command:
npx @modelcontextprotocol/server-github
If you installed it globally:
github-mcp-server
VS Code now natively supports GitHub MCP server integration through Copilot's Agent Mode. Here's how to set it up:
The easiest way to set up the GitHub MCP server in VS Code is through the built-in installation process:
For more control over the setup, you can manually configure the server:
{
"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}"
}
}
}
}
}
To share the configuration with your team, create a workspace-specific setup:
{
"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}"
}
}
}
}
To use the GitHub MCP server, you need to enable Copilot's Agent Mode:
"chat.agent.enabled": trueYou can control which GitHub API capabilities are available by configuring toolsets. This helps reduce context size and improves tool selection:
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}"
}
}
}
}
Once configured, you can interact with GitHub directly through Copilot Chat in Agent Mode:
In Agent Mode, you can control which tools are active:
If you prefer not to use Docker, you can build and run the GitHub MCP server directly:
cmd/github-mcp-server directorygo build -o github-mcp-server{
"mcp": {
"servers": {
"github": {
"command": "/path/to/github-mcp-server",
"args": ["stdio"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
}
}
}
}
}
Customize your GitHub MCP server with additional settings:
Configure which repositories the server can access:
{
"github": {
"allowedRepositories": [
"username/repo1",
"organization/repo2"
],
"excludedRepositories": [
"username/private-repo"
]
}
}
Set up rate limiting to comply with GitHub API limits:
{
"github": {
"rateLimiting": {
"requestsPerHour": 5000,
"burstLimit": 100
}
}
}
Verify your configuration works correctly:
Follow these security guidelines:
Keep your GitHub MCP server running smoothly:
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.