create_note_from_template
Create Obsidian notes using templates with variable replacement to standardize note structure and save time on repetitive formatting.
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)The core handler function that processes the template with provided variables, validates the output path and permissions, ensures the target directory exists, handles overwrite checks, and writes the resulting note content to the Obsidian vault.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)Registers the create_note_from_template tool in the MCP server's tool list, including its name, description, and detailed input schema for validation.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 structure of input options for the createNoteFromTemplate handler, matching the MCP input schema.export interface CreateNoteOptions { templateName: string; variables: Record<string, any>; outputPath: string; overwrite?: boolean; }
- src/server.ts:259-269 (handler)Dispatches incoming tool calls for 'create_note_from_template' to the ObsidianHandler instance, mapping MCP arguments to handler parameters and returning the result.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 }], };