{"record":{"id":"afd08a084cae38e7","repo":"googleapis/mcp-toolbox","slug":"error-replacing-pathparams-s","errorCode":null,"errorMessage":"error replacing pathParams: %s","messagePattern":"error replacing pathParams: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/http/http.go","lineNumber":186,"sourceCode":"\t\t\"queryEscape\": func(v any) string {\n\t\t\tif s, ok := v.(string); ok {\n\t\t\t\treturn url.QueryEscape(s)\n\t\t\t}\n\t\t\tif v == nil {\n\t\t\t\treturn \"\"\n\t\t\t}\n\t\t\treturn url.QueryEscape(fmt.Sprintf(\"%v\", v))\n\t\t},\n\t}\n\n\ttempl, err := template.New(\"url\").Funcs(funcMap).Parse(path)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error parsing URL: %s\", err)\n\t}\n\tvar templatedPath bytes.Buffer\n\terr = templ.Execute(&templatedPath, pathParamsMap)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error replacing pathParams: %s\", err)\n\t}\n\n\tbaseParsedURL, err := url.Parse(baseURL)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error parsing base URL: %s\", err)\n\t}\n\tif baseParsedURL.Scheme == \"\" || baseParsedURL.Host == \"\" {\n\t\treturn \"\", fmt.Errorf(\"base URL must include scheme and host\")\n\t}\n\n\trelativePath := templatedPath.String()\n\trelParsedURL, err := url.Parse(relativePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error parsing URL path: %s\", err)\n\t}\n\tif relParsedURL.Scheme != \"\" || relParsedURL.Host != \"\" || relParsedURL.User != nil {\n\t\treturn \"\", fmt.Errorf(\"path must be relative and cannot override base host\")\n\t}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/http/http.go#L168-L204","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npath: \"/users/{{.userId}}\" // pathParams declares \"id\"\n// after\npath: \"/users/{{.id}}\"","handlingStrategy":"validation","validationCode":"// Ensure every template reference in path has a matching pathParam\nfor _, name := range extractTemplateRefs(tool.Path) {\n    if !pathParams.Contains(name) {\n        return fmt.Errorf(\"path references %q which is not declared in pathParams\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":"urlString, err := getURL(baseURL, path, pathParams, queryParams, defaultQuery, paramsMap)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"error replacing pathParams\") {\n        return nil, fmt.Errorf(\"failed to render path params into %q: %w\", path, err)\n    }\n    return nil, err\n}","preventionTips":["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"],"tags":["go","http","template","url"],"backgroundTag":"url-template-parse-error","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}