googleapis/mcp-toolbox · error
error executing script template: %w
Error message
error executing script template: %w
What it means
`generateScriptContent` throws "error executing script template: %w" when the parsed `nodeScriptTemplate` fails during `tmpl.Execute(&buf, data)` while rendering the Node wrapper script with the tool data (name, parameters, toolbox version, optional vars). Parse succeeded; rendering against the provided `data` struct failed, typically because a template action dereferences a missing/nil value or a method returns an error.
Source
Thrown at cmd/internal/skills/generator.go:273
// (using a generated config) and arguments to execute the specific tool.
func generateScriptContent(name string, configArgs string, licenseHeader string, mode string, version string, optionalVars []string) (string, error) {
data := scriptData{
Name: name,
ConfigArgs: configArgs,
LicenseHeader: licenseHeader,
InvocationMode: mode,
ToolboxVersion: version,
OptionalVars: optionalVars,
}
tmpl, err := template.New("script").Parse(nodeScriptTemplate)
if err != nil {
return "", fmt.Errorf("error parsing script template: %w", err)
}
var buf strings.Builder
if err := tmpl.Execute(&buf, data); err != nil {
return "", fmt.Errorf("error executing script template: %w", err)
}
return buf.String(), nil
}
// formatParameters converts a list of parameter manifests into a formatted JSON schema string.
// This schema is used in the skill documentation to describe the input parameters for a tool.
func formatParameters(params []parameters.ParameterManifest, envVars map[string]string) (string, error) {
if len(params) == 0 {
return "", nil
}
var sb strings.Builder
sb.WriteString("#### Parameters\n\n")
sb.WriteString("| Name | Type | Description | Required | Default |\n")
sb.WriteString("| :--- | :--- | :--- | :--- | :--- |\n")
for _, p := range params {View on GitHub (pinned to 8cc6e09de2)
Solutions
- Read the wrapped execution error — it names the failing template node and line
- Verify every field referenced in `nodeScriptTemplate` exists on the script data struct and is non-nil where used
- Add `{{ if }}` guards around optional fields (optionalVars, parameters) in the template
- Reproduce with the failing tool's manifest in a unit test for generateScriptContent
Example fix
// before (template): {{ range .OptionalVars }}{{ . }}{{ end }} on nil slice
// after (template): {{ if .OptionalVars }}{{ range .OptionalVars }}{{ . }}{{ end }}{{ end }} Defensive patterns
Strategy: try-catch
Validate before calling
// Normalize inputs before rendering
if optionalVars == nil { optionalVars = map[string]string{} }
if params == nil { params = []map[string]any{} } Try / catch
var buf strings.Builder
if err := tmpl.Execute(&buf, data); err != nil {
return "", fmt.Errorf("error executing script template: %w", err)
} Prevention
- Guard optional fields (optionalVars, parameters) with `{{ if }}` in the template
- Keep nodeScriptTemplate field references aligned with the data struct definition
- Test generateScriptContent with manifests missing optional fields
- Inspect the wrapped error's template line to locate the failing action
When it happens
Trigger: `tmpl.Execute(&buf, data)` is called with the script data struct and a field/method used in `nodeScriptTemplate` fails — e.g. ranging over a nil parameters slice, calling a method that returns an error, or a field renamed in the data struct that the template still references.
Common situations: A tool manifest with nil/empty parameters fed into the template after a refactor changed the data struct fields; template actions reference fields removed from the script data struct; version/optionalVars fields unset where the template assumes values.
Related errors
- error parsing script template: %w
- error parsing markdown template: %w
- error executing markdown template: %w
- error parsing URL: %s
- error replacing pathParams: %s
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/b00bffebb399b916.
Report an issue: GitHub.