diff --git a/README.md b/README.md index 76ed3c98..10e50037 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ and set it as the GITHUB_PERSONAL_ACCESS_TOKEN environment variable. - `pull_number`: Pull request number (number, required) - **get_pull_request_reviews** - Get the reviews on a pull request + - `owner`: Repository owner (string, required) - `repo`: Repository name (string, required) - `pull_number`: Pull request number (number, required) @@ -391,6 +392,10 @@ Try something like the following prompt to verify that it works: I'd like to know more about my GitHub profile. ``` +## GitHub Enterprise Server + +The flag `--gh-host` and the environment variable `GH_HOST` can be used to set the GitHub Enterprise Server hostname. + ## TODO Testing diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index f9de5c8d..5e8c520e 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -54,12 +54,14 @@ func init() { rootCmd.PersistentFlags().String("log-file", "", "Path to log file") rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file") rootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file") + rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)") // Bind flag to viper viper.BindPFlag("read-only", rootCmd.PersistentFlags().Lookup("read-only")) viper.BindPFlag("log-file", rootCmd.PersistentFlags().Lookup("log-file")) viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging")) viper.BindPFlag("export-translations", rootCmd.PersistentFlags().Lookup("export-translations")) + viper.BindPFlag("gh-host", rootCmd.PersistentFlags().Lookup("gh-host")) // Add subcommands rootCmd.AddCommand(stdioCmd) @@ -100,6 +102,20 @@ func runStdioServer(readOnly bool, logger *log.Logger, logCommands bool, exportT } ghClient := gogithub.NewClient(nil).WithAuthToken(token) + // Check GH_HOST env var first, then fall back to viper config + host := os.Getenv("GH_HOST") + if host == "" { + host = viper.GetString("gh-host") + } + + if host != "" { + var err error + ghClient, err = ghClient.WithEnterpriseURLs(host, host) + if err != nil { + return fmt.Errorf("failed to create GitHub client with host: %w", err) + } + } + t, dumpTranslations := translations.TranslationHelper() // Create