MCPcopy Index your code
hub / github.com/github/github-mcp-server / init

Function init

cmd/github-mcp-server/main.go:204–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202)
203
204func init() {
205 cobra.OnInitialize(initConfig)
206 rootCmd.SetGlobalNormalizationFunc(wordSepNormalizeFunc)
207
208 rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n")
209
210 // Add global flags that will be shared by all commands
211 rootCmd.PersistentFlags().StringSlice("toolsets", nil, github.GenerateToolsetsHelp())
212 rootCmd.PersistentFlags().StringSlice("tools", nil, "Comma-separated list of specific tools to enable")
213 rootCmd.PersistentFlags().StringSlice("exclude-tools", nil, "Comma-separated list of tool names to disable regardless of other settings")
214 rootCmd.PersistentFlags().StringSlice("features", nil, "Comma-separated list of feature flags to enable")
215 rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations")
216 rootCmd.PersistentFlags().String("log-file", "", "Path to log file")
217 rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
218 rootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file")
219 rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)")
220 rootCmd.PersistentFlags().Int("content-window-size", 5000, "Specify the content window size")
221 rootCmd.PersistentFlags().Bool("lockdown-mode", false, "Enable lockdown mode")
222 rootCmd.PersistentFlags().Bool("insiders", false, "Enable insiders features")
223 rootCmd.PersistentFlags().Duration("repo-access-cache-ttl", 5*time.Minute, "Override the repo access cache TTL (e.g. 1m, 0s to disable)")
224
225 // stdio-specific OAuth flags. Provide --oauth-client-id (instead of a token)
226 // to log in via the browser-based OAuth flow on first use. Works for both
227 // OAuth Apps and GitHub Apps.
228 stdioCmd.Flags().String("oauth-client-id", "", "OAuth App or GitHub App client ID, enabling interactive OAuth login when no token is set")
229 stdioCmd.Flags().String("oauth-client-secret", "", "OAuth client secret, if the app requires one (it is a public, non-confidential credential for distributed clients)")
230 stdioCmd.Flags().StringSlice("oauth-scopes", nil, "Comma-separated OAuth scopes to request; also filters tools to those scopes. Defaults to the full supported set")
231 stdioCmd.Flags().Int("oauth-callback-port", 0, "Fixed local port for the OAuth callback server. Defaults to a random port; set a fixed port when mapping it through Docker")
232
233 // HTTP-specific flags
234 httpCmd.Flags().Int("port", 8082, "HTTP server port")
235 httpCmd.Flags().String("listen-host", "", "Host the HTTP server binds to (e.g. 127.0.0.1). Empty binds to all interfaces.")
236 httpCmd.Flags().String("base-url", "", "Base URL where this server is publicly accessible (for OAuth resource metadata)")
237 httpCmd.Flags().String("base-path", "", "Externally visible base path for the HTTP server (for OAuth resource metadata)")
238 httpCmd.Flags().Bool("scope-challenge", false, "Enable OAuth scope challenge responses")
239 httpCmd.Flags().Bool("trust-proxy-headers", false, "Honor X-Forwarded-Host and X-Forwarded-Proto when constructing OAuth resource metadata URLs. Only enable when the server is deployed behind a trusted proxy that sets these headers. Ignored when --base-url is set.")
240
241 // Bind flag to viper
242 _ = viper.BindPFlag("toolsets", rootCmd.PersistentFlags().Lookup("toolsets"))
243 _ = viper.BindPFlag("tools", rootCmd.PersistentFlags().Lookup("tools"))
244 _ = viper.BindPFlag("exclude_tools", rootCmd.PersistentFlags().Lookup("exclude-tools"))
245 _ = viper.BindPFlag("features", rootCmd.PersistentFlags().Lookup("features"))
246 _ = viper.BindPFlag("read-only", rootCmd.PersistentFlags().Lookup("read-only"))
247 _ = viper.BindPFlag("log-file", rootCmd.PersistentFlags().Lookup("log-file"))
248 _ = viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging"))
249 _ = viper.BindPFlag("export-translations", rootCmd.PersistentFlags().Lookup("export-translations"))
250 _ = viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("gh-host"))
251 _ = viper.BindPFlag("content-window-size", rootCmd.PersistentFlags().Lookup("content-window-size"))
252 _ = viper.BindPFlag("lockdown-mode", rootCmd.PersistentFlags().Lookup("lockdown-mode"))
253 _ = viper.BindPFlag("insiders", rootCmd.PersistentFlags().Lookup("insiders"))
254 _ = viper.BindPFlag("repo-access-cache-ttl", rootCmd.PersistentFlags().Lookup("repo-access-cache-ttl"))
255 _ = viper.BindPFlag("oauth-client-id", stdioCmd.Flags().Lookup("oauth-client-id"))
256 _ = viper.BindPFlag("oauth-client-secret", stdioCmd.Flags().Lookup("oauth-client-secret"))
257 _ = viper.BindPFlag("oauth-scopes", stdioCmd.Flags().Lookup("oauth-scopes"))
258 _ = viper.BindPFlag("oauth-callback-port", stdioCmd.Flags().Lookup("oauth-callback-port"))
259 _ = viper.BindPFlag("port", httpCmd.Flags().Lookup("port"))
260 _ = viper.BindPFlag("listen-host", httpCmd.Flags().Lookup("listen-host"))
261 _ = viper.BindPFlag("base-url", httpCmd.Flags().Lookup("base-url"))

Callers

nothing calls this directly

Calls 2

GenerateToolsetsHelpFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected