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

  1. Pass an explicit apiHost resolver to NewAuthHandler instead of relying on the default
  2. Keep any customized default an absolute https URL
  3. 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

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


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