github/github-mcp-server · warning

failed to create OAuth handler: %w

Error message

failed to create OAuth handler: %w

What it means

oauth.NewAuthHandler(cfg, apiHost) failed while constructing the OAuth protected-resource metadata handler. Internally it only errors when the apiHost resolver is nil and the hardcoded default host fails to parse - but RunHTTPServer already parsed apiHost successfully at startup, so this branch is effectively unreachable defensive error wrapping.

Source

Thrown at pkg/http/server.go:185

	// Register OAuth protected resource metadata endpoints
	oauthCfg := &oauth.Config{
		BaseURL:           cfg.BaseURL,
		ResourcePath:      cfg.ResourcePath,
		TrustProxyHeaders: cfg.TrustProxyHeaders,
	}

	serverOptions := []HandlerOption{}
	if cfg.ScopeChallenge {
		scopeFetcher := scopes.NewFetcher(apiHost, scopes.FetcherOptions{})
		serverOptions = append(serverOptions, WithScopeFetcher(scopeFetcher))
	}

	r := chi.NewRouter()
	handler := NewHTTPMcpHandler(ctx, &cfg, deps, t, logger, apiHost, append(serverOptions, WithFeatureChecker(featureChecker), WithOAuthConfig(oauthCfg))...)
	oauthHandler, err := oauth.NewAuthHandler(oauthCfg, apiHost)
	if err != nil {
		return fmt.Errorf("failed to create OAuth handler: %w", err)
	}

	r.Group(func(r chi.Router) {
		r.Use(middleware.SetCorsHeaders)

		// Register Middleware First, needs to be before route registration
		handler.RegisterMiddleware(r)

		// Register MCP server routes
		handler.RegisterRoutes(r)
	})
	logger.Info("MCP endpoints registered", "baseURL", cfg.BaseURL)

	r.Group(func(r chi.Router) {
		// Register OAuth protected resource metadata endpoints
		oauthHandler.RegisterRoutes(r)
	})
	logger.Info("OAuth protected resource endpoints registered", "baseURL", cfg.BaseURL)

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Reuse the apiHost resolved early in RunHTTPServer (as the current code does) instead of nil
  2. Keep NewAuthHandler's default host constant a valid URL
  3. Add a startup test that constructs the OAuth handler with the production config
Defensive patterns

Strategy: validation

Validate before calling

if apiHost == nil {
	return fmt.Errorf("cannot create OAuth handler without an API host resolver")
}
oauthHandler, err := oauth.NewAuthHandler(oauthCfg, apiHost)

Prevention

When it happens

Trigger: A fork or refactor changes NewAuthHandler to validate the passed resolver and the resolver construction fails; passing a nil apiHost in a build where the default constant is invalid.

Common situations: Custom deployments altering OAuth handler construction; refactor drift between the server and the oauth package.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/68cffc2ca86795f0. Report an issue: GitHub.