set_fill
Set the background fill of an Apple .icon bundle using solid colors or gradients. Supports hex colors and gradient angle control.
Instructions
Set the background fill of an .icon bundle. Supports solid colors and gradients.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bundle_path | Yes | Path to .icon bundle | |
| fill_type | Yes | Fill type | |
| color | No | Hex color for solid fill or gradient bottom | |
| color2 | No | Second hex color for gradient top | |
| gradient_angle | No | Gradient angle in degrees (0 = bottom to top) |
Implementation Reference
- src/lib/ops-glass.ts:291-328 (handler)The `setFill` function — the core handler that reads the icon bundle manifest, sets the background fill based on `fill_type` (none, automatic, solid, or gradient), computes gradient orientation from `gradient_angle`, and saves the updated manifest.
export async function setFill(params: SetFillParams): Promise<McpResult> { try { const { manifest } = await readIconBundle(params.bundle_path); if (params.fill_type === 'none') { manifest.fill = 'none'; } else if (params.fill_type === 'automatic') { manifest.fill = 'automatic'; } else if (params.fill_type === 'solid' && params.color) { manifest.fill = solidFill(params.color); } else if (params.fill_type === 'gradient' && params.color && params.color2) { const angle = (params.gradient_angle * Math.PI) / 180; manifest.fill = { 'linear-gradient': [ hexToIconColor(params.color), hexToIconColor(params.color2), ], orientation: { start: { x: 0.5 - Math.sin(angle) * 0.5, y: 0.5 + Math.cos(angle) * 0.5, }, stop: { x: 0.5 + Math.sin(angle) * 0.5, y: 0.5 - Math.cos(angle) * 0.5, }, }, }; } await saveManifest(params.bundle_path, manifest); return ok(`Updated fill in ${params.bundle_path}`); } catch (error: unknown) { const msg = error instanceof Error ? error.message : 'Unknown error'; return err(`Error: ${msg}`); } } - src/lib/ops-glass.ts:62-68 (schema)The `SetFillParams` interface defining input parameters: bundle_path, fill_type (solid|gradient|automatic|none), color, color2, and gradient_angle.
export interface SetFillParams { bundle_path: string; fill_type: 'solid' | 'gradient' | 'automatic' | 'none'; color?: string; color2?: string; gradient_angle: number; } - src/server.ts:193-205 (registration)The MCP tool registration for 'set_fill' on the server, with Zod schema for validation (bundle_path, fill_type enum, optional color/color2, gradient_angle with default 0), delegating to the `setFill` handler.
// ── Tool: set_fill ── server.tool( 'set_fill', 'Set the background fill of an .icon bundle. Supports solid colors and gradients.', { bundle_path: z.string().describe('Path to .icon bundle'), fill_type: z.enum(['solid', 'gradient', 'automatic', 'none']).describe('Fill type'), color: z.optional(z.string()).describe('Hex color for solid fill or gradient bottom'), color2: z.optional(z.string()).describe('Second hex color for gradient top'), gradient_angle: z.number().default(0).describe('Gradient angle in degrees (0 = bottom to top)'), }, async (params) => setFill(params), ); - src/lib/manifest.ts:45-47 (helper)The `solidFill` helper function that converts a hex color string to the `{ solid: colorString }` format used by the manifest.
export function solidFill(hex: string): FillValue { return { solid: hexToIconColor(hex) }; } - src/lib/manifest.ts:31-43 (helper)The `hexToIconColor` helper function that converts a hex color (e.g., #FF6B35) to the icon color string format (e.g., 'srgb:1.00000,0.41961,0.20784,1.00000'), used by both solid and gradient fills.
export function hexToIconColor(hex: string, colorSpace: string = 'srgb'): string { hex = hex.replace('#', ''); if (hex.length === 3) { hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; } if ((hex.length !== 6) || !/^[0-9a-fA-F]{6}$/.test(hex)) { return `${colorSpace}:0.00000,0.00000,0.00000,1.00000`; } const r = parseInt(hex.slice(0, 2), 16) / 255; const g = parseInt(hex.slice(2, 4), 16) / 255; const b = parseInt(hex.slice(4, 6), 16) / 255; return `${colorSpace}:${r.toFixed(5)},${g.toFixed(5)},${b.toFixed(5)},1.00000`; }