googleapis/mcp-toolbox · error
unable to parse Timeout string as time.Duration: %s
Error message
unable to parse Timeout string as time.Duration: %s
What it means
This error comes from the HTTP source's Initialize when time.ParseDuration cannot parse the configured Timeout string into a valid time.Duration. The Timeout field must be a Go duration string such as "30s", "5m", or "1h30m". A missing unit (e.g. "30") or garbage text makes parsing fail and the source aborts initialization.
Source
Thrown at internal/sources/http/http.go:91
Timeout string `yaml:"timeout"`
DefaultHeaders map[string]string `yaml:"headers"`
QueryParams map[string]string `yaml:"queryParams"`
ReturnFullError bool `yaml:"returnFullError"`
DisableSslVerification bool `yaml:"disableSslVerification"`
AllowedIPRanges []string `yaml:"allowedIpRanges"`
CustomBlockedIPRanges []string `yaml:"customBlockedIpRanges"`
AllowPrivateNetworks bool `yaml:"allowPrivateNetworks"`
}
func (r Config) SourceConfigType() string {
return SourceType
}
// Initialize initializes an HTTP Source instance.
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
duration, err := time.ParseDuration(r.Timeout)
if err != nil {
return nil, fmt.Errorf("unable to parse Timeout string as time.Duration: %s", err)
}
var tr *http.Transport
if defaultTr, ok := http.DefaultTransport.(*http.Transport); ok {
tr = defaultTr.Clone()
} else {
tr = &http.Transport{}
}
logger, err := util.LoggerFromContext(ctx)
if err != nil {
return nil, fmt.Errorf("unable to get logger from ctx: %s", err)
}
if r.DisableSslVerification {
tr.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}View on GitHub (pinned to 8cc6e09de2)
Solutions
- Set Timeout to a valid Go duration string, e.g. "30s" or "2m"
- Remember the unit is mandatory: use "500ms" not "500"
- Check the YAML config for the http source's `timeout:` key — remove quotes-irrelevant typos and stray characters
Example fix
// before timeout: 30 // after timeout: 30s
Defensive patterns
Strategy: validation
Validate before calling
func validTimeout(s string) bool {
_, err := time.ParseDuration(s)
return err == nil
}
// usage: if !validTimeout(cfg.Timeout) { fix config before Initialize } Try / catch
src, err := cfg.Initialize(ctx, tracer)
if err != nil && strings.Contains(err.Error(), "unable to parse Timeout") {
log.Fatalf("bad timeout format in http source config: %v", err)
} Prevention
- Always include units in durations: "30s", "5m", "500ms"
- Never use bare integers in the timeout field
- Add a config pre-check with time.ParseDuration in CI/startup scripts
When it happens
Trigger: Config.Initialize calls time.ParseDuration(r.Timeout) and gets an error: Timeout set to "30" (no unit), "seconds", "", "thirty seconds", or any string outside Go's duration syntax.
Common situations: Copy-pasting a plain integer timeout from another tool's config; forgetting units like "ms" vs "s"; empty Timeout field in YAML; assuming the value is seconds by default.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse BaseUrl %v
- invalid allowedIpRanges: %w
- invalid queryTimeout %q: %w
- %s is not a valid http method
- `introspectionEndpoint` is not allowed when `mcpEnabled` is
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/c3172a5383320239.
Report an issue: GitHub.