{"record":{"id":"7dafd24af3b5b9cd","repo":"CoplayDev/unity-mcp","slug":"invalid-unity-mcp-http-port-value-port-raw-r","errorCode":null,"errorMessage":"Invalid UNITY_MCP_HTTP_PORT value: {port_raw!r}","messagePattern":"Invalid UNITY_MCP_HTTP_PORT value: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/utils/config.py","lineNumber":24,"sourceCode":"\n\n@dataclass\nclass CLIConfig:\n    \"\"\"Configuration for CLI connection to Unity.\"\"\"\n\n    host: str = \"127.0.0.1\"\n    port: int = 8080\n    timeout: int = 30\n    format: str = \"text\"  # text, json, table\n    unity_instance: Optional[str] = None\n\n    @classmethod\n    def from_env(cls) -> \"CLIConfig\":\n        port_raw = os.environ.get(\"UNITY_MCP_HTTP_PORT\", \"8080\")\n        try:\n            port = int(port_raw)\n        except (ValueError, TypeError):\n            raise ValueError(\n                f\"Invalid UNITY_MCP_HTTP_PORT value: {port_raw!r}\")\n\n        timeout_raw = os.environ.get(\"UNITY_MCP_TIMEOUT\", \"30\")\n        try:\n            timeout = int(timeout_raw)\n        except (ValueError, TypeError):\n            raise ValueError(\n                f\"Invalid UNITY_MCP_TIMEOUT value: {timeout_raw!r}\")\n\n        return cls(\n            host=os.environ.get(\"UNITY_MCP_HOST\", \"127.0.0.1\"),\n            port=port,\n            timeout=timeout,\n            format=os.environ.get(\"UNITY_MCP_FORMAT\", \"text\"),\n            unity_instance=os.environ.get(\"UNITY_MCP_INSTANCE\"),\n        )\n\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/utils/config.py#L6-L42","documentation":"Thrown by CLIConfig.from_env() when the UNITY_MCP_HTTP_PORT environment variable cannot be parsed as an int. The value defaults to '8080' only when unset; if set to a non-numeric string, int() raises and this ValueError propagates. It fires during CLI startup, before any network call.","triggerScenarios":"Setting UNITY_MCP_HTTP_PORT to a non-integer such as 'abc', '8080/tcp', '' (empty), or '80.0'. Also when a value with surrounding whitespace is supplied on some shells.","commonSituations":"A misconfigured .env file or shell profile exports a port with a unit suffix or typo, or an empty value from an unset-in-template variable. Common when port is templated and the template variable resolved to blank.","solutions":["Set UNITY_MCP_HTTP_PORT to a plain integer (e.g. 8080).","Unset the variable to fall back to the default 8080: `unset UNITY_MCP_HTTP_PORT`.","Audit .env / shell profiles for a stale or empty UNITY_MCP_HTTP_PORT assignment."],"exampleFix":"# before\nexport UNITY_MCP_HTTP_PORT=8080/tcp\n# after\nexport UNITY_MCP_HTTP_PORT=8080","handlingStrategy":"validation","validationCode":"raw = os.environ.get(\"UNITY_MCP_HTTP_PORT\", \"8080\")\nif not raw.isdigit():\n    raise ValueError(f\"Invalid UNITY_MCP_HTTP_PORT value: {raw!r}\")\nport = int(raw)","typeGuard":"def is_int_env(raw: str | None) -> bool:\n    return raw is not None and raw.lstrip(\"+\").isdigit()","tryCatchPattern":"try:\n    cfg = CLIConfig.from_env()\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Keep UNITY_MCP_HTTP_PORT a bare integer in env files.","Avoid unit suffixes and empty values."],"tags":["cli","config","environment","validation"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}