Skip to main content
Glama

render_template

Generate dynamic content by applying variables to predefined templates within the DollhouseMCP server for AI persona management.

Instructions

Render a template element with provided variables

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesThe template name to render
variablesYesVariables to use in the template

Implementation Reference

  • Registration of the 'render_template' tool including input schema, description, and handler function that executes the tool by calling server.renderTemplate
    // Element-specific tools
    {
      tool: {
        name: "render_template",
        description: "Render a template element with provided variables",
        inputSchema: {
          type: "object",
          properties: {
            name: {
              type: "string",
              description: "The template name to render",
            },
            variables: {
              type: "object",
              description: "Variables to use in the template",
              additionalProperties: true,
            },
          },
          required: ["name", "variables"],
        },
      },
      handler: (args: RenderTemplateArgs) => server.renderTemplate(args.name, args.variables)
    },
  • Type definition for tool input arguments
    interface RenderTemplateArgs {
      name: string;
      variables: Record<string, any>;
    }
  • Interface definition for the underlying server.renderTemplate service method
    renderTemplate(name: string, variables: Record<string, any>): Promise<any>;
  • Core implementation of template rendering logic in Template class (called indirectly via server.renderTemplate)
    async render<T extends Record<string, unknown>>(
      variables: T = {} as T, 
      includeDepth: number = 0
    ): Promise<string> {
      // SECURITY FIX #4: Prevent infinite include loops
      if (includeDepth > this.MAX_INCLUDE_DEPTH) {
        SecurityMonitor.logSecurityEvent({
          type: 'INCLUDE_DEPTH_EXCEEDED',
          severity: 'HIGH',
          source: 'Template.render',
          details: `Include depth ${includeDepth} exceeds maximum ${this.MAX_INCLUDE_DEPTH}`
        });
        throw ErrorHandler.createError('Maximum template include depth exceeded', ErrorCategory.VALIDATION_ERROR, ValidationErrorCodes.MAX_INCLUDE_DEPTH);
      }
    
      // Compile the template
      const compiled = this.compile();
      
      // Validate and sanitize all provided variables
      const sanitizedVariables = await this.validateAndSanitizeVariables(variables);
      
      // Start with the template content
      let rendered = compiled.content;
      
      // Replace tokens in reverse order to maintain positions
      const sortedTokens = [...compiled.tokens].sort((a, b) => b.position - a.position);
      
      for (const token of sortedTokens) {
        const value = this.resolveVariable(token.variable, sanitizedVariables);
        const stringValue = this.formatValue(value);
        
        // Replace the token with the sanitized value
        rendered = rendered.substring(0, token.position) + 
                   stringValue + 
                   rendered.substring(token.position + token.token.length);
      }
      
      // Process includes if any
      if (this.metadata.includes && this.metadata.includes.length > 0) {
        rendered = await this.processIncludes(rendered, sanitizedVariables, includeDepth);
      }
      
      // Update usage statistics
      // NOTE: These updates are not atomic and may have race conditions under concurrent access
      // This is acceptable for usage statistics which don't require perfect accuracy
      // For production systems requiring atomic counters, consider using a database or atomic operations
      this.metadata.usage_count = (this.metadata.usage_count || 0) + 1;
      this.metadata.last_used = new Date().toISOString();
      
      // SECURITY FIX #5: Log template usage for audit trail
      SecurityMonitor.logSecurityEvent({
        type: 'TEMPLATE_RENDERED',
        severity: 'LOW',
        source: 'Template.render',
        details: `Template ${this.metadata.name} rendered with ${Object.keys(sanitizedVariables).length} variables`
      });
      
      return rendered;
    }
  • Global registration of all element tools (including render_template) into the MCP tool registry during server setup
    // Register element tools (new generic tools for all element types)
    this.toolRegistry.registerMany(getElementTools(instance));
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool renders a template with variables but doesn't describe what rendering entails (e.g., generating output, applying transformations), potential side effects, error handling, or performance considerations. This is a significant gap for a tool with no annotation coverage.

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 that front-loads the core action ('Render a template element') and specifies the key input ('with provided variables'). There is no wasted text, making it highly concise and well-structured for quick understanding.

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 rendering with variables, no annotations, and no output schema, the description is incomplete. It doesn't explain the rendering process, output format, error cases, or how variables are interpreted. For a tool that likely produces some output, more context is needed to guide effective use.

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 fully documents the two parameters ('name' and 'variables'). The description adds minimal value by mentioning 'provided variables', which aligns with the schema but doesn't provide additional syntax, format details, or examples beyond what's already in the structured data.

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 clearly states the action ('Render') and the resource ('a template element'), specifying it uses 'provided variables'. It distinguishes from siblings like 'create_element' or 'edit_element' by focusing on rendering rather than creation or modification. However, it doesn't explicitly differentiate from potential similar tools like 'execute_agent' which might also involve processing with variables.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a pre-existing template), exclusions, or comparisons to siblings like 'execute_agent' or 'validate_element'. Usage is implied only by the action of rendering with variables, lacking explicit context.

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/DollhouseMCP/DollhouseMCP'

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