Skip to content

Commit 9e51548

Browse files
authored
Merge branch 'main' into juruen/create-pr
2 parents fc99b14 + 671f824 commit 9e51548

File tree

230 files changed

+12401
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+12401
-161
lines changed

.github/licenses.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# GitHub MCP Server dependencies
2+
3+
The following open source dependencies are used to build the [github/github-mcp-server][] GitHub Model Context Protocol Server.
4+
5+
## Go Packages
6+
7+
Some packages may only be included on certain architectures or operating systems.
8+
9+
{{ range . }}
10+
- [{{.Name}}](https://pkg.go.dev/{{.Name}}) ([{{.LicenseName}}]({{.LicenseURL}}))
11+
{{- end }}
12+
13+
[github/github-mcp-server]: https://github.com/github/github-mcp-server
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Create a github action that runs the license check script and fails if it exits with a non-zero status
2+
3+
name: License Check
4+
on: [push, pull_request]
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
license-check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: "go.mod"
20+
- name: check licenses
21+
run: ./script/licenses-check

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.idea
2+
cmd/github-mcp-server/github-mcp-server

README.md

Lines changed: 74 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,113 @@
11
# GitHub MCP Server
22

3-
GitHub MCP Server implemented in Go.
3+
The GitHub MCP Server is a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction)
4+
server that provides seamless integration with GitHub APIs, enabling advanced
5+
automation and interaction capabilities for developers and tools.
46

5-
## Setup
7+
## Use Cases
68

7-
Create a GitHub Personal Access Token with the appropriate permissions
8-
and set it as the GITHUB_PERSONAL_ACCESS_TOKEN environment variable.
9+
- Automating GitHub workflows and processes.
10+
- Extracting and analyzing data from GitHub repositories.
11+
- Building AI powered tools and applications that interact with GitHub's ecosystem.
912

10-
## Testing in VS Code Insiders
13+
## Prerequisites
1114

12-
### Requirements
15+
[Create a GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new).
16+
The MCP server can use many of the GitHub APIs, so enable the permissions that you feel comfortable granting your AI tools.
1317

14-
You can either use a Docker image or build the binary from the repo.
18+
To learn more about access tokens, please check out the [documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).
1519

16-
#### Docker image
20+
To run the server in a container, you will need to have [Docker](https://www.docker.com/) installed.
1721

18-
As of now, this repo is private, and hence the docker image is not available publicly. To pull it,
19-
you need to make sure you can access the GitHub docker registry. See [this](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic)
20-
for more details.
22+
## Installation
2123

22-
To make sure you can access the GitHub docker registry, run the following command:
24+
### Usage with VS Code
2325

24-
```bash
25-
docker pull ghcr.io/github/github-mcp-server:main
26-
```
26+
Install the GitHub MCP server into VS Code by clicking here:
2727

28-
If the above command works, you are good to go.
28+
[<img alt="Install in VS Code Insiders" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Server&color=24bfa5">](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%25%7B%22name%22%3A%22github%22%2C%22command%22%3A%22docker%22%2C%22args%22%3A%5B%22run%22%2C%20%22-i%22%2C%20%22--rm%22%2C%20%22-e%22%2C%20%22GITHUB_PERSONAL_ACCESS_TOKEN%22%2C%20%22ghcr.io%2Fgithub%2Fgithub-mcp-server%3Amain%22%5D%2C%20%22env%22%3A%20%7B%22GITHUB_PERSONAL_ACCESS_TOKEN%22%3A%20%22%24%7Binput%3Agithub-pat%7D%22%7D%2C%20%22inputs%22%3A%20%5B%7B%20%22id%22%3A%20%22github-pat%22%2C%20%22type%22%3A%20%22promptString%22%2C%20%22description%22%3A%20%22Github%20Personal%20Access%20Token%22%2C%20%22password%22%3A%20true%7D%5D%7D)
2929

30-
#### Build from repo
31-
First, install `github-mcp-server` by cloning the repo and running the following command:
30+
Or run this command in your terminal:
3231

3332
```bash
34-
go install ./cmd/github-mcp-server
35-
```
33+
code --add-mcp '{"name":"github","command":"docker","args":["run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server:main"], "env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github-pat}"}, "inputs": [{ "id": "github-pat", "type": "promptString", "description": "Github Personal Access Token", "password": true}]}'
3634

37-
If you don't want to clone the repo, you can run:
38-
39-
```bash
40-
GOPRIVATE=github.com/github go install github.com/github/github-mcp-server/cmd/github-mcp-server@latest
4135
```
36+
VS Code is now configured and will prompt for your token the first time you use agent mode.
4237

43-
This will install the `github-mcp-server` binary in your `$GOPATH/bin` directory.
38+
### Usage with Claude Desktop
4439

45-
Find where the binary is installed by running:
46-
47-
```bash
48-
# note this assumes $GOPATH/bin is in your $PATH
49-
which github-mcp-server
40+
```json
41+
{
42+
"mcpServers": {
43+
"github": {
44+
"command": "docker",
45+
"args": [
46+
"run",
47+
"-i",
48+
"--rm",
49+
"-e",
50+
"GITHUB_PERSONAL_ACCESS_TOKEN",
51+
"ghcr.io/github/github-mcp-server:main"
52+
],
53+
"env": {
54+
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
55+
}
56+
}
57+
}
58+
}
5059
```
5160

52-
### Start VS Code Insiders
61+
### Build from source
5362

54-
Start VS Code Insiders and make sure you pass the `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable to the process.
63+
If you don't have Docker, you can use `go` to build the binary in the
64+
`cmd/github-mcp-server` directory, and use the `github-mcp-server stdio`
65+
command with the `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable set to
66+
your token.
5567

56-
One way to do this is to make sure that [you can run VS code from your terminal](https://code.visualstudio.com/docs/setup/mac#_launch-vs-code-from-the-command-line) and
57-
start it with the following command:
68+
## GitHub Enterprise Server
5869

59-
```bash
60-
export GITHUB_PERSONAL_ACCESS_TOKEN=your-token-here
61-
code-insiders
62-
```
70+
The flag `--gh-host` and the environment variable `GH_HOST` can be used to set
71+
the GitHub Enterprise Server hostname.
6372

64-
Another way is to set the environment variable in your shell configuration file (e.g., `.bashrc`, `.zshrc`, etc.).
73+
## i18n / Overriding Descriptions
6574

66-
Create a new file `.vscode/mcp.json` and provide this configuration:
75+
The descriptions of the tools can be overridden by creating a
76+
`github-mcp-server-config.json` file in the same directory as the binary.
6777

68-
If you are using the docker image, use this configuration:
78+
The file should contain a JSON object with the tool names as keys and the new
79+
descriptions as values. For example:
6980

7081
```json
7182
{
72-
"inputs": [
73-
{
74-
"id": "github-pat",
75-
"type": "promptString",
76-
"description": "Github Personal Access Token",
77-
"password": true,
78-
}
79-
],
80-
"servers": {
81-
"github-mcp-server": {
82-
"type": "stdio",
83-
"command": "docker",
84-
"args": [
85-
"run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server:main"
86-
],
87-
"env": {
88-
"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github-pat}"
89-
}
90-
}
91-
}
83+
"TOOL_ADD_ISSUE_COMMENT_DESCRIPTION": "an alternative description",
84+
"TOOL_CREATE_BRANCH_DESCRIPTION": "Create a new branch in a GitHub repository"
9285
}
9386
```
9487

95-
When you start the server, VS Code will prompt for your token, as indicated by `${input:github-pat}`.
88+
You can create an export of the current translations by running the binary with
89+
the `--export-translations` flag.
9690

97-
If you built the binary from the repo use this configuration:
91+
This flag will preserve any translations/overrides you have made, while adding
92+
any new translations that have been added to the binary since the last time you
93+
exported.
9894

99-
```json
100-
{
101-
"mcp": {
102-
"inputs": [ ],
103-
"servers": {
104-
"mcp-github-server": {
105-
"command": "path-to-your/github-mcp-server",
106-
"args": ["stdio"],
107-
"env": { }
108-
}
109-
}
110-
}
111-
}
95+
```sh
96+
./github-mcp-server --export-translations
97+
cat github-mcp-server-config.json
11298
```
11399

114-
Right on top of `servers`, you should see a `Start` link to start the server.
100+
You can also use ENV vars to override the descriptions. The environment
101+
variable names are the same as the keys in the JSON file, prefixed with
102+
`GITHUB_MCP_` and all uppercase.
115103

104+
For example, to override the `TOOL_ADD_ISSUE_COMMENT_DESCRIPTION` tool, you can
105+
set the following environment variable:
116106

117-
Try something like the following prompt to verify that it works:
118-
119-
```
120-
I'd like to know more about my GitHub profile.
107+
```sh
108+
export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description"
121109
```
122110

123-
## GitHub Enterprise Server
124-
125-
The flag `--gh-host` and the environment variable `GH_HOST` can be used to set the GitHub Enterprise Server hostname.
126-
127-
128111
## Tools
129112

130113
### Users
@@ -366,7 +349,7 @@ The flag `--gh-host` and the environment variable `GH_HOST` can be used to set t
366349

367350
### Repository Content
368351

369-
- **Get Repository Content**
352+
- **Get Repository Content**
370353
Retrieves the content of a repository at a specific path.
371354

372355
- **Template**: `repo://{owner}/{repo}/contents{/path*}`
@@ -375,7 +358,7 @@ The flag `--gh-host` and the environment variable `GH_HOST` can be used to set t
375358
- `repo`: Repository name (string, required)
376359
- `path`: File or directory path (string, optional)
377360

378-
- **Get Repository Content for a Specific Branch**
361+
- **Get Repository Content for a Specific Branch**
379362
Retrieves the content of a repository at a specific path for a given branch.
380363

381364
- **Template**: `repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}`
@@ -385,7 +368,7 @@ The flag `--gh-host` and the environment variable `GH_HOST` can be used to set t
385368
- `branch`: Branch name (string, required)
386369
- `path`: File or directory path (string, optional)
387370

388-
- **Get Repository Content for a Specific Commit**
371+
- **Get Repository Content for a Specific Commit**
389372
Retrieves the content of a repository at a specific path for a given commit.
390373

391374
- **Template**: `repo://{owner}/{repo}/sha/{sha}/contents{/path*}`
@@ -395,7 +378,7 @@ The flag `--gh-host` and the environment variable `GH_HOST` can be used to set t
395378
- `sha`: Commit SHA (string, required)
396379
- `path`: File or directory path (string, optional)
397380

398-
- **Get Repository Content for a Specific Tag**
381+
- **Get Repository Content for a Specific Tag**
399382
Retrieves the content of a repository at a specific path for a given tag.
400383

401384
- **Template**: `repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}`
@@ -405,7 +388,7 @@ The flag `--gh-host` and the environment variable `GH_HOST` can be used to set t
405388
- `tag`: Tag name (string, required)
406389
- `path`: File or directory path (string, optional)
407390

408-
- **Get Repository Content for a Specific Pull Request**
391+
- **Get Repository Content for a Specific Pull Request**
409392
Retrieves the content of a repository at a specific path for a given pull request.
410393

411394
- **Template**: `repo://{owner}/{repo}/refs/pull/{pr_number}/head/contents{/path*}`
@@ -414,73 +397,3 @@ The flag `--gh-host` and the environment variable `GH_HOST` can be used to set t
414397
- `repo`: Repository name (string, required)
415398
- `pr_number`: Pull request number (string, required)
416399
- `path`: File or directory path (string, optional)
417-
418-
## Standard input/output server
419-
420-
```sh
421-
go run cmd/github-mcp-server/main.go stdio
422-
```
423-
424-
E.g:
425-
426-
Set the PAT token in the environment variable and run:
427-
428-
```sh
429-
script/get-me
430-
```
431-
432-
And you should see the output of the GitHub MCP server responding with the user information.
433-
434-
```sh
435-
GitHub MCP Server running on stdio
436-
{
437-
"jsonrpc": "2.0",
438-
"id": 3,
439-
"result": {
440-
"content": [
441-
{
442-
"type": "text",
443-
"text": "{\"login\":\"juruen\",\"id\" ... }
444-
}
445-
]
446-
}
447-
}
448-
449-
```
450-
451-
## i18n / Overriding descriptions
452-
453-
The descriptions of the tools can be overridden by creating a github-mcp-server.json file in the same directory as the binary.
454-
The file should contain a JSON object with the tool names as keys and the new descriptions as values.
455-
For example:
456-
457-
```json
458-
{
459-
"TOOL_ADD_ISSUE_COMMENT_DESCRIPTION": "an alternative description",
460-
"TOOL_CREATE_BRANCH_DESCRIPTION": "Create a new branch in a GitHub repository"
461-
}
462-
```
463-
464-
You can create an export of the current translations by running the binary with the `--export-translations` flag.
465-
This flag will preserve any translations/overrides you have made, while adding any new translations that have been added to the binary since the last time you exported.
466-
467-
```sh
468-
./github-mcp-server --export-translations
469-
cat github-mcp-server.json
470-
```
471-
472-
You can also use ENV vars to override the descriptions. The environment variable names are the same as the keys in the JSON file,
473-
prefixed with `GITHUB_MCP_` and all uppercase.
474-
475-
For example, to override the `TOOL_ADD_ISSUE_COMMENT_DESCRIPTION` tool, you can set the following environment variable:
476-
477-
```sh
478-
export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description"
479-
```
480-
481-
## TODO
482-
483-
Testing
484-
485-
- Integration tests
486-
- Blackbox testing: ideally comparing output to Anthropic's server to make sure that this is a fully compatible drop-in replacement.

cmd/github-mcp-server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func runStdioServer(readOnly bool, logger *log.Logger, logCommands bool, exportT
101101
logger.Fatal("GITHUB_PERSONAL_ACCESS_TOKEN not set")
102102
}
103103
ghClient := gogithub.NewClient(nil).WithAuthToken(token)
104+
ghClient.UserAgent = "github-mcp-server/1.0"
104105

105106
// Check GH_HOST env var first, then fall back to viper config
106107
host := os.Getenv("GH_HOST")

script/licenses

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
go install github.com/google/go-licenses@latest
4+
go-licenses report ./... --template .github/licenses.tmpl > third-party-licenses.md || echo "Ignore warnings"
5+
go-licenses save ./... --save_path=third-party --force || echo "Ignore warnings"

script/licenses-check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
trap 'rm -f third-party-licenses.copy.md' EXIT
4+
5+
go install github.com/google/go-licenses@latest
6+
go-licenses report ./... --template .github/licenses.tmpl > third-party-licenses.copy.md || echo "Ignore warnings"
7+
# if not diff -s then exit 1
8+
9+
if ! diff -s third-party-licenses.copy.md third-party-licenses.md; then
10+
echo "License check failed. Please update the license file."
11+
exit 1
12+
fi

0 commit comments

Comments
 (0)