create_note_from_template
Create Obsidian notes using templates with variable replacement to standardize formatting and content structure.
Instructions
テンプレートを使用してObsidianノートを作成します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| templateName | Yes | TEMPLATEフォルダ内のテンプレート名(.md拡張子なし) | |
| variables | Yes | テンプレート内の変数を置換するためのオブジェクト | |
| outputPath | Yes | ノートの保存先パス(vault相対パス) | |
| overwrite | No | 既存ファイルを上書きするかどうか |
Implementation Reference
- src/obsidian-handler.ts:26-54 (handler)Primary handler function executing the tool: validates output path, processes template with variables using TemplateEngine, builds full path, ensures directory exists, checks for overwrite if specified, writes content to file, returns success message.async createNoteFromTemplate(options: CreateNoteOptions): Promise<string> { // パスの検証 if (!FileUtils.validatePath(this.config.vaultPath, options.outputPath)) { throw new Error('無効なファイルパスです'); } // テンプレートを処理 const content = await this.templateEngine.processTemplate( options.templateName, options.variables ); // 出力パスを構築 const fullOutputPath = path.join(this.config.vaultPath, options.outputPath); const outputDir = path.dirname(fullOutputPath); // ディレクトリを作成 await FileUtils.ensureDir(outputDir); // ファイルの存在チェック if (!options.overwrite && await FileUtils.fileExists(fullOutputPath)) { throw new Error(`ファイル '${options.outputPath}' は既に存在します`); } // ファイルを書き込み await fs.writeFile(fullOutputPath, content, 'utf-8'); return `ノート '${options.outputPath}' を作成しました`; }
- src/server.ts:54-79 (registration)Tool registration definition in the ListTools handler, specifying name, description, and detailed input schema for parameters.name: 'create_note_from_template', description: 'テンプレートを使用してObsidianノートを作成します', inputSchema: { type: 'object', properties: { templateName: { type: 'string', description: 'TEMPLATEフォルダ内のテンプレート名(.md拡張子なし)', }, variables: { type: 'object', description: 'テンプレート内の変数を置換するためのオブジェクト', }, outputPath: { type: 'string', description: 'ノートの保存先パス(vault相対パス)', }, overwrite: { type: 'boolean', description: '既存ファイルを上書きするかどうか', default: false, }, }, required: ['templateName', 'variables', 'outputPath'], }, },
- src/types.ts:15-20 (schema)TypeScript interface defining the input parameters for the createNoteFromTemplate handler, matching the tool's inputSchema.export interface CreateNoteOptions { templateName: string; variables: Record<string, any>; outputPath: string; overwrite?: boolean; }
- src/server.ts:259-269 (handler)Dispatch handler in the MCP server that maps tool call arguments to the ObsidianHandler method and returns the result as MCP content.case 'create_note_from_template': const result = await this.obsidianHandler.createNoteFromTemplate({ templateName: args.templateName as string, variables: (args.variables as Record<string, any>) || {}, outputPath: args.outputPath as string, overwrite: (args.overwrite as boolean) || false, }); return { content: [{ type: 'text', text: result }], };