github/github-mcp-server · error
could not parse host as URL: %s
Error message
could not parse host as URL: %s
What it means
parseAPIHost feeds the configured host string (empty means github.com) to url.Parse and this is the raw parse failure. It only fires on syntactically broken URLs - control characters, spaces, or invalid percent-encoding - because almost any hostname-shaped string parses fine and fails the later scheme checks instead.
Source
Thrown at pkg/utils/api.go:239
resp, err := client.Get(subdomainURL)
if err != nil {
return false
}
defer resp.Body.Close()
return resp.StatusCode == http.StatusOK
}
// Note that this does not handle ports yet, so development environments are out.
func parseAPIHost(s string) (APIHost, error) {
if s == "" {
return newDotcomHost()
}
u, err := url.Parse(s)
if err != nil {
return APIHost{}, fmt.Errorf("could not parse host as URL: %s", s)
}
if u.Scheme == "" {
return APIHost{}, fmt.Errorf("host must have a scheme (http or https): %s", s)
}
// Enforce HTTPS centrally so no deployment (GHES in particular) can build
// authenticated REST/GraphQL/upload/raw URLs over cleartext http, which
// would leak the bearer token/PAT to anyone on the network.
if err := requireSecureScheme(u); err != nil {
return APIHost{}, err
}
switch classifyHost(u) {
case HostTypeDotcom:
return newDotcomHost()
case HostTypeGHEC:
return newGHECHost(s)View on GitHub (pinned to 0ea1f775a7)
Solutions
- Trim whitespace and newlines from the env value before use
- Re-enter the value without stray characters and confirm it starts with https://
- Log the exact (non-secret) host value at startup to spot invisible characters
Example fix
# before (trailing space from env_file) GITHUB_HOST='https://github.example.com ' # after GITHUB_HOST=https://github.example.com
Defensive patterns
Strategy: validation
Validate before calling
func validAPIHost(s string) error {
s = strings.TrimSpace(s)
if s == "" {
return nil // dotcom default
}
u, err := url.Parse(s)
if err != nil {
return fmt.Errorf("unparseable host %q: %w", s, err)
}
if u.Scheme == "" {
return fmt.Errorf("host %q must include an https:// scheme", s)
}
return nil
} Prevention
- Trim env-sourced host strings before use
- Validate GITHUB_HOST once at process start and fail fast showing the offending value (it is non-secret)
- Quote values in env_file/compose files to avoid stray whitespace
When it happens
Trigger: GITHUB_HOST / --github-host containing a space ('https://github. example.com'), a trailing newline from a docker env_file or Kubernetes secret, or stray control characters.
Common situations: env_file entries with trailing whitespace; k8s secrets storing values with a trailing \n; shell quoting mistakes injecting spaces.
Related errors
- creating installation token request: %w
- unknown tools specified in WithTools: %s
- host must have a scheme (http or https): %s
- GitHub App authentication and OAuth login (--oauth-client-id
- GitHub App installation ID is required (GITHUB_APP_INSTALLAT
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/6aa665042d548ebd.
Report an issue: GitHub.