CoplayDev/unity-mcp · error · ValueError
{context} must be a list or hex string
Error message
{context} must be a list or hex string What it means
Raised by _normalize_color (texture.py:143) when the value is not None, not a (hex) string, not a dict, and not a list/tuple — i.e. an unsupported scalar type such as an int, float, or bool. The 'context' label names the field. After a non-# string is JSON-parsed it may become one of these unsupported types, hitting the final fallback.
Source
Thrown at Server/src/cli/commands/texture.py:143
except (TypeError, ValueError):
raise ValueError(f"{context} dict values must be numeric, got {value}")
raise ValueError(f"{context} dict must have 'r', 'g', 'b' keys, got {list(value.keys())}")
if isinstance(value, (list, tuple)):
if len(value) == 3:
value = list(value) + [1.0 if _is_normalized_color(value) else 255]
if len(value) == 4:
try:
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 valueView on GitHub (pinned to c21bf496bc)
Solutions
- Pass a color as a hex string (#RRGGBB), a [r,g,b] list, or an {r,g,b} dict.
- If you meant grayscale, expand it to a 3- or 4-element array (e.g. [128,128,128]).
- Ensure JSON color arguments parse to an array or object, not a scalar.
Example fix
# before unity-mcp texture create Assets/Tex.png --color '128' # after unity-mcp texture create Assets/Tex.png --color '[128,128,128]'
Defensive patterns
Strategy: type-guard
Validate before calling
# Python - accept only supported color shapes before _normalize_color
ok = value is None or isinstance(value, str) or isinstance(value, dict) or isinstance(value, (list, tuple))
if not ok:
raise ValueError(f"{context} must be a list or hex string") Type guard
def is_color_shape(v) -> bool: return v is None or isinstance(v,(str,dict,list,tuple))
Try / catch
try:
color = _normalize_color(value, context)
except ValueError as e:
print_error(str(e)); sys.exit(1) Prevention
- Never pass a bare scalar (int/float/bool) as a color.
- Expand grayscale ints to [v,v,v] first.
When it happens
Trigger: Passing --color '128' (a bare integer), --color '1.0', or a JSON string that parses to a scalar. Applies to any color argument (color, palette item, pixel, set-pixels color).
Common situations: Passing a grayscale int expecting it to expand; a JSON string that evaluates to a number instead of an array/object; a boolean where a color was expected.
Related errors
- Invalid hex color: {value}
- {context} is required
- {context} dict values must be numeric, got {value}
- {context} values must be numeric, got {value}
- {context} must have 3 or 4 components, got {len(value)}
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/d8f96ba0cda96400.
Report an issue: GitHub.