googleapis/mcp-toolbox · error
error creating go template %s
Error message
error creating go template %s
What it means
ResolveTemplateParams wraps text/template's Parse failure with this message. The configured statement/URL/message is not syntactically valid Go template syntax — typically unbalanced braces or invalid template tokens. This fails before any parameter values are substituted.
Source
Thrown at internal/util/parameters/parameters.go:291
}
resultParamValues = append(resultParamValues, ParamValue{Name: k, Value: v})
}
return resultParamValues, nil
}
func ResolveTemplateParams(templateParams Parameters, originalStatement string, paramsMap map[string]any) (string, error) {
templateParamsValues, err := GetParams(templateParams, paramsMap)
templateParamsMap := templateParamsValues.AsMap()
if err != nil {
return "", fmt.Errorf("error getting template params %s", err)
}
funcMap := template.FuncMap{
"array": ConvertArrayParamToString,
}
t, err := template.New("statement").Funcs(funcMap).Parse(originalStatement)
if err != nil {
return "", fmt.Errorf("error creating go template %s", err)
}
var result bytes.Buffer
err = t.Execute(&result, templateParamsMap)
if err != nil {
return "", fmt.Errorf("error executing go template %s", err)
}
modifiedStatement := result.String()
return modifiedStatement, nil
}
// ProcessParameters concatenate templateParameters and parameters from a tool.
// It returns a list of concatenated parameters, concatenated Toolbox manifest, and concatenated MCP Manifest.
func ProcessParameters(templateParams Parameters, params Parameters) (Parameters, []ParameterManifest, error) {
allParameters := slices.Concat(params, templateParams)
// verify no duplicate parameter names
err := CheckDuplicateParameters(allParameters)View on GitHub (pinned to 8cc6e09de2)
Solutions
- Locate the {{...}} expression cited in the wrapped error and balance/fix the braces.
- Use only Go template syntax: {{.paramName}} and the provided {{array .paramName}} helper.
- Escape or remove literal {{ sequences in the statement that weren't meant as templates.
- Validate the statement offline with template.New("statement").Parse before deploying the config.
Example fix
# before (Jinja-style, invalid in Go)
SELECT * FROM t LIMIT {{ limit }}
# after (Go template syntax)
SELECT * FROM t LIMIT {{.limit}} Defensive patterns
Strategy: validation
Validate before calling
if _, err := template.New("s").Funcs(template.FuncMap{"array": params.ConvertArrayParamToString}).Parse(stmt); err != nil {
return fmt.Errorf("invalid template in statement: %w", err)
} Try / catch
out, err := params.ResolveTemplateParams(tp, stmt, m)
if err != nil && strings.Contains(err.Error(), "error creating go template") {
return fmt.Errorf("statement has invalid Go template syntax: %w", err)
} Prevention
- Parse-validate every statement in CI before deploying configs.
- Use Go template syntax only — no Jinja/Handlebars constructs.
- Escape literal braces in SQL/URLs that shouldn't be templated.
- Keep a lint rule or test that runs Parse over all configured statements.
When it happens
Trigger: A configured statement containing malformed template syntax: unclosed {{, stray braces, invalid pipeline syntax, or syntax from other template languages (Jinja/Handlebars) that Go's parser rejects.
Common situations: Hand-edited SQL or YAML introducing literal {{; copying templates from non-Go docs; leftover {{ limit }} style syntax from Jinja; accidental use of undefined helper names at parse time.
Related errors
- error substituting params for message: %w
- error parsing template '%s': %w
- error executing go template %s
- error embedding parameters: %w
- failed to check auth requirements: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/a7d6a5ea765f21f6.
Report an issue: GitHub.