On this page
Server-authoritative variant MCP tools that deterministically generate palette presets from a seed, bake a preset's palette swap into pixels, and list or remove presets.
#server.src.pixelweaver.mcp_variant_tools
#server.src.pixelweaver.mcp_variant_tools
Variant-preset MCP tools -- server-authoritative variant generation + baking.
Four tools drive the project-scoped variant subsystem (project.variant_presets):
- generate_variant: deterministically generate a palette variant from a REQUIRED integer seed. Resolves the target's palette from the authoritative pixel buffers (server-side), runs the byte-exact Python port (variant_palette.generate_random_variant), appends the resulting preset, and rides a meta_snapshot undo record. Same seed + same pixels => identical preset overrides (the port shares the browser's culori math + xorshift32).
- apply_variant: BAKE a preset's palette swap into the authoritative pixel buffers (all frames of the target's rgba leaves), through the shared variant_palette.apply_palette_swap primitive. Rides a COMPOUND pixel undo record (one per changed layer/frame) so MCP/WS undo reverts every byte. This is the destructive counterpart to the client's non-destructive preview toggle.
- list_variant_presets (read-only) / remove_variant_preset.
Mutating handlers follow the established sequence: validate -> mutate authoritative state -> dispatch the history/undo entry -> broadcast full state. Bad input is a loud, structured {"success": false} error, never a silent success.
#_resolve_canvas
def _resolve_canvas(project: Any, canvas_name: str | None) -> AnyPick the target canvas by name (default: first canvas).
#_resolve_target
def _resolve_target(canvas: Any, target_id: str | None) -> dict[str, Any]Resolve the variant target node: an explicit id, else group-first then the first rgba leaf (a faithful simplification of the client's findTarget).
#_rgba_leaf_ids
def _rgba_leaf_ids(node: dict[str, Any]) -> list[str]Ids of the rgba (pixel) leaves under node (the node itself if a leaf).
#_extract_palette
def _extract_palette(canvas: Any, leaf_ids: list[str]) -> list[str]Union of opaque colors across all frames of the given leaves, sorted (mirror of the client extractGroupPalette, which sorts for determinism).
#register_variant_tools
def register_variant_tools(registry: MCPCommandRegistry) -> NoneRegister all variant-preset MCP tools.