Skip to main content
Glama
libra850
by libra850

create_note_from_template

Create Obsidian notes using templates with variable replacement to standardize formatting and content structure.

Instructions

テンプレートを使用してObsidianノートを作成します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templateNameYesTEMPLATEフォルダ内のテンプレート名(.md拡張子なし)
variablesYesテンプレート内の変数を置換するためのオブジェクト
outputPathYesノートの保存先パス(vault相対パス)
overwriteNo既存ファイルを上書きするかどうか

Implementation Reference

  • 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'],
      },
    },
  • 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;
    }
  • 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 }],
      };

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/libra850/obsidian-mcp-server'

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