From c85178d3df01d96d24ddc05bea1a44ff1a956529 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Wed, 25 Jun 2025 15:46:21 +0200 Subject: [PATCH 1/6] Add underscore variant --- cmd/github-mcp-server/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index fb716f78d..f9fe64cbe 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -49,7 +49,7 @@ var ( Token: token, EnabledToolsets: enabledToolsets, DynamicToolsets: viper.GetBool("dynamic_toolsets"), - ReadOnly: viper.GetBool("read-only"), + ReadOnly: viper.GetBool("read-only") || viper.GetBool("read_only"), ExportTranslations: viper.GetBool("export-translations"), EnableCommandLogging: viper.GetBool("enable-command-logging"), LogFilePath: viper.GetString("log-file"), @@ -65,10 +65,13 @@ func init() { rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n") + readOnlyFlag := false + // Add global flags that will be shared by all commands rootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools, "An optional comma separated list of groups of tools to allow, defaults to enabling all") rootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets") - rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations") + rootCmd.PersistentFlags().BoolVar(&readOnlyFlag, "read-only", false, "Restrict the server to read-only operations") + rootCmd.PersistentFlags().BoolVar(&readOnlyFlag, "read_only", false, "Restrict the server to read-only operations") 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") From 8e0c5efb1a9bce457eb49f3645b458965cdca55e Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Wed, 25 Jun 2025 15:48:45 +0200 Subject: [PATCH 2/6] Remove unnecessary or --- cmd/github-mcp-server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index f9fe64cbe..7430400ac 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -49,7 +49,7 @@ var ( Token: token, EnabledToolsets: enabledToolsets, DynamicToolsets: viper.GetBool("dynamic_toolsets"), - ReadOnly: viper.GetBool("read-only") || viper.GetBool("read_only"), + ReadOnly: viper.GetBool("read-only"), ExportTranslations: viper.GetBool("export-translations"), EnableCommandLogging: viper.GetBool("enable-command-logging"), LogFilePath: viper.GetString("log-file"), From f3cb8a693e68f552d3267089f3a2585a1a9a2b61 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Wed, 25 Jun 2025 16:01:13 +0200 Subject: [PATCH 3/6] Bind --- cmd/github-mcp-server/main.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index 7430400ac..7743afcb8 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -49,12 +49,11 @@ var ( Token: token, EnabledToolsets: enabledToolsets, DynamicToolsets: viper.GetBool("dynamic_toolsets"), - ReadOnly: viper.GetBool("read-only"), + ReadOnly: viper.GetBool("read-only") || viper.GetBool("read_only"), ExportTranslations: viper.GetBool("export-translations"), EnableCommandLogging: viper.GetBool("enable-command-logging"), LogFilePath: viper.GetString("log-file"), } - return ghmcp.RunStdioServer(stdioServerConfig) }, } @@ -65,13 +64,11 @@ func init() { rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n") - readOnlyFlag := false - // Add global flags that will be shared by all commands rootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools, "An optional comma separated list of groups of tools to allow, defaults to enabling all") rootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets") - rootCmd.PersistentFlags().BoolVar(&readOnlyFlag, "read-only", false, "Restrict the server to read-only operations") - rootCmd.PersistentFlags().BoolVar(&readOnlyFlag, "read_only", false, "Restrict the server to read-only operations") + rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations") + rootCmd.PersistentFlags().Bool("read_only", false, "Restrict the server to read-only operations") 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") @@ -81,6 +78,7 @@ func init() { _ = viper.BindPFlag("toolsets", rootCmd.PersistentFlags().Lookup("toolsets")) _ = viper.BindPFlag("dynamic_toolsets", rootCmd.PersistentFlags().Lookup("dynamic-toolsets")) _ = viper.BindPFlag("read-only", rootCmd.PersistentFlags().Lookup("read-only")) + _ = 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")) @@ -94,6 +92,7 @@ func initConfig() { // Initialize Viper configuration viper.SetEnvPrefix("github") viper.AutomaticEnv() + } func main() { From f54546a2da82dae5a9983b368ed4faac320b5b3a Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Thu, 26 Jun 2025 15:30:50 +0200 Subject: [PATCH 4/6] Update main.go --- cmd/github-mcp-server/main.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index 7743afcb8..652d7b742 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -4,10 +4,12 @@ import ( "errors" "fmt" "os" + "strings" "github.com/github/github-mcp-server/internal/ghmcp" "github.com/github/github-mcp-server/pkg/github" "github.com/spf13/cobra" + "github.com/spf13/pflag" "github.com/spf13/viper" ) @@ -49,7 +51,7 @@ var ( Token: token, EnabledToolsets: enabledToolsets, DynamicToolsets: viper.GetBool("dynamic_toolsets"), - ReadOnly: viper.GetBool("read-only") || viper.GetBool("read_only"), + ReadOnly: viper.GetBool("read-only"), ExportTranslations: viper.GetBool("export-translations"), EnableCommandLogging: viper.GetBool("enable-command-logging"), LogFilePath: viper.GetString("log-file"), @@ -61,6 +63,7 @@ var ( func init() { cobra.OnInitialize(initConfig) + rootCmd.SetGlobalNormalizationFunc(wordSepNormalizeFunc) rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n") @@ -68,7 +71,6 @@ func init() { rootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools, "An optional comma separated list of groups of tools to allow, defaults to enabling all") rootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets") rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations") - rootCmd.PersistentFlags().Bool("read_only", false, "Restrict the server to read-only operations") 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") @@ -78,7 +80,6 @@ func init() { _ = viper.BindPFlag("toolsets", rootCmd.PersistentFlags().Lookup("toolsets")) _ = viper.BindPFlag("dynamic_toolsets", rootCmd.PersistentFlags().Lookup("dynamic-toolsets")) _ = viper.BindPFlag("read-only", rootCmd.PersistentFlags().Lookup("read-only")) - _ = 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")) @@ -101,3 +102,12 @@ func main() { os.Exit(1) } } + +func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName { + from := []string{"_"} + to := "-" + for _, sep := range from { + name = strings.Replace(name, sep, to, -1) + } + return pflag.NormalizedName(name) +} From 13383eae33b44db095b584e9520b845e10b90808 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Thu, 26 Jun 2025 15:34:30 +0200 Subject: [PATCH 5/6] Tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9cee56b5c..4cc7682fd 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,7 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.14.0 // indirect github.com/spf13/cast v1.7.1 // indirect - github.com/spf13/pflag v1.0.6 // indirect + github.com/spf13/pflag v1.0.6 github.com/subosito/gotenv v1.6.0 // indirect github.com/yosida95/uritemplate/v3 v3.0.2 // indirect go.uber.org/multierr v1.11.0 // indirect From 043949b255823b766ec9a781de69a9c446183344 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Thu, 26 Jun 2025 15:36:58 +0200 Subject: [PATCH 6/6] Fix linter error --- cmd/github-mcp-server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index 652d7b742..b39a8b7df 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -107,7 +107,7 @@ func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName { from := []string{"_"} to := "-" for _, sep := range from { - name = strings.Replace(name, sep, to, -1) + name = strings.ReplaceAll(name, sep, to) } return pflag.NormalizedName(name) }