{"record":{"id":"3627692ba43559ce","repo":"CoplayDev/unity-mcp","slug":"http-transport-requires-command-arguments","errorCode":null,"errorMessage":"HTTP transport requires command arguments","messagePattern":"HTTP transport requires command arguments","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/transport/unity_transport.py","lineNumber":51,"sourceCode":"            return None\n        service = ApiKeyService.get_instance()\n        result = await service.validate(api_key)\n        return result.user_id if result.valid else None\n    except Exception as e:\n        logger.debug(\"Failed to resolve user_id from HTTP request: %s\", e)\n        return None\n\n\nasync def send_with_unity_instance(\n    send_fn: Callable[..., Awaitable[T]],\n    unity_instance: str | None,\n    *args,\n    user_id: str | None = None,\n    **kwargs,\n) -> T:\n    if _is_http_transport():\n        if not args:\n            raise ValueError(\"HTTP transport requires command arguments\")\n        command_type = args[0]\n        params = args[1] if len(args) > 1 else kwargs.get(\"params\")\n        if params is None:\n            params = {}\n        if not isinstance(params, dict):\n            raise TypeError(\n                \"Command parameters must be a dict for HTTP transport\")\n\n        # Auto-resolve user_id from HTTP request API key (remote-hosted mode)\n        if user_id is None:\n            user_id = await _resolve_user_id_from_request()\n\n        # Auth check\n        if config.http_remote_hosted and not user_id:\n            return normalize_unity_response(\n                MCPResponse(\n                    success=False,\n                    error=\"auth_required\",","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/transport/unity_transport.py#L33-L69","documentation":"Raised by send_with_unity_instance when the server is in HTTP transport mode but the caller passed no positional arguments, so there is no command_type to send. The HTTP code path needs at least the command name as args[0]; without it the request cannot be constructed.","triggerScenarios":"_is_http_transport() is true and the function was called as send_with_unity_instance(send_fn, instance) with nothing in *args. The guard at unity_transport.py:49-50 fires.","commonSituations":"A tool wrapper called send_with_unity_instance passing command_type and params only as kwargs (command_type=, params=) instead of positionally; refactor forgot the leading positional command name.","solutions":["Pass the command_type as the first positional arg: send_with_unity_instance(send_fn, instance, 'manage_gameobject', params).","If authoring a wrapper, assert args is non-empty before dispatching in HTTP mode.","Keep the stdio and HTTP call signatures identical (both positional) to avoid this branch."],"exampleFix":"// before\nawait send_with_unity_instance(send_fn, instance, command_type='manage_gameobject', params=p)\n// after\nawait send_with_unity_instance(send_fn, instance, 'manage_gameobject', p)","handlingStrategy":"validation","validationCode":"if _is_http_transport() and not args:\n    raise ValueError('command_type is required as the first positional arg in HTTP mode')","typeGuard":"def has_command_type(args: tuple) -> bool:\n    return len(args) >= 1","tryCatchPattern":"try:\n    await send_with_unity_instance(send_fn, instance, *args)\nexcept ValueError as e:\n    if 'requires command arguments' in str(e):\n        await send_with_unity_instance(send_fn, instance, command_type, params)","preventionTips":["Always pass command_type as the first positional argument","Keep call signatures identical across stdio and HTTP","Wrap send_with_unity_instance once and reuse the wrapper"],"tags":["transport","http","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}