Skip to main content
Glama
bazylhorsey
by bazylhorsey

create_from_template

Generate new notes in Obsidian using predefined templates with custom variables and frontmatter for consistent document creation.

Instructions

Create a new note from a template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
frontmatterNoAdditional frontmatter
targetPathYesPath for new note
templatePathYesPath to template file
variablesNoTemplate variables
vaultYesVault name

Implementation Reference

  • MCP tool handler for 'create_from_template' that retrieves the vault connector and delegates execution to TemplateService.createFromTemplate, returning the result as MCP content.
    case 'create_from_template': {
      const connector = this.connectors.get(args?.vault as string);
      if (!connector || !connector.vaultPath) {
        throw new Error(`Vault "${args?.vault}" not found or not a local vault`);
      }
    
      const result = await this.templateService.createFromTemplate(
        connector.vaultPath,
        args?.templatePath as string,
        args?.targetPath as string,
        {
          variables: args?.variables as Record<string, any> | undefined,
          frontmatter: args?.frontmatter as Record<string, any> | undefined,
        }
      );
    
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • src/index.ts:379-392 (registration)
    Registration of the 'create_from_template' tool in the MCP server's tools list, including name, description, and input schema.
      name: 'create_from_template',
      description: 'Create a new note from a template',
      inputSchema: {
        type: 'object',
        properties: {
          vault: { type: 'string', description: 'Vault name' },
          templatePath: { type: 'string', description: 'Path to template file' },
          targetPath: { type: 'string', description: 'Path for new note' },
          variables: { type: 'object', description: 'Template variables' },
          frontmatter: { type: 'object', description: 'Additional frontmatter' },
        },
        required: ['vault', 'templatePath', 'targetPath'],
      },
    },
  • Main helper function in TemplateService that renders a template using renderTemplate and writes the rendered content to the specified target path in the vault.
    async createFromTemplate(
      vaultPath: string,
      templatePath: string,
      targetPath: string,
      options?: TemplateRenderOptions
    ): Promise<VaultOperationResult<string>> {
      try {
        // Render template
        const renderResult = await this.renderTemplate(vaultPath, templatePath, {
          ...options,
          targetPath,
        });
    
        if (!renderResult.success || !renderResult.data) {
          return { success: false, error: renderResult.error };
        }
    
        // Write to target path
        const fullTargetPath = path.join(vaultPath, targetPath);
    
        // Ensure directory exists
        await fs.mkdir(path.dirname(fullTargetPath), { recursive: true });
    
        // Write file
        await fs.writeFile(fullTargetPath, renderResult.data.content, 'utf-8');
    
        return { success: true, data: targetPath };
      } catch (error) {
        return {
          success: false,
          error: `Failed to create from template: ${error instanceof Error ? error.message : String(error)}`
        };
      }
    }

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

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