CoplayDev/unity-mcp · error · ValueError

Invalid UNITY_MCP_TIMEOUT value: {timeout_raw!r}

Error message

Invalid UNITY_MCP_TIMEOUT value: {timeout_raw!r}

What it means

Thrown by CLIConfig.from_env() when the UNITY_MCP_TIMEOUT environment variable cannot be parsed as an int (seconds). It defaults to '30' only when unset; a non-numeric value triggers this during startup, before any request is made.

Source

Thrown at Server/src/cli/utils/config.py:31

    port: int = 8080
    timeout: int = 30
    format: str = "text"  # text, json, table
    unity_instance: Optional[str] = None

    @classmethod
    def from_env(cls) -> "CLIConfig":
        port_raw = os.environ.get("UNITY_MCP_HTTP_PORT", "8080")
        try:
            port = int(port_raw)
        except (ValueError, TypeError):
            raise ValueError(
                f"Invalid UNITY_MCP_HTTP_PORT value: {port_raw!r}")

        timeout_raw = os.environ.get("UNITY_MCP_TIMEOUT", "30")
        try:
            timeout = int(timeout_raw)
        except (ValueError, TypeError):
            raise ValueError(
                f"Invalid UNITY_MCP_TIMEOUT value: {timeout_raw!r}")

        return cls(
            host=os.environ.get("UNITY_MCP_HOST", "127.0.0.1"),
            port=port,
            timeout=timeout,
            format=os.environ.get("UNITY_MCP_FORMAT", "text"),
            unity_instance=os.environ.get("UNITY_MCP_INSTANCE"),
        )


# Global config instance
_config: Optional[CLIConfig] = None


def get_config() -> CLIConfig:
    """Get the current CLI configuration."""
    global _config

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Set UNITY_MCP_TIMEOUT to an integer of seconds (e.g. 60).
  2. Unset the variable to fall back to the 30s default: `unset UNITY_MCP_TIMEOUT`.
  3. Check .env / CI variables for stray suffixes or empty values.

Example fix

# before
export UNITY_MCP_TIMEOUT=30s
# after
export UNITY_MCP_TIMEOUT=30
Defensive patterns

Strategy: validation

Validate before calling

raw = os.environ.get("UNITY_MCP_TIMEOUT", "30")
if not raw.isdigit():
    raise ValueError(f"Invalid UNITY_MCP_TIMEOUT value: {raw!r}")
timeout = int(raw)

Type guard

def is_int_env(raw: str | None) -> bool:
    return raw is not None and raw.lstrip("+").isdigit()

Try / catch

try:
    cfg = CLIConfig.from_env()
except ValueError as e:
    print_error(str(e)); sys.exit(1)

Prevention

When it happens

Trigger: Setting UNITY_MCP_TIMEOUT to a non-integer such as '30s', 'fast', '' (empty), or '30.5'. Triggered on any CLI invocation that builds the config.

Common situations: A developer adds a unit suffix ('30s') expecting duration parsing, or a templated env value resolves to blank. Common when migrating from a tool that accepts duration strings.

Understand the failure class

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/f3d39efa23d570af. Report an issue: GitHub.