Skip to content

Commit e7002b8

Browse files
committed
feat: enable go run execution by moving main to root
- Move main.go to project root to enable `go run github.com/github/github-mcp-server@latest` - Delegate execution to cmd/github-mcp-server package - Update build configurations (Dockerfile, .goreleaser.yaml) - Fix ldflags paths and import aliases - Maintain backwards compatibility with existing cmd structure
1 parent ea73047 commit e7002b8

Some content is hidden

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

48 files changed

+206
-183
lines changed

.github/licenses.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Some packages may only be included on certain architectures or operating systems
1010
- [{{.Name}}](https://pkg.go.dev/{{.Name}}) ([{{.LicenseName}}]({{.LicenseURL}}))
1111
{{- end }}
1212

13-
[github/github-mcp-server]: https://github.com/github/github-mcp-server
13+
[github/github-mcp-server]: https://github.com/SchulteDev/github_github-mcp-server

.github/workflows/docs-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
go-version-file: 'go.mod'
2323

2424
- name: Build docs generator
25-
run: go build -o github-mcp-server ./cmd/github-mcp-server
25+
run: go build -o github-mcp-server .
2626

2727
- name: Generate documentation
2828
run: ./github-mcp-server generate-docs
@@ -35,7 +35,7 @@ jobs:
3535
echo "The generated documentation differs from what's committed."
3636
echo "Please run the following command to update the documentation:"
3737
echo ""
38-
echo " go run ./cmd/github-mcp-server generate-docs"
38+
echo " go run . generate-docs"
3939
echo ""
4040
echo "Then commit the changes."
4141
echo ""

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
run: script/test
3030

3131
- name: Build
32-
run: go build -v ./cmd/github-mcp-server
32+
run: go build -v .

.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ builds:
99
- env:
1010
- CGO_ENABLED=0
1111
ldflags:
12-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
12+
- -s -w -X github.com/SchulteDev/github_github-mcp-server/cmd/github-mcp-server.version={{.Version}} -X github.com/SchulteDev/github_github-mcp-server/cmd/github-mcp-server.commit={{.Commit}} -X github.com/SchulteDev/github_github-mcp-server/cmd/github-mcp-server.date={{.Date}}
1313
goos:
1414
- linux
1515
- windows
1616
- darwin
17-
main: ./cmd/github-mcp-server
17+
main: .
1818

1919
archives:
2020
- formats: tar.gz

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"mode": "auto",
1212
"cwd": "${workspaceFolder}",
13-
"program": "cmd/github-mcp-server/main.go",
13+
"program": "main.go",
1414
"args": ["stdio"],
1515
"console": "integratedTerminal",
1616
},
@@ -20,7 +20,7 @@
2020
"request": "launch",
2121
"mode": "auto",
2222
"cwd": "${workspaceFolder}",
23-
"program": "cmd/github-mcp-server/main.go",
23+
"program": "main.go",
2424
"args": ["stdio", "--read-only"],
2525
"console": "integratedTerminal",
2626
}

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Contributing
22

3-
[fork]: https://github.com/github/github-mcp-server/fork
4-
[pr]: https://github.com/github/github-mcp-server/compare
5-
[style]: https://github.com/github/github-mcp-server/blob/main/.golangci.yml
3+
[fork]: https://github.com/SchulteDev/github_github-mcp-server/fork
4+
[pr]: https://github.com/SchulteDev/github_github-mcp-server/compare
5+
[style]: https://github.com/SchulteDev/github_github-mcp-server/blob/main/.golangci.yml
66

77
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
88

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ RUN --mount=type=cache,target=/var/cache/apk \
1313
RUN --mount=type=cache,target=/go/pkg/mod \
1414
--mount=type=cache,target=/root/.cache/go-build \
1515
--mount=type=bind,target=. \
16-
CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=${VERSION} -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
17-
-o /bin/github-mcp-server cmd/github-mcp-server/main.go
16+
CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/SchulteDev/github_github-mcp-server/cmd/github-mcp-server.version=${VERSION} -X github.com/SchulteDev/github_github-mcp-server/cmd/github-mcp-server.commit=$(git rev-parse HEAD) -X github.com/SchulteDev/github_github-mcp-server/cmd/github-mcp-server.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
17+
-o /bin/github-mcp-server .
1818

