Skip to main content
Glama
sureshsankaran

Obsidian Tools MCP Server

create_from_template

Create new Obsidian notes from templates by specifying paths and variables for content replacement.

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 `handleCreateFromTemplate` that reads the content from a template note, replaces user-provided variables (e.g., {{title}}) and built-in variables like {{date}}, {{time}}, {{datetime}}, ensures the target directory exists, and writes the processed content to the new note path.
    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 JSON schema defining the input parameters for the tool: required templatePath and newPath, optional variables object.
    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:319-341 (registration)
    Tool registration in the `tools` array used for ListTools response, specifying name, description, and inputSchema.
    { 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)
    Dispatch case in the CallTool request handler switch statement that invokes the handler function with properly typed arguments.
    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