compose
Combine multiple text blocks into a single layout by arranging them side by side or stacked, with control over spacing and alignment.
Instructions
Combine multiple text blocks side-by-side or stacked.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blocks | Yes | Text blocks to combine | |
| mode | No | Layout mode | horizontal |
| gap | No | Gap between blocks (spaces for horizontal, blank lines for vertical) | |
| align | No | Vertical alignment for horizontal mode | top |
| separator | No | Separator string for vertical mode |
Implementation Reference
- src/compose.ts:11-58 (handler)The compose() function that implements the core logic for combining text blocks horizontally (side-by-side) or vertically (stacked). Handles alignment (top/middle/bottom), gaps, and optional separator strings.
export function compose(blocks: string[], options: ComposeOptions = {}): string { if (blocks.length === 0) return ''; if (blocks.length === 1) return blocks[0]; const { mode = 'horizontal', gap = 1, align = 'top', separator } = options; if (mode === 'vertical') { if (separator) { return blocks.join('\n' + separator + '\n'); } const spacer = '\n' + '\n'.repeat(gap); return blocks.join(spacer); } // Horizontal mode const split = blocks.map((b) => b.split('\n')); const widths = split.map((lines) => Math.max(...lines.map((l) => l.length), 0)); const maxHeight = Math.max(...split.map((lines) => lines.length)); const gapStr = ' '.repeat(gap); // Pad each block to maxHeight with alignment const padded = split.map((lines, i) => { const w = widths[i]; const normalized = lines.map((l) => l.padEnd(w)); const diff = maxHeight - normalized.length; const empty = ' '.repeat(w); if (diff === 0) return normalized; let topPad = 0; if (align === 'middle') topPad = Math.floor(diff / 2); else if (align === 'bottom') topPad = diff; const bottomPad = diff - topPad; return [ ...Array(topPad).fill(empty), ...normalized, ...Array(bottomPad).fill(empty), ]; }); const result: string[] = []; for (let row = 0; row < maxHeight; row++) { result.push(padded.map((lines) => lines[row]).join(gapStr)); } return result.join('\n'); } - src/compose.ts:1-9 (schema)Type definitions for ComposeMode, ComposeAlign, and ComposeOptions used by the compose tool.
export type ComposeMode = 'horizontal' | 'vertical'; export type ComposeAlign = 'top' | 'middle' | 'bottom'; export interface ComposeOptions { mode?: ComposeMode; gap?: number; align?: ComposeAlign; separator?: string; } - src/mcp.ts:228-242 (registration)Registration of the 'compose' MCP tool with server.tool(), defining the Zod schema for blocks, mode, gap, align, and separator, and calling the imported compose() function.
server.tool( 'compose', 'Combine multiple text blocks side-by-side or stacked.', { blocks: z.array(z.string()).min(1).max(MAX_COMPOSE_BLOCKS).describe('Text blocks to combine'), mode: z.enum(['horizontal', 'vertical']).default('horizontal').describe('Layout mode'), gap: z.number().min(0).max(MAX_COMPOSE_GAP).default(1).describe('Gap between blocks (spaces for horizontal, blank lines for vertical)'), align: z.enum(['top', 'middle', 'bottom']).default('top').describe('Vertical alignment for horizontal mode'), separator: z.string().max(80).optional().describe('Separator string for vertical mode'), }, async ({ blocks, mode, gap, align, separator }) => { const result = compose(blocks, { mode: mode as any, gap, align: align as any, separator }); return { content: [{ type: 'text', text: result }] }; } ); - src/constants.ts:28-29 (helper)Constants MAX_COMPOSE_BLOCKS (10) and MAX_COMPOSE_GAP (10) used as limits in the compose tool schema.
export const MAX_COMPOSE_BLOCKS = 10; export const MAX_COMPOSE_GAP = 10;