googleapis/mcp-toolbox · error

error parsing script template: %w

Error message

error parsing script template: %w

What it means

`generateScriptContent` throws "error parsing script template: %w" when `template.New("script").Parse(nodeScriptTemplate)` fails for the embedded Node.js wrapper script template. Like the markdown template error, the template text is embedded in the binary, so this indicates a syntax error in the shipped `nodeScriptTemplate` constant (malformed Go template actions) rather than user configuration. The wrapped text/template error identifies the exact syntax problem.

Source

Thrown at cmd/internal/skills/generator.go:268

	OptionalVars   []string
}

// generateScriptContent creates the content for a Node.js wrapper script.
// This script invokes the toolbox CLI with the appropriate configuration
// (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

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped error — it gives the line/column of the bad template action
  2. Inspect `nodeScriptTemplate` in cmd/internal/skills/generator.go for unbalanced `{{ }}` or raw `{`/`}` conflicts with template actions (use `{{"{"}}` or backtick-safe literals)
  3. Rebuild with `go build -o toolbox` so the embedded template matches source
  4. Add/keep a unit test covering generateScriptContent to catch template syntax regressions

Example fix

// before: raw JS object literal inside a template action confuses parsing
// const cfg = {{ .Config };
// after: valid action with proper braces
// const cfg = {{ .Config }};
Defensive patterns

Strategy: try-catch

Validate before calling

// Fail fast on template syntax in tests/init
func validateScriptTemplate(t string) error {
	_, err := template.New("script").Parse(t)
	return err
}

Try / catch

tmpl, err := template.New("script").Parse(nodeScriptTemplate)
if err != nil {
	return "", fmt.Errorf("error parsing script template: %w", err)
}

Prevention

When it happens

Trigger: Calling `generateScriptContent` (via `run` or an anonymous test helper) with a `nodeScriptTemplate` containing invalid template syntax: unbalanced `{{`/`}}`, unknown functions, or invalid pipelines — e.g. after someone edited the script template and mixed JavaScript braces with template actions incorrectly.

Common situations: A developer edited the embedded node script (adding JS objects with `{{`-like sequences or template actions) and broke parsing; a fork or patch applied to generator.go corrupted the template string; build artifacts stale relative to source.

Related errors


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