googleapis/mcp-toolbox · error

failed to parse BaseUrl %v

Error message

failed to parse BaseUrl %v

What it means

This error occurs when url.ParseRequestURI rejects the configured BaseUrl for the HTTP source. ParseRequestURI is stricter than url.Parse: it requires an absolute URI (scheme + host) for this usage, so values like "example.com/api", "/api", or strings with spaces/illegal characters fail. The source cannot make any request without a valid base URL.

Source

Thrown at internal/sources/http/http.go:117

	}

	logger, err := util.LoggerFromContext(ctx)
	if err != nil {
		return nil, fmt.Errorf("unable to get logger from ctx: %s", err)
	}

	if r.DisableSslVerification {
		tr.TLSClientConfig = &tls.Config{
			InsecureSkipVerify: true,
		}

		logger.WarnContext(ctx, "WARNING: TLS certificate verification is skipped (InsecureSkipVerify: true) for HTTP source %s. This exposes all traffic for this source to Man-in-the-Middle (MITM) attacks. Do not use in production.", r.Name)
	}

	// Validate BaseURL
	parsedURL, err := url.ParseRequestURI(r.BaseURL)
	if err != nil {
		return nil, fmt.Errorf("failed to parse BaseUrl %v", err)
	}

	allowedRanges, err := parseCIDRs(r.AllowedIPRanges)
	if err != nil {
		return nil, fmt.Errorf("invalid allowedIpRanges: %w", err)
	}

	customBlocked, err := parseCIDRs(r.CustomBlockedIPRanges)
	if err != nil {
		return nil, fmt.Errorf("invalid customBlockedIpRanges: %w", err)
	}

	guard := &SSRFGuard{
		AllowPrivateNetworks: r.AllowPrivateNetworks,
		AllowedRanges:        allowedRanges,
		CustomBlocked:        customBlocked,
	}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Include the scheme: use "https://api.example.com" not "api.example.com"
  2. Trim whitespace and stray quotes from the configured value
  3. Verify the full BaseUrl with a quick curl or by parsing it in a scratch Go snippet using url.ParseRequestURI to confirm it passes

Example fix

// before
baseUrl: api.example.com/v1
// after
baseUrl: https://api.example.com/v1
Defensive patterns

Strategy: validation

Validate before calling

func validBaseURL(s string) bool {
    u, err := url.ParseRequestURI(strings.TrimSpace(s))
    return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
}

Try / catch

src, err := cfg.Initialize(ctx, tracer)
if err != nil && strings.Contains(err.Error(), "failed to parse BaseUrl") {
    log.Fatalf("BaseUrl must be an absolute URI with scheme, e.g. https://host: %v", err)
}

Prevention

When it happens

Trigger: url.ParseRequestURI(r.BaseURL) returns non-nil err during Initialize: BaseUrl missing the scheme ("myhost.com" instead of "https://myhost.com"), empty string, relative path, embedded spaces, or otherwise malformed URI.

Common situations: Omitting https:// from the configured URL; trailing config typos; pasting a URL with surrounding whitespace/quotes; using a path-only value for internal services.

Understand the failure class

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/d44309dba4722091. Report an issue: GitHub.