github/github-mcp-server · error

failed to get base REST URL: %w

Error message

failed to get base REST URL: %w

What it means

RequestDeps.GetClient resolves the REST base URL through its utils.APIHostResolver before building a go-github client. The bundled utils.APIHost parses everything eagerly in NewAPIHost, so its BaseRESTURL never fails; this wrap fires only when a custom APIHostResolver (remote-server variant, proxy, test fake) returns an error or a resolver was wired in without a REST URL. It is a dependency-wiring/configuration error, not an API error.

Source

Thrown at pkg/github/dependencies.go:318

		T:                 t,
		ContentWindowSize: contentWindowSize,
		featureChecker:    featureChecker,
		obsv:              obsv,
	}
}

// GetClient implements ToolDependencies.
func (d *RequestDeps) GetClient(ctx context.Context) (*gogithub.Client, error) {
	// extract the token from the context
	tokenInfo, ok := ghcontext.GetTokenInfo(ctx)
	if !ok {
		return nil, fmt.Errorf("no token info in context")
	}
	token := tokenInfo.Token

	baseRestURL, err := d.apiHosts.BaseRESTURL(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to get base REST URL: %w", err)
	}
	uploadURL, err := d.apiHosts.UploadURL(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to get upload URL: %w", err)
	}

	// Construct REST client
	restClient, err := gogithub.NewClient(
		gogithub.WithAuthToken(token),
		gogithub.WithUserAgent(fmt.Sprintf("github-mcp-server/%s", d.version)),
		gogithub.WithEnterpriseURLs(baseRestURL.String(), uploadURL.String()),
	)
	if err != nil {
		return nil, fmt.Errorf("failed to create REST client: %w", err)
	}
	return restClient, nil
}

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. If you use the standard host config, set GITHUB_HOST to a full URL with scheme (e.g. https://ghe.example.com) and rely on NewAPIHost, which fails fast at startup instead of per request
  2. If you implement APIHostResolver, ensure BaseRESTURL returns a parsed non-nil *url.URL and reserve errors for genuinely unresolvable hosts
  3. Preflight the resolver once at startup (call BaseRESTURL on a background context) and fail process init rather than every tool call
  4. Check the wrapped error chain with errors.Unwrap to see the resolver's own message before debugging go-github

Example fix

// before: resolver that can fail per request
type tenantResolver struct{ host string }
func (t tenantResolver) BaseRESTURL(ctx context.Context) (*url.URL, error) {
	return url.Parse(t.host) // may fail on every GetClient call
}

// after: resolve once, validate at startup
type tenantResolver struct{ rest *url.URL }
func newTenantResolver(host string) (*tenantResolver, error) {
	u, err := url.Parse(host)
	if err != nil || u.Scheme == "" {
		return nil, fmt.Errorf("invalid host %q: must be a URL with scheme", host)
	}
	return &tenantResolver{rest: u}, nil
}
func (t tenantResolver) BaseRESTURL(context.Context) (*url.URL, error) { return t.rest, nil }
Defensive patterns

Strategy: validation

Validate before calling

// startup preflight: fail init, not every tool call
rest, err := apiHosts.BaseRESTURL(context.Background())
if err != nil || rest == nil || !rest.IsAbs() {
	log.Fatalf("invalid API host resolver: REST URL unusable: %v", err)
}

Type guard

func hasValidRESTResolver(a utils.APIHostResolver) bool {
	u, err := a.BaseRESTURL(context.Background())
	return err == nil && u != nil && u.IsAbs() && u.Host != ""
}

Prevention

When it happens

Trigger: Calling deps.GetClient(ctx) when d.apiHosts is a non-standard APIHostResolver whose BaseRESTURL(ctx) errors, e.g. a resolver that derives URLs per-request from tenant headers or one constructed without a parsed REST URL. Never triggers with utils.NewAPIHost output, which validates GITHUB_HOST (scheme present, https except loopback, GHEC https) at startup.

Common situations: Embedding github-mcp-server as a library and passing a homemade APIHostResolver; remote multi-tenant deployments resolving hosts per request; test doubles that return errors; upgrading the resolver interface and forgetting REST URL handling.

Related errors


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