Skip to main content
Glama
bazylhorsey
by bazylhorsey

render_template

Generate Obsidian notes by applying variables to template files, creating structured content with custom frontmatter and predefined formats.

Instructions

Render a template with variables

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
frontmatterNoAdditional frontmatter
targetPathNoTarget note path (for context)
templatePathYesPath to template file
variablesNoTemplate variables
vaultYesVault name

Implementation Reference

  • src/index.ts:363-377 (registration)
    Registration of the 'render_template' tool in the ListTools response, defining its name, description, and input schema.
    {
      name: 'render_template',
      description: 'Render a template with variables',
      inputSchema: {
        type: 'object',
        properties: {
          vault: { type: 'string', description: 'Vault name' },
          templatePath: { type: 'string', description: 'Path to template file' },
          variables: { type: 'object', description: 'Template variables' },
          frontmatter: { type: 'object', description: 'Additional frontmatter' },
          targetPath: { type: 'string', description: 'Target note path (for context)' },
        },
        required: ['vault', 'templatePath'],
      },
    },
  • Handler for the 'render_template' tool call in the MCP server switch statement, which retrieves the vault connector and delegates rendering to TemplateService.
    case 'render_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.renderTemplate(
        connector.vaultPath,
        args?.templatePath as string,
        {
          variables: args?.variables as Record<string, any> | undefined,
          frontmatter: args?.frontmatter as Record<string, any> | undefined,
          targetPath: args?.targetPath as string | undefined,
        }
      );
    
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • Core handler function that implements the template rendering logic: loads template, substitutes variables (built-in and custom), handles frontmatter, and returns rendered content.
    async renderTemplate(
      vaultPath: string,
      templatePath: string,
      options?: TemplateRenderOptions
    ): Promise<VaultOperationResult<TemplateRenderResult>> {
      try {
        // Get template
        const templateResult = await this.getTemplate(vaultPath, templatePath);
        if (!templateResult.success || !templateResult.data) {
          return { success: false, error: templateResult.error };
        }
    
        const template = templateResult.data;
        let content = template.content;
    
        // Build variables
        const builtInVars = this.getBuiltInVariables(options?.targetPath);
        const customVars = options?.variables || {};
        const allVariables: Record<string, any> = {
          ...builtInVars,
          ...customVars,
        };
    
        // Replace template variables
        content = this.substituteVariables(content, allVariables);
    
        // Add/update frontmatter if provided
        if (options?.frontmatter) {
          content = this.addFrontmatter(content, options.frontmatter);
        }
    
        return {
          success: true,
          data: {
            content,
            renderedVariables: allVariables,
          },
        };
      } catch (error) {
        return {
          success: false,
          error: `Failed to render template: ${error instanceof Error ? error.message : String(error)}`
        };
      }
    }
  • Helper function for substituting template variables in content, supporting formats, defaults, and date formatting.
    private substituteVariables(content: string, variables: Record<string, any>): string {
      // Replace {{variable}} or {{variable|default}} patterns
      return content.replace(/\{\{([^}]+)\}\}/g, (match, expression) => {
        expression = expression.trim();
    
        // Handle default values: {{variable|default}}
        const [varName, defaultValue] = expression.split('|').map((s: string) => s.trim());
    
        // Handle date formats: {{date:YYYY-MM-DD}}
        const [actualVar, format] = varName.split(':').map((s: string) => s.trim());
    
        let value = variables[actualVar];
    
        // Apply format if specified
        if (format && value instanceof Date) {
          value = this.formatDate(value, format);
        } else if (format && typeof value === 'string') {
          // Try to parse as date and format
          const date = new Date(value);
          if (!isNaN(date.getTime())) {
            value = this.formatDate(date, format);
          }
        }
    
        // Use default if value is undefined
        if (value === undefined || value === null) {
          return defaultValue !== undefined ? defaultValue : match;
        }
    
        return String(value);
      });
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions rendering but doesn't disclose behavioral traits like whether this is a read-only operation, if it modifies files, what the output format is, or any permissions needed. This leaves significant gaps for a tool with 5 parameters and no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It is appropriately sized and front-loaded, making it easy to understand at a glance without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of 5 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what rendering entails (e.g., output format, file changes), behavioral context, or usage scenarios, leaving the agent with insufficient information for effective tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 5 parameters. The description adds no additional meaning beyond implying variables are used in rendering, which is already clear from the parameter names. Baseline 3 is appropriate as the schema handles the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Render a template with variables' clearly states the action (render) and resource (template), specifying the use of variables. It distinguishes from siblings like 'create_from_template' by focusing on rendering rather than creation, though it doesn't explicitly contrast with all template-related tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'create_from_template' or other template-related siblings. The description lacks context about prerequisites, such as needing an existing template file, or exclusions for when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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