googleapis/mcp-toolbox · error

error parsing markdown template: %w

Error message

error parsing markdown template: %w

What it means

`generateSkillMarkdown` throws "error parsing markdown template: %w" when Go's `text/template` cannot parse the embedded `skillTemplate` string (`template.New("markdown").Parse(skillTemplate)` fails). Because the template is compiled into the binary, this almost always indicates a bug in the shipped template text (e.g. malformed `{{...}}` actions) rather than anything the user configured. The wrapped error from text/template names the line and syntax problem.

Source

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

		}

		toolsData = append(toolsData, toolTemplateData{
			Name:             name,
			Description:      manifest.Description,
			ParametersSchema: parametersSchema,
		})
	}

	data := skillTemplateData{
		SkillName:        skillName,
		SkillDescription: skillDescription,
		AdditionalNotes:  additionalNotes,
		Tools:            toolsData,
	}

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

	var buf strings.Builder
	if err := tmpl.Execute(&buf, data); err != nil {
		return "", fmt.Errorf("error executing markdown template: %w", err)
	}

	return buf.String(), nil
}

const nodeScriptTemplate = `#!/usr/bin/env node
{{if .LicenseHeader}}
{{.LicenseHeader}}
{{end}}
const { spawn, execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped text/template error — it pinpoints the offending line/column in the template
  2. Check `skillTemplate` in cmd/internal/skills/generator.go for unbalanced `{{ }}`, bad pipelines, or undefined functions
  3. Rebuild the binary so the embedded template matches the source (`go build -o toolbox`)
  4. If customizing, test the template with `TestGenerateSkillMarkdown` before shipping

Example fix

// before: malformed action in skillTemplate
// {{ if .Tools }}...{{ end
// after: closed action
// {{ if .Tools }}...{{ end }}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate template syntax at startup/test time
func validateTemplate(t string) error {
	_, err := template.New("markdown").Parse(t)
	return err
}
// call in an init() or unit test so bad templates fail fast

Try / catch

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

Prevention

When it happens

Trigger: Calling `generateSkillMarkdown` (via `run` or the unit test `TestGenerateSkillMarkdown`) with a `skillTemplate` containing invalid template syntax such as unbalanced `{{`/`}}`, unknown functions, or an unterminated action.

Common situations: A developer edited the embedded `skillTemplate` constant in `cmd/internal/skills/generator.go` and introduced a syntax error; a custom template passed through a fork/patch is malformed; Go version differences in template parsing behavior.

Related errors


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