Skip to main content

MCI Templates

MCI includes a powerful templating system that works consistently across all adapters (Python, JavaScript, Go, etc.). This document covers the standard templating features available in every MCI adapter.

Overview

The MCI templating system allows you to inject dynamic values into your tool definitions, file content, and text output. It supports:
  • Variable substitution with {{}} syntax
  • Default values with pipe operator |
  • Conditional blocks with @if, @elseif, @else, @endif
  • For loops with @for and range()
  • Foreach loops with @foreach for arrays and objects
Important: All features described here are part of the MCI standard and are supported by every adapter. Some adapters may provide additional language-specific templating (e.g., Jinja2 in Python), but check adapter documentation for those extensions.

Where Templates are Used

Templates work in:
  1. MCI Schema Files (.mci.json, .mci.yaml)
  2. File Execution content (when enableTemplating: true)
  3. Text Execution content

Basic Variable Substitution

Syntax

Use double curly braces to reference variables:

Available Contexts

Examples in JSON

Tool Definition:
File Execution:
Text Execution:

Nested Properties

Access nested object properties with dot notation:

Default Values

Use the pipe operator | to provide default values when variables are not set:

Syntax

Examples in JSON

With Environment Variables:
With Properties:
In File Paths:

Multiple Levels

Conditional Blocks

Conditionals allow you to include or exclude content based on conditions.

Syntax

Supported Conditions

Examples in File Templates

Simple Conditional (template.txt):
Multiple Conditions (report.txt):
Numeric Comparison (access.txt):

Examples in Text Execution

XML-Style Conditionals

Some file types (like XML) benefit from explicit conditional syntax: config.xml:

For Loops

For loops iterate a fixed number of times using a range.

Syntax

  • start: Starting value (inclusive)
  • end: Ending value (exclusive)
  • Standard programming range: [start, end)

Examples in File Templates

Simple Loop (list.txt):
Output:
Loop with Variables (report.txt):
Loop in JSON-like Format:
Output:

Foreach Loops

Foreach loops iterate over arrays or object properties from your data.

Syntax

Examples with Arrays

Array Iteration (list.txt):
Input:
Output:

Examples with Object Arrays

Complex Objects (users.txt):
Input:
Output:

Nested Foreach

XML Example

data.xml:

Combining Features

You can combine variables, defaults, conditionals, and loops:

Example 1: Complex Template

prompt.txt:

Example 2: JSON Configuration Template

config-template.json (loaded via file execution):

Example 3: XML Report

report.xml:

Best Practices

1. Use Defaults for Configuration

2. Keep File Templates for Complex Logic

Instead of:
Use:

3. Use Descriptive Variable Names

✓ Good:
✗ Avoid:

4. Validate Required Variables

Use inputSchema to require necessary properties:

Adapter-Specific Extensions

While the features described here work in all MCI adapters, some adapters may provide additional templating capabilities. Always rely on standard MCI templating for cross-adapter compatibility.

Summary

  • Variable Substitution: {{props.field}}, {{env.VAR}}
  • Defaults: {{env.VAR|'default'}}
  • Conditionals: @if, @elseif, @else, @endif
  • For Loops: @for(i in range(start, end))
  • Foreach Loops: @foreach(item in props.items)
  • Standard Across Adapters: All features should work in any adapter.
  • File Templates: Best for complex logic
  • JSON & XML: Templates work in any text format
The MCI templating system provides powerful, consistent templating across all adapters, making your tools portable and maintainable.