CoplayDev/unity-mcp · error · ValueError
{context} must be a list of colors
Error message
{context} must be a list of colors What it means
Raised by _normalize_palette (texture.py:152) when the palette value, after optional JSON parsing, is not a list. A palette must be a JSON array of colors. The 'context' label is 'palette' (from the create command's --palette option).
Source
Thrown at Server/src/cli/commands/texture.py:152
if _is_normalized_color(value):
return [int(round(float(c) * 255)) for c in value]
return [int(c) for c in value]
except (TypeError, ValueError):
raise ValueError(
f"{context} values must be numeric, got {value}")
raise ValueError(
f"{context} must have 3 or 4 components, got {len(value)}")
raise ValueError(f"{context} must be a list or hex string")
def _normalize_palette(value: Any, context: str) -> list[list[int]]:
if value is None:
return []
if isinstance(value, str):
value = try_parse_json(value, context)
if not isinstance(value, list):
raise ValueError(f"{context} must be a list of colors")
return [_normalize_color(color, f"{context} item") for color in value]
def _normalize_pixels(value: Any, width: int, height: int, context: str) -> list[list[int]] | str:
if value is None:
raise ValueError(f"{context} is required")
if isinstance(value, str):
if value.startswith("base64:"):
return value
trimmed = value.strip()
if trimmed.startswith("[") and trimmed.endswith("]"):
value = try_parse_json(trimmed, context)
else:
return f"base64:{value}"
if isinstance(value, list):
expected_count = width * height
if len(value) != expected_count:
raise ValueError(View on GitHub (pinned to c21bf496bc)
Solutions
- Pass the palette as a JSON array of colors, e.g. '["#FF0000","#00FF00"]'.
- Wrap a single color in brackets: '["#FF0000"]'.
- Confirm the --palette JSON parses to a list before running.
Example fix
# before unity-mcp texture create Assets/Tex.png --pattern checkerboard --palette '"#FF0000"' # after unity-mcp texture create Assets/Tex.png --pattern checkerboard --palette '["#FF0000","#00FF00"]'
Defensive patterns
Strategy: type-guard
Validate before calling
# Python - ensure palette is a list before _normalize_palette
if not isinstance(value, list):
raise ValueError(f"{context} must be a list of colors") Type guard
def is_palette_list(v) -> bool: return isinstance(v, list)
Try / catch
try:
palette = _normalize_palette(value, context)
except ValueError as e:
print_error(str(e)); sys.exit(1) Prevention
- Always wrap palette colors in a JSON array.
- Pass a single color as [color], not color.
When it happens
Trigger: Passing --palette '"#FF0000"' (a single color string, not an array), --palette '{"a":1}' (a dict), or a JSON string that parses to a scalar. The create command calls _normalize_palette(palette, 'palette').
Common situations: Forgetting the outer array brackets around palette colors; passing a single color where a list is required; a JSON object where an array was intended.
Related errors
- width and height must be positive
- Invalid hex color: {value}
- {context} is required
- {context} dict values must be numeric, got {value}
- {context} values must be numeric, got {value}
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/6a0acebd0357766f.
Report an issue: GitHub.