googleapis/mcp-toolbox · error

invalid value for maxDelay: %w

Error message

invalid value for maxDelay: %w

What it means

Initialize() parses the tool's optional maxDelay config field with time.ParseDuration. When the string cannot be parsed as a Go duration (e.g. "5", "5m30", "five minutes"), the parse error is wrapped and initialization of the alloydb-wait-for-operation tool fails immediately at config-load time.

Source

Thrown at internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation.go:142

	var delay time.Duration
	if cfg.Delay == "" {
		delay = 3 * time.Second
	} else {
		var err error
		delay, err = time.ParseDuration(cfg.Delay)
		if err != nil {
			return nil, fmt.Errorf("invalid value for delay: %w", err)
		}
	}

	var maxDelay time.Duration
	if cfg.MaxDelay == "" {
		maxDelay = 4 * time.Minute
	} else {
		var err error
		maxDelay, err = time.ParseDuration(cfg.MaxDelay)
		if err != nil {
			return nil, fmt.Errorf("invalid value for maxDelay: %w", err)
		}
	}

	multiplier := cfg.Multiplier
	if multiplier == 0 {
		multiplier = 2.0
	}

	maxRetries := cfg.MaxRetries
	if maxRetries == 0 {
		maxRetries = 10
	}

	params := buildParams("")
	return Tool{
		BaseTool: tools.NewBaseTool(
			cfg,
			tools.GetAnnotationsOrDefault(cfg.Annotations, tools.NewReadOnlyAnnotations),

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Fix maxDelay in the tool config to a valid Go duration string with a unit, e.g. "5m" or "4m".
  2. Remove the maxDelay field entirely to use the default of 4 minutes.
  3. Validate the value locally with time.ParseDuration before writing it into the config to get a clearer message.

Example fix

// before (invalid)
maxDelay: 300
// after
maxDelay: 300s
Defensive patterns

Strategy: validation

Validate before calling

if cfg.MaxDelay != "" {
    if _, err := time.ParseDuration(cfg.MaxDelay); err != nil {
        return fmt.Errorf("maxDelay %q is not a valid duration: %w", cfg.MaxDelay, err)
    }
}

Try / catch

_, err := toolConfig.Initialize(ctx)
if err != nil {
    var cfgErr error
    if errors.As(err, &cfgErr) && strings.Contains(err.Error(), "invalid value for maxDelay") {
        // fall back to default (omit maxDelay) and re-init
    }
}

Prevention

When it happens

Trigger: Calling Initialize() on an alloydb-wait-for-operation Config whose MaxDelay is non-empty and not a valid Go duration string (valid: "30s", "5m", "1h", "500ms"; invalid: "5", "5 minutes", "", missing unit).

Common situations: YAML configs where maxDelay is written as a bare number ("maxDelay: 300") instead of a duration string, typos like "5mintues", or quoting/whitespace issues in the YAML that leave stray characters in the value.

Understand the failure class

Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.

Related errors


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