googleapis/mcp-toolbox · error

error parsing URL: %s

Error message

error parsing URL: %s

What it means

The tool's "path" is treated as a Go text/template that is rendered with path params before being joined to the source's base URL. This error wraps any template.Parse failure, meaning the path string is not syntactically valid template syntax.

Source

Thrown at internal/tools/http/http.go:181

			if v == nil {
				return ""
			}
			return url.PathEscape(fmt.Sprintf("%v", v))
		},
		"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 {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Fix the template syntax in the tool's "path" field (close all {{ }} actions).
  2. Escape literal braces in the path (use {{"{"}} or avoid braces entirely).
  3. If path values come from users, validate/reject unescaped template delimiters before Invoke.

Example fix

// before
path: "/users/{{.id"
// after
path: "/users/{{.id}}"
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the path template parses before configuring the tool
_, err := template.New("url").Parse(toolPath)
if err != nil {
    return fmt.Errorf("invalid path template %q: %w", toolPath, err)
}

Try / catch

urlString, err := getURL(baseURL, path, pathParams, queryParams, defaultQuery, paramsMap)
if err != nil {
    if strings.HasPrefix(err.Error(), "error parsing URL") {
        return nil, fmt.Errorf("malformed path template %q: %w", path, err)
    }
    return nil, err
}

Prevention

When it happens

Trigger: A path value contains malformed template syntax, e.g. an unclosed {{ or an invalid pipeline such as "/users/{{.id" or "/items/{{if}}", passed to getURL during Invoke.

Common situations: Paths containing literal braces that weren't intended as templates (JSON snippets pasted into path); forgetting to escape "{{" as a literal; typos in template actions; user-supplied path values with special characters.

Related errors


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