github/github-mcp-server · warning
failed to create default API host: %w
Error message
failed to create default API host: %w
What it means
NewAuthHandler, when called with a nil apiHost resolver, falls back to utils.NewAPIHost("https://api.github.com") and that constant failed URL parsing/normalization. With the shipped constant this path is practically unreachable; it fires in forks or custom builds that change the default host string.
Source
Thrown at pkg/http/oauth/oauth.go:85
}
// AuthHandler handles OAuth-related HTTP endpoints.
type AuthHandler struct {
cfg *Config
apiHost utils.APIHostResolver
}
// NewAuthHandler creates a new OAuth auth handler.
func NewAuthHandler(cfg *Config, apiHost utils.APIHostResolver) (*AuthHandler, error) {
if cfg == nil {
cfg = &Config{}
}
if apiHost == nil {
var err error
apiHost, err = utils.NewAPIHost("https://api.github.com")
if err != nil {
return nil, fmt.Errorf("failed to create default API host: %w", err)
}
}
return &AuthHandler{
cfg: cfg,
apiHost: apiHost,
}, nil
}
// routePatterns defines the route patterns for OAuth protected resource metadata.
var routePatterns = []string{
"", // Root: /.well-known/oauth-protected-resource
"/readonly", // Read-only mode
"/insiders", // Insiders mode
"/x/{toolset}",
"/x/{toolset}/readonly",
}
View on GitHub (pinned to 0ea1f775a7)
Solutions
- Pass an explicit apiHost resolver to NewAuthHandler instead of relying on the default
- Keep any customized default an absolute https URL
- Add a unit test asserting NewAuthHandler with a nil resolver succeeds
Example fix
// before oauthHandler, err := oauth.NewAuthHandler(cfg, nil) // after - reuse the host already parsed and validated at startup oauthHandler, err := oauth.NewAuthHandler(cfg, apiHost)
Defensive patterns
Strategy: validation
Validate before calling
if apiHost == nil {
return nil, fmt.Errorf("apiHost resolver is required; construct one with utils.NewAPIHost first")
}
oauthHandler, err := oauth.NewAuthHandler(cfg, apiHost) Prevention
- Always pass an explicit, pre-validated apiHost resolver
- Never rely on package-level default host constants in forks
- Cover NewAuthHandler construction in startup smoke tests
When it happens
Trigger: Passing nil as apiHost in a build where the default constant was edited to an invalid URL; defensive URL validation rejecting a modified host.
Common situations: Forks pointing the default at an internal gateway with a malformed URL; refactors of the default constant.
Related errors
- authentication required: set GITHUB_PERSONAL_ACCESS_TOKEN, c
- starting callback listener on %s: %w
- OAuth callback port %d is not available; another process may
- exchanging authorization code: %w
- requesting device code: %w
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/13703800bb7b851b.
Report an issue: GitHub.