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
- Reuse the apiHost resolved early in RunHTTPServer (as the current code does) instead of nil
- Keep NewAuthHandler's default host constant a valid URL
- 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
- Construct the apiHost once at startup and pass it everywhere
- Smoke-test OAuth handler construction with production config in CI
- Keep default host constants valid absolute URLs
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
- starting callback listener on %s: %w
- OAuth callback port %d is not available; another process may
- authentication required: set GITHUB_PERSONAL_ACCESS_TOKEN, c
- failed to unmarshal toolsets: %w
- failed to unmarshal tools: %w
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/68cffc2ca86795f0.
Report an issue: GitHub.