GitHub MCP server

Manage repositories, issues, and search code via GitHub API.
Back to servers
Provider
Anthropic
Release date
Nov 19, 2024
Language
TypeScript
Package
Stats
249.5K downloads
43.7K stars

The GitHub MCP Server is a powerful interface to the GitHub API, enabling file operations, repository management, search functionality, and more through the Model Context Protocol. It offers comprehensive features for Git operations while maintaining proper history and providing clear error handling.

Installation

Prerequisites

You'll need a GitHub Personal Access Token with the appropriate permissions:

  1. Go to GitHub Personal Access Tokens
  2. Select repository access (Public, All, or Select)
  3. Create a token with the repo scope (or public_repo for public repositories only)
  4. Copy the generated token

Setting Up with Claude Desktop

To use this MCP server with Claude Desktop, add the following to your claude_desktop_config.json:

Using Docker

{
  "mcpServers": {
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "mcp/github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
      }
    }
  }
}

Using NPX

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
      }
    }
  }
}

Setting Up with VS Code

For manual installation in VS Code, add the following to your User Settings (JSON) file:

Using Docker

{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "github_token",
        "description": "GitHub Personal Access Token",
        "password": true
      }
    ],
    "servers": {
      "github": {
        "command": "docker",
        "args": ["run", "-i", "--rm", "mcp/github"],
        "env": {
          "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
        }
      }
    }
  }
}

Using NPX

{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "github_token",
        "description": "GitHub Personal Access Token",
        "password": true
      }
    ],
    "servers": {
      "github": {
        "command": "npx",
        "args": [
          "-y",
          "@modelcontextprotocol/server-github"
        ],
        "env": {
          "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
        }
      }
    }
  }
}

Alternatively, you can add this configuration to a .vscode/mcp.json file in your workspace (without the mcp key).

Available Tools

File Operations

Create or Update a File

create_or_update_file({
  owner: "username",
  repo: "repository-name",
  path: "path/to/file.txt",
  content: "File content here",
  message: "Commit message",
  branch: "main"
})

Push Multiple Files

push_files({
  owner: "username",
  repo: "repository-name",
  branch: "main",
  files: [
    { path: "file1.txt", content: "Content for file 1" },
    { path: "file2.txt", content: "Content for file 2" }
  ],
  message: "Add multiple files"
})

Get File Contents

get_file_contents({
  owner: "username",
  repo: "repository-name",
  path: "path/to/file.txt",
  branch: "main"
})

Repository Management

Create Repository

create_repository({
  name: "new-repo",
  description: "A new repository",
  private: false,
  autoInit: true
})

Fork Repository

fork_repository({
  owner: "original-owner",
  repo: "repository-to-fork"
})

Create Branch

create_branch({
  owner: "username",
  repo: "repository-name",
  branch: "new-feature",
  from_branch: "main"
})

List Commits

list_commits({
  owner: "username",
  repo: "repository-name",
  sha: "main",
  per_page: 10
})

Issues and Pull Requests

Create Issue

create_issue({
  owner: "username",
  repo: "repository-name",
  title: "Issue title",
  body: "Issue description",
  labels: ["bug", "critical"]
})

Get Issue

get_issue({
  owner: "username",
  repo: "repository-name",
  issue_number: 42
})

List Issues

list_issues({
  owner: "username",
  repo: "repository-name",
  state: "open",
  labels: ["bug"],
  sort: "created",
  direction: "desc"
})

Update Issue

update_issue({
  owner: "username",
  repo: "repository-name",
  issue_number: 42,
  title: "Updated title",
  state: "closed"
})

Add Issue Comment

add_issue_comment({
  owner: "username",
  repo: "repository-name",
  issue_number: 42,
  body: "New comment text"
})

Create Pull Request

create_pull_request({
  owner: "username",
  repo: "repository-name",
  title: "Add new feature",
  body: "This PR adds XYZ functionality",
  head: "feature-branch",
  base: "main"
})

Get Pull Request

get_pull_request({
  owner: "username",
  repo: "repository-name",
  pull_number: 123
})

List Pull Requests

list_pull_requests({
  owner: "username",
  repo: "repository-name",
  state: "open",
  sort: "updated",
  direction: "desc"
})

Create Pull Request Review

create_pull_request_review({
  owner: "username",
  repo: "repository-name",
  pull_number: 123,
  body: "Looks good!",
  event: "APPROVE"
})

Merge Pull Request

merge_pull_request({
  owner: "username",
  repo: "repository-name",
  pull_number: 123,
  merge_method: "squash"
})

Get Pull Request Files

get_pull_request_files({
  owner: "username",
  repo: "repository-name",
  pull_number: 123
})

Update Pull Request Branch

update_pull_request_branch({
  owner: "username",
  repo: "repository-name",
  pull_number: 123
})

Search Functionality

Search Repositories

search_repositories({
  query: "language:javascript stars:>1000",
  page: 1,
  perPage: 10
})

Search Code

search_code({
  q: "import express language:typescript path:src/",
  sort: "indexed",
  order: "desc",
  per_page: 20
})

Search Issues

search_issues({
  q: "is:issue is:open label:bug in:title memory leak",
  sort: "created",
  order: "desc"
})

Search Users

search_users({
  q: "location:London followers:>100 fullstack",
  sort: "followers",
  order: "desc"
})

Search Query Syntax

Code Search Examples

  • Search for JavaScript files containing "React": q: "import React" language:javascript
  • Find TypeScript code in a specific repository: q: "function" language:typescript repo:username/repo-name
  • Look for code in specific file paths: q: "api" path:src/services extension:js

Issues Search Examples

  • Find open bug issues: q: "is:issue is:open label:bug"
  • Search for security issues assigned to a user: q: "security is:issue assignee:username"
  • Find recently updated pull requests: q: "is:pr updated:>2023-01-01"

Users Search Examples

  • Find developers in a specific location: q: "location:Berlin type:user"
  • Search for organizations with many followers: q: "type:org followers:>1000"
  • Find users with specific interests: q: "fullstack developer followers:>100"

For comprehensive search syntax, refer to GitHub's searching documentation.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later