Skip to main content
Glama

create_from_template

Generate new notes in Obsidian by applying templates with customizable variables for consistent formatting and structure.

Instructions

Create a new note from an existing template note

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templatePathYesPath to the template note
newPathYesPath for the new note
variablesNoVariables to replace in template (e.g., {{title}} -> 'My Note')

Implementation Reference

  • The main handler function that reads a template note, replaces variables like {{title}} and built-in {{date}}, {{time}}, {{datetime}}, ensures directories, and writes the new note.
    async function handleCreateFromTemplate(args: { templatePath: string; newPath: string; variables?: Record<string, string>; }): Promise<string> { const templateFullPath = resolvePath(args.templatePath); const newFullPath = resolvePath(args.newPath); if (!(await fileExists(templateFullPath))) { throw new Error(`Template not found at ${args.templatePath}`); } if (await fileExists(newFullPath)) { throw new Error(`Note already exists at ${args.newPath}`); } let content = await fs.readFile(templateFullPath, "utf-8"); // Replace variables if (args.variables) { for (const [key, value] of Object.entries(args.variables)) { const pattern = new RegExp(`\\{\\{${key}\\}\\}`, "g"); content = content.replace(pattern, value); } } // Replace built-in variables const now = new Date(); content = content .replace(/\{\{date\}\}/g, now.toISOString().split("T")[0]) .replace(/\{\{time\}\}/g, now.toTimeString().split(" ")[0]) .replace(/\{\{datetime\}\}/g, now.toISOString()); await ensureDir(newFullPath); await fs.writeFile(newFullPath, content, "utf-8"); return `Successfully created note at ${args.newPath} from template ${args.templatePath}`; }
  • The tool schema definition including input schema with properties for templatePath, newPath, and optional variables object.
    { name: "create_from_template", description: "Create a new note from an existing template note", inputSchema: { type: "object", properties: { templatePath: { type: "string", description: "Path to the template note", }, newPath: { type: "string", description: "Path for the new note", }, variables: { type: "object", description: "Variables to replace in template (e.g., {{title}} -> 'My Note')", }, }, required: ["templatePath", "newPath"], }, },
  • src/index.ts:935-943 (registration)
    The switch case in the CallToolRequestSchema handler that dispatches to the handleCreateFromTemplate function.
    case "create_from_template": result = await handleCreateFromTemplate( args as { templatePath: string; newPath: string; variables?: Record<string, string>; } ); break;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sureshsankaran/obsidian-tools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server