googleapis/mcp-toolbox · error
error replacing pathParams: %s
Error message
error replacing pathParams: %s
What it means
After parsing the path template, getURL executes it against the resolved path-param values; if templ.Execute fails (e.g., the template references a missing map key with a raising option or an action returns an error), the failure is wrapped as this error during Invoke.
Source
Thrown at internal/tools/http/http.go:186
"queryEscape": func(v any) string {
if s, ok := v.(string); ok {
return url.QueryEscape(s)
}
if v == nil {
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")
}View on GitHub (pinned to 8cc6e09de2)
Solutions
- Verify every {{.name}} reference in the tool's path matches a declared pathParams entry exactly (case-sensitive).
- Make required path params non-nil and correctly typed before invocation.
- Guard templates with {{if}} or default handling ({{.x | default}}) for optional values.
Example fix
// before
path: "/users/{{.userId}}" // pathParams declares "id"
// after
path: "/users/{{.id}}" Defensive patterns
Strategy: validation
Validate before calling
// Ensure every template reference in path has a matching pathParam
for _, name := range extractTemplateRefs(tool.Path) {
if !pathParams.Contains(name) {
return fmt.Errorf("path references %q which is not declared in pathParams", name)
}
} Try / catch
urlString, err := getURL(baseURL, path, pathParams, queryParams, defaultQuery, paramsMap)
if err != nil {
if strings.HasPrefix(err.Error(), "error replacing pathParams") {
return nil, fmt.Errorf("failed to render path params into %q: %w", path, err)
}
return nil, err
} Prevention
- Match {{.name}} references exactly to declared pathParams names (case-sensitive)
- Use {{if}} guards or defaults for possibly-missing values
- Test the tool invocation with all path params supplied before exposing it
When it happens
Trigger: The path template calls a function or accesses data that fails at execution time — e.g., {{.missing | pathEscape}} on a nil/absent path param value, or a custom func invoked with invalid input — during Invoke of an http tool.
Common situations: Path declared in "pathParams" but the LLM supplied a wrong-typed value; template referencing a param name that doesn't exist in pathParams; nil values flowing into pathEscape.
Related errors
- error parsing URL: %s
- error parsing URL path: %s
- failed to create request: %w
- error parsing base URL: %s
- base URL must include scheme and host
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/afd08a084cae38e7.
Report an issue: GitHub.