googleapis/mcp-toolbox · error
error parsing base URL: %s
Error message
error parsing base URL: %s
What it means
getURL parses the source's HttpBaseURL() with net/url.Parse before resolving the relative path. If the base URL string is not a parseable URL, the parse error is wrapped as "error parsing base URL" and Invoke fails with an agent error.
Source
Thrown at internal/tools/http/http.go:191
return ""
}
return url.QueryEscape(fmt.Sprintf("%v", v))
},
}
templ, err := template.New("url").Funcs(funcMap).Parse(path)
if err != nil {
return "", fmt.Errorf("error parsing URL: %s", err)
}
var templatedPath bytes.Buffer
err = templ.Execute(&templatedPath, pathParamsMap)
if err != nil {
return "", fmt.Errorf("error replacing pathParams: %s", err)
}
baseParsedURL, err := url.Parse(baseURL)
if err != nil {
return "", fmt.Errorf("error parsing base URL: %s", err)
}
if baseParsedURL.Scheme == "" || baseParsedURL.Host == "" {
return "", fmt.Errorf("base URL must include scheme and host")
}
relativePath := templatedPath.String()
relParsedURL, err := url.Parse(relativePath)
if err != nil {
return "", fmt.Errorf("error parsing URL path: %s", err)
}
if relParsedURL.Scheme != "" || relParsedURL.Host != "" || relParsedURL.User != nil {
return "", fmt.Errorf("path must be relative and cannot override base host")
}
// Reject dot segments before resolution
for _, segment := range strings.Split(relParsedURL.Path, "/") {
if segment == ".." {
return "", fmt.Errorf("path cannot contain dot segments (..)")View on GitHub (pinned to 8cc6e09de2)
Solutions
- Fix the source's "baseUrl" in tools.yaml so it is a valid absolute URL.
- Check the environment variable or secret substituted into baseUrl for stray spaces/quotes.
- Add a startup validation that url.Parse succeeds on every http source's baseUrl before serving.
Example fix
# before baseUrl: "http://api.example.com/%zz" # after baseUrl: "https://api.example.com"
Defensive patterns
Strategy: validation
Validate before calling
// Validate baseUrl when defining the source
if _, err := url.Parse(strings.TrimSpace(os.Getenv("API_BASE_URL"))); err != nil {
return fmt.Errorf("invalid API_BASE_URL: %w", err)
} Try / catch
urlString, err := getURL(baseURL, path, pathParams, queryParams, defaultQuery, paramsMap)
if err != nil {
if strings.HasPrefix(err.Error(), "error parsing base URL") {
return nil, fmt.Errorf("source baseUrl %q is not a valid URL: %w", baseURL, err)
}
return nil, err
} Prevention
- Quote baseUrl values in YAML and trim env-var substitutions
- Avoid characters needing percent-encoding (spaces, control chars) in baseUrl
- Validate baseUrl parses at source initialization to fail at startup
When it happens
Trigger: The http source's baseUrl config value is malformed — contains spaces, control characters, or invalid percent-encodings like "http://api.example.com/%zz" — causing url.Parse to fail during Invoke.
Common situations: Env-var-substituted base URLs with stray whitespace or quotes; truncated URLs in YAML; invalid percent-encoding after string interpolation.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- base URL must include scheme and host
- invalid auth URL
- error creating request: %w
- failed to create request: %w
- description is required for tool %q
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/a231438c708e51c4.
Report an issue: GitHub.