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
@forandrange() - Foreach loops with
@foreachfor arrays and objects
Where Templates are Used
Templates work in:- MCI Schema Files (
.mci.json,.mci.yaml) - File Execution content (when
enableTemplating: true) - Text Execution content
Basic Variable Substitution
Syntax
Use double curly braces to reference variables:Available Contexts
| Context | Access | Description |
|---|---|---|
props | {{props.fieldName}} | Input properties passed to the tool |
env | {{env.VARIABLE_NAME}} | Environment variables |
input | {{input.fieldName}} | Alias for props (legacy, use props) |
Examples in JSON
Tool Definition: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:Multiple Levels
Conditional Blocks
Conditionals allow you to include or exclude content based on conditions.Syntax
Supported Conditions
| Type | Syntax | Example |
|---|---|---|
| Truthy | @if(path.to.value) | @if(props.enabled) |
| Equality | @if(path == "value") | @if(props.status == "active") |
| Inequality | @if(path != "value") | @if(props.role != "admin") |
| Greater than | @if(path > value) | @if(props.age > 18) |
| Less than | @if(path < value) | @if(props.count < 100) |
Examples in File Templates
Simple Conditional (template.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):Foreach Loops
Foreach loops iterate over arrays or object properties from your data.Syntax
Examples with Arrays
Array Iteration (list.txt):Examples with Object Arrays
Complex Objects (users.txt):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:3. Use Descriptive Variable Names
✓ Good:4. Validate Required Variables
UseinputSchema 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
