github/github-mcp-server · error

failed to classify API host: %w

Error message

failed to classify API host: %w

What it means

utils.ParseHostType could not classify cfg.Host as dotcom, GHEC, or GHES. It errors only when url.Parse fails or the parsed URL has an empty scheme - i.e. the host string is not an absolute http(s) URL.

Source

Thrown at pkg/http/server.go:134

		if err != nil {
			return fmt.Errorf("failed to open log file: %w", err)
		}
		logOutput = file
		slogHandler = slog.NewTextHandler(logOutput, &slog.HandlerOptions{Level: slog.LevelDebug})
	} else {
		logOutput = os.Stderr
		slogHandler = slog.NewTextHandler(logOutput, &slog.HandlerOptions{Level: slog.LevelInfo})
	}
	logger := slog.New(slogHandler)
	logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "lockdownEnabled", cfg.LockdownMode, "readOnly", cfg.ReadOnly, "insidersMode", cfg.InsidersMode)

	apiHost, err := utils.NewAPIHost(cfg.Host)
	if err != nil {
		return fmt.Errorf("failed to parse API host: %w", err)
	}
	hostType, err := utils.ParseHostType(cfg.Host)
	if err != nil {
		return fmt.Errorf("failed to classify API host: %w", err)
	}

	repoAccessOpts := []lockdown.RepoAccessOption{
		lockdown.WithLogger(logger.With("component", "lockdown")),
	}
	if cfg.RepoAccessCacheTTL != nil {
		repoAccessOpts = append(repoAccessOpts, lockdown.WithTTL(*cfg.RepoAccessCacheTTL))
	}

	featureChecker := createHTTPFeatureChecker(cfg.EnabledFeatures, cfg.InsidersMode)

	obs, err := observability.NewExporters(logger, metrics.NewNoopMetrics())
	if err != nil {
		return fmt.Errorf("failed to create observability exporters: %w", err)
	}

	deps := github.NewRequestDeps(
		apiHost,

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. Prefix the host with https:// (or http:// for local testing)
  2. Verify the env/flag value for the host is an absolute URL with no surrounding whitespace or quotes
  3. Add a startup config check that runs ParseHostType before the server boots

Example fix

// before
cfg.Host = os.Getenv("GH_HOST") // "github.corp.example"

// after
cfg.Host = url.PathEscape(os.Getenv("GH_HOST"))
if !strings.Contains(cfg.Host, "://") {
	cfg.Host = "https://" + cfg.Host
}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := utils.ParseHostType(cfg.Host); err != nil {
	// normalize before boot: default to dotcom or prefix a scheme
	if cfg.Host == "" {
		cfg.Host = "https://api.github.com"
	} else if !strings.Contains(cfg.Host, "://") {
		cfg.Host = "https://" + cfg.Host
	}
}

Prevention

When it happens

Trigger: Host string without a scheme ('api.github.com.', 'github.corp'); unparseable URL syntax; host taken from an env var that includes quotes or spaces.

Common situations: GHES deployments configured with a bare hostname; config templating that strips or mangles the scheme; the same misconfigurations that trigger the NewAPIHost failure one line above.

Related errors


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