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
202.2K downloads
39.2K stars

The GitHub MCP Server enables Git operations through the GitHub API, providing file management, repository functions, search capabilities, and more—all without requiring a local Git installation.

Installation

Requirements

To use the GitHub MCP Server, you'll need a GitHub Personal Access Token with the appropriate permissions.

Setting Up Your GitHub Token

  1. Create a GitHub Personal Access Token:
    • Go to Personal access tokens in GitHub Settings > Developer settings
    • Choose which repositories you want the token to access (Public, All, or Select)
    • Select the repo scope for full repository access (or public_repo for public repositories only)
    • Copy the generated token

Configuration with Claude Desktop

To integrate the GitHub MCP Server with Claude Desktop, update your claude_desktop_config.json file using one of the following methods:

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>"
      }
    }
  }
}

Usage

The GitHub MCP Server provides numerous tools for interacting with GitHub repositories. Here are the main functions:

File Operations

Creating or Updating a File

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

Getting File Contents

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

Pushing Multiple Files

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

Repository Management

Creating a Repository

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

Creating a Branch

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

Forking a Repository

fork_repository({
  owner: "original-owner",
  repo: "repository-name",
  organization: "my-organization"  // optional
})

Listing Commits

list_commits({
  owner: "username",
  repo: "repository-name",
  page: "1",  // optional
  per_page: "30",  // optional
  sha: "main"  // optional, branch name
})

Issues and Pull Requests

Creating an Issue

create_issue({
  owner: "username",
  repo: "repository-name",
  title: "Bug in login function",
  body: "The login function throws an error when...",
  assignees: ["developer1", "developer2"],  // optional
  labels: ["bug", "priority-high"],  // optional
  milestone: 1  // optional
})

Creating a Pull Request

create_pull_request({
  owner: "username",
  repo: "repository-name",
  title: "Add login feature",
  body: "This PR implements the login functionality...",
  head: "feature-login",
  base: "main",
  draft: false,  // optional
  maintainer_can_modify: true  // optional
})

Getting Pull Request Details

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

Merging a Pull Request

merge_pull_request({
  owner: "username",
  repo: "repository-name",
  pull_number: 123,
  commit_title: "Merge login feature",  // optional
  commit_message: "This adds the login functionality",  // optional
  merge_method: "squash"  // optional: 'merge', 'squash', 'rebase'
})

Search Functionality

The GitHub MCP Server supports powerful search capabilities:

Searching Repositories

search_repositories({
  query: "machine learning language:python stars:>1000",
  page: 1,  // optional
  perPage: 50  // optional
})

Searching Code

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

Searching Issues and Pull Requests

search_issues({
  q: "memory leak is:issue is:open label:bug",
  sort: "created",  // optional
  order: "desc",  // optional
  per_page: 50,  // optional
  page: 1  // optional
})

Searching Users

search_users({
  q: "fullstack developer location:London followers:>100",
  sort: "followers",  // optional
  order: "desc",  // optional
  per_page: 50,  // optional
  page: 1  // optional
})

Search Query Syntax

Code Search Examples

  • language:javascript - Search by programming language
  • repo:owner/name - Search in specific repository
  • path:app/src - Search in specific path
  • extension:js - Search by file extension

Issues Search Examples

  • is:issue or is:pr - Filter by type
  • is:open or is:closed - Filter by state
  • label:bug - Search by label
  • author:username - Search by author

Users Search Examples

  • type:user or type:org - Filter by account type
  • followers:>1000 - Filter by followers
  • location:London - Search by location

For complete search syntax documentation, 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