set_layer_position
Set the scale and offset of a layer or group within an icon bundle to zoom or reposition the glyph.
Instructions
Set the scale (zoom) and offset of a layer or group within the .icon bundle. Use to zoom the glyph in/out or reposition it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bundle_path | Yes | Path to .icon bundle | |
| target | No | Whether to set position on a layer or group | layer |
| group_index | No | Group index (0-based) | |
| layer_index | No | Layer index within the group (0-based, required for target=layer) | |
| scale | No | Scale factor (0.05-3.0, where 1.0 = full size, 0.5 = half, 2.0 = double) | |
| offset_x | No | X offset in points | |
| offset_y | No | Y offset in points |
Implementation Reference
- src/lib/ops-glass.ts:334-380 (handler)The actual handler that reads an icon bundle manifest, updates the scale and offset (translation-in-points) for either a group or a specific layer, then saves the manifest.
export async function setLayerPosition(params: SetLayerPositionParams): Promise<McpResult> { try { const { manifest } = await readIconBundle(params.bundle_path); if (manifest.groups.length === 0) { return err('Error: No groups in this icon bundle'); } const group = manifest.groups[Math.min(params.group_index, manifest.groups.length - 1)]; if (params.target === 'group') { const currentPos = group.position ?? { scale: 1.0, 'translation-in-points': [0, 0] as [number, number] }; group.position = { scale: params.scale ?? currentPos.scale, 'translation-in-points': [ params.offset_x ?? currentPos['translation-in-points'][0], params.offset_y ?? currentPos['translation-in-points'][1], ], }; } else { const layerIdx = params.layer_index ?? 0; if (layerIdx >= group.layers.length) { return err(`Error: Layer index ${layerIdx} out of range (group has ${group.layers.length} layers)`); } const layer = group.layers[layerIdx]; const currentPos = layer.position ?? { scale: 1.0, 'translation-in-points': [0, 0] as [number, number] }; layer.position = { scale: params.scale ?? currentPos.scale, 'translation-in-points': [ params.offset_x ?? currentPos['translation-in-points'][0], params.offset_y ?? currentPos['translation-in-points'][1], ], }; } await saveManifest(params.bundle_path, manifest); const targetDesc = params.target === 'group' ? `group ${params.group_index}` : `layer ${params.layer_index ?? 0} in group ${params.group_index}`; return ok(`Updated position on ${targetDesc}: scale=${params.scale ?? '(unchanged)'}, offset=(${params.offset_x ?? '(unchanged)'}, ${params.offset_y ?? '(unchanged)'})`); } catch (error: unknown) { const msg = error instanceof Error ? error.message : 'Unknown error'; return err(`Error: ${msg}`); } } - src/lib/ops-glass.ts:70-78 (schema)TypeScript interface defining the input parameters for set_layer_position.
export interface SetLayerPositionParams { bundle_path: string; target: 'layer' | 'group'; group_index: number; layer_index?: number; scale?: number; offset_x?: number; offset_y?: number; } - src/server.ts:207-221 (registration)Registers the tool with the MCP server using the name 'set_layer_position', defines Zod schema for input validation, and delegates to the handler function.
// ── Tool: set_layer_position ── server.tool( 'set_layer_position', 'Set the scale (zoom) and offset of a layer or group within the .icon bundle. Use to zoom the glyph in/out or reposition it.', { bundle_path: z.string().describe('Path to .icon bundle'), target: z.enum(['layer', 'group']).default('layer').describe('Whether to set position on a layer or group'), group_index: z.number().default(0).describe('Group index (0-based)'), layer_index: z.optional(z.number()).describe('Layer index within the group (0-based, required for target=layer)'), scale: z.optional(z.number().min(0.05).max(3.0)).describe('Scale factor (0.05-3.0, where 1.0 = full size, 0.5 = half, 2.0 = double)'), offset_x: z.optional(z.number()).describe('X offset in points'), offset_y: z.optional(z.number()).describe('Y offset in points'), }, async (params) => setLayerPosition(params), );