1919
# Make a stage to run the app
2020
FROM gcr.io/distroless/base-debian12

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ automation and interaction capabilities for developers and tools.
1616

1717
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=github&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2F%22%7D) [![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install_Server-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=github&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2F%22%7D&quality=insiders)
1818

19-
The remote GitHub MCP Server is hosted by GitHub and provides the easiest method for getting up and running. If your MCP host does not support remote MCP servers, don't worry! You can use the [local version of the GitHub MCP Server](https://github.com/github/github-mcp-server?tab=readme-ov-file#local-github-mcp-server) instead.
19+
The remote GitHub MCP Server is hosted by GitHub and provides the easiest method for getting up and running. If your MCP host does not support remote MCP servers, don't worry! You can use the [local version of the GitHub MCP Server](https://github.com/SchulteDev/github_github-mcp-server?tab=readme-ov-file#local-github-mcp-server) instead.
2020

2121
## Prerequisites
2222

@@ -234,8 +234,43 @@ More about using MCP server tools in VS Code's [agent mode documentation](https:
234234

235235
### Build from source
236236

237-
If you don't have Docker, you can use `go build` to build the binary in the
238-
`cmd/github-mcp-server` directory, and use the `github-mcp-server stdio` command with the `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable set to your token. To specify the output location of the build, use the `-o` flag. You should configure your server to use the built executable as its `command`. For example:
237+
If you don't have Docker, you have several options:
238+
239+
#### Option 1: Run directly from source (Recommended)
240+
241+
You can run the server directly from source using `go run`:
242+
243+
```bash
244+
GITHUB_PERSONAL_ACCESS_TOKEN=<your-token> go run github.com/SchulteDev/github_github-mcp-server@latest stdio
245+
```
246+
247+
Or configure your MCP host to use `go run`:
248+
249+
```JSON
250+
{
251+
"mcp": {
252+
"servers": {
253+
"github": {
254+
"command": "go",
255+
"args": ["run", "github.com/SchulteDev/github_github-mcp-server@latest", "stdio"],
256+
"env": {
257+
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
258+
}
259+
}
260+
}
261+
}
262+
}
263+
```
264+
265+
#### Option 2: Build and install
266+
267+
You can build the binary and use the built executable:
268+
269+
```bash
270+
go build -o github-mcp-server github.com/SchulteDev/github_github-mcp-server@latest
271+
```
272+
273+
Then configure your server to use the built executable:
239274

240275
```JSON
241276
{

cmd/github-mcp-server/generate_docs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"
@@ -9,10 +9,10 @@ import (
99
"sort"
1010
"strings"
1111

12-
"github.com/github/github-mcp-server/pkg/github"
13-
"github.com/github/github-mcp-server/pkg/raw"
14-
"github.com/github/github-mcp-server/pkg/toolsets"
15-
"github.com/github/github-mcp-server/pkg/translations"
12+
"github.com/SchulteDev/github_github-mcp-server/pkg/github"
13+
"github.com/SchulteDev/github_github-mcp-server/pkg/raw"
14+
"github.com/SchulteDev/github_github-mcp-server/pkg/toolsets"
15+
"github.com/SchulteDev/github_github-mcp-server/pkg/translations"
1616
gogithub "github.com/google/go-github/v72/github"
1717
"github.com/mark3labs/mcp-go/mcp"
1818
"github.com/shurcooL/githubv4"
@@ -29,7 +29,7 @@ var generateDocsCmd = &cobra.Command{
2929
}
3030

3131
func init() {
32-
rootCmd.AddCommand(generateDocsCmd)
32+
RootCmd.AddCommand(generateDocsCmd)
3333
}
3434

3535
// mockGetClient returns a mock GitHub client for documentation generation

cmd/github-mcp-server/main.go renamed to cmd/github-mcp-server/root_command.go

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
package main
1+
package cmd
22

33
import (
44
"errors"
55
"fmt"
6-
"os"
76
"strings"
87

9-
"github.com/github/github-mcp-server/internal/ghmcp"
10-
"github.com/github/github-mcp-server/pkg/github"
8+
"github.com/SchulteDev/github_github-mcp-server/internal/ghmcp"
9+
"github.com/SchulteDev/github_github-mcp-server/pkg/github"
1110
"github.com/spf13/cobra"
1211
"github.com/spf13/pflag"
1312
"github.com/spf13/viper"
@@ -19,7 +18,7 @@ var commit = "commit"
1918
var date = "date"
2019

2120
var (
22-
rootCmd = &cobra.Command{
21+
RootCmd = &cobra.Command{
2322
Use: "server",
2423
Short: "GitHub MCP Server",
2524
Long: `A GitHub MCP server that handles various tools and resources.`,
@@ -63,30 +62,30 @@ var (
6362

6463
func init() {
6564
cobra.OnInitialize(initConfig)
66-
rootCmd.SetGlobalNormalizationFunc(wordSepNormalizeFunc)
65+
RootCmd.SetGlobalNormalizationFunc(wordSepNormalizeFunc)
6766

68-
rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n")
67+
RootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n")
6968

7069
// Add global flags that will be shared by all commands
71-
rootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools, "An optional comma separated list of groups of tools to allow, defaults to enabling all")
72-
rootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets")
73-
rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations")
74-
rootCmd.PersistentFlags().String("log-file", "", "Path to log file")
75-
rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
76-
rootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file")
77-
rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)")
70+
RootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools, "An optional comma separated list of groups of tools to allow, defaults to enabling all")
71+
RootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets")
72+
RootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations")
73+
RootCmd.PersistentFlags().String("log-file", "", "Path to log file")
74+
RootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
75+
RootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file")
76+
RootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)")
7877

7978
// Bind flag to viper
80-
_ = viper.BindPFlag("toolsets", rootCmd.PersistentFlags().Lookup("toolsets"))
81-
_ = viper.BindPFlag("dynamic_toolsets", rootCmd.PersistentFlags().Lookup("dynamic-toolsets"))
82-
_ = viper.BindPFlag("read-only", rootCmd.PersistentFlags().Lookup("read-only"))
83-
_ = viper.BindPFlag("log-file", rootCmd.PersistentFlags().Lookup("log-file"))
84-
_ = viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging"))
85-
_ = viper.BindPFlag("export-translations", rootCmd.PersistentFlags().Lookup("export-translations"))
86-
_ = viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("gh-host"))
79+
_ = viper.BindPFlag("toolsets", RootCmd.PersistentFlags().Lookup("toolsets"))
80+
_ = viper.BindPFlag("dynamic_toolsets", RootCmd.PersistentFlags().Lookup("dynamic-toolsets"))
81+
_ = viper.BindPFlag("read-only", RootCmd.PersistentFlags().Lookup("read-only"))
82+
_ = viper.BindPFlag("log-file", RootCmd.PersistentFlags().Lookup("log-file"))
83+
_ = viper.BindPFlag("enable-command-logging", RootCmd.PersistentFlags().Lookup("enable-command-logging"))
84+
_ = viper.BindPFlag("export-translations", RootCmd.PersistentFlags().Lookup("export-translations"))
85+
_ = viper.BindPFlag("host", RootCmd.PersistentFlags().Lookup("gh-host"))
8786

8887
// Add subcommands
89-
rootCmd.AddCommand(stdioCmd)
88+
RootCmd.AddCommand(stdioCmd)
9089
}
9190

9291
func initConfig() {
@@ -96,13 +95,6 @@ func initConfig() {
9695

9796
}
9897

99-
func main() {
100-
if err := rootCmd.Execute(); err != nil {
101-
fmt.Fprintf(os.Stderr, "%v\n", err)
102-
os.Exit(1)
103-
}
104-
}
105-
10698
func wordSepNormalizeFunc(_ *pflag.FlagSet, name string) pflag.NormalizedName {
10799
from := []string{"_"}
108100
to := "-"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy