iterate_loop
Execute a single iteration of a named loop with optional rhythm application to process input data within structured workflows.
Instructions
Execute one iteration of a loop with rhythm
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apply_rhythm | No | Apply the loop's rhythm pattern | |
| input | Yes | Input for this iteration | |
| loop_name | Yes | Name of the loop to iterate |
Implementation Reference
- index.js:610-645 (handler)The handler function for the 'iterate_loop' tool. It retrieves the specified loop, creates a new iteration with the provided input, applies rhythm if requested, updates the loop state, and returns a textual visualization of the iteration including phase and rhythm step.iterateLoop(args) { const { loop_name, input, apply_rhythm = true } = args; const loop = this.loops.get(loop_name); if (!loop) { return { content: [ { type: 'text', text: `❌ Loop "${loop_name}" not found.`, }, ], }; } const rhythm = apply_rhythm ? this.rhythms.get(`loop_${loop_name}`) : null; const iteration = { number: loop.iterations.length + 1, input, timestamp: new Date().toISOString(), rhythmStep: rhythm ? rhythm.next() : 1, phase: this.calculatePhase(loop.type, loop.iterations.length), }; loop.iterations.push(iteration); loop.phase = iteration.phase; return { content: [ { type: 'text', text: `🔄 Loop "${loop_name}" - Iteration ${iteration.number}\n\nInput: "${input}"\nPhase: ${iteration.phase}°\nRhythm: ${iteration.rhythmStep}\n\n${this.visualizeLoopIteration(loop.type, iteration.number)}\n\nPattern: ${this.describeLoopBehavior(loop.type, iteration.number)}`, }, ], }; }
- index.js:175-195 (schema)The input schema definition for the 'iterate_loop' tool, including properties for loop_name (required string), input (required string), and apply_rhythm (optional boolean, default true).name: 'iterate_loop', description: 'Execute one iteration of a loop with rhythm', inputSchema: { type: 'object', properties: { loop_name: { type: 'string', description: 'Name of the loop to iterate', }, input: { type: 'string', description: 'Input for this iteration', }, apply_rhythm: { type: 'boolean', description: 'Apply the loop\'s rhythm pattern', default: true, }, }, required: ['loop_name', 'input'], },
- index.js:341-342 (registration)The switch case in the CallToolRequestSchema handler that registers and dispatches 'iterate_loop' calls to the iterateLoop method.case 'iterate_loop': return this.iterateLoop(args);
- index.js:174-196 (registration)The tool object registration in the ListToolsRequestSchema response, providing name, description, and input schema.{ name: 'iterate_loop', description: 'Execute one iteration of a loop with rhythm', inputSchema: { type: 'object', properties: { loop_name: { type: 'string', description: 'Name of the loop to iterate', }, input: { type: 'string', description: 'Input for this iteration', }, apply_rhythm: { type: 'boolean', description: 'Apply the loop\'s rhythm pattern', default: true, }, }, required: ['loop_name', 'input'], }, },