siyuan-note/siyuan · error

path is required

Error message

path is required

What it means

`resolveTemplatePath` requires a non-empty `path` argument; an empty string is rejected immediately because there is no default template to select. Every template tool operation (get, remove, render) needs the caller to name the target template file.

Source

Thrown at kernel/mcp/tools/template.go:92

func templateSearch(args map[string]any) (CallToolResult, error) {
	keyword, _ := args["keyword"].(string)
	results := model.SearchTemplate(keyword)
	if len(results) == 0 {
		return CallToolResult{Content: []ContentItem{{Type: "text", Text: "no templates found"}}}, nil
	}

	var sb strings.Builder
	sb.WriteString(fmt.Sprintf("Templates (%d):\n\n", len(results)))
	for _, r := range results {
		sb.WriteString(fmt.Sprintf("- %s\n", r.Content))
		sb.WriteString(fmt.Sprintf("  path: %s\n", r.Path))
	}
	return CallToolResult{Content: []ContentItem{{Type: "text", Text: sb.String()}}}, nil
}

func resolveTemplatePath(p string) (string, error) {
	if p == "" {
		return "", fmt.Errorf("path is required")
	}
	abs := p
	if !filepath.IsAbs(abs) {
		abs = filepath.Join(util.DataDir, "templates", p)
	}
	abs = filepath.Clean(abs)
	templatesBase := filepath.Clean(filepath.Join(util.DataDir, "templates"))
	rel, err := filepath.Rel(templatesBase, abs)
	if err != nil || strings.HasPrefix(rel, "..") || rel == ".." {
		return "", fmt.Errorf("path escapes templates dir: %s", p)
	}
	return abs, nil
}

func templateGet(args map[string]any) (CallToolResult, error) {
	p, _ := args["path"].(string)
	abs, err := resolveTemplatePath(p)
	if err != nil {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Provide a non-empty `path` value, relative (under `data/templates/`) or absolute, pointing at the template file.
  2. If you need to discover available templates first, call the list-templates tool, then pass a returned `path`.

Example fix

// before
{"path": ""}
// after
{"path": "daily.md"}
Defensive patterns

Strategy: validation

Validate before calling

// Require a non-empty path before invoking a template tool.
if strings.TrimSpace(p) == "" {
    return errors.New("path is required")
}

Prevention

When it happens

Trigger: Calling `templateGet`/`templateRemove`/`templateRender` (or any consumer of `resolveTemplatePath`) with `args["path"]` missing or set to `""`.

Common situations: The MCP client omitted the `path` field from the arguments object, or sent `path: ""`. A caller assumed a default template would be chosen.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/06ea7772a6da8042. Report an issue: GitHub.