MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / _execute_command

Method _execute_command

relay/server.py:653–736  ·  view source on GitHub ↗

Execute a command on a Unity instance

(
        self,
        request_id: str,
        instance_id: str | None,
        command: str,
        params: dict[str, Any],
        timeout_ms: int,
    )

Source from the content-addressed store, hash-verified

651 ).to_dict()
652
653 async def _execute_command(
654 self,
655 request_id: str,
656 instance_id: str | None,
657 command: str,
658 params: dict[str, Any],
659 timeout_ms: int,
660 ) -> dict[str, Any]:
661 """Execute a command on a Unity instance"""
662 result = await self._wait_for_instance(request_id, instance_id)
663 if isinstance(result, dict):
664 return result
665 instance = result
666
667 if instance.capabilities and command not in instance.capabilities:
668 return ErrorMessage.from_code(
669 request_id,
670 ErrorCode.CAPABILITY_NOT_SUPPORTED,
671 f"Command '{command}' not supported by instance. Available: {', '.join(instance.capabilities)}",
672 ).to_dict()
673
674 if instance.status == InstanceStatus.BUSY:
675 return await self._enqueue_command(request_id, instance, command, params, timeout_ms)
676
677 # Send command to Unity
678 cmd_msg = CommandMessage(
679 id=request_id,
680 command=command,
681 params=params,
682 timeout_ms=timeout_ms,
683 )
684
685 # Create future for response
686 future: asyncio.Future[dict[str, Any]] = asyncio.Future()
687 self._pending_commands[request_id] = future
688 logger.info(f"Registered pending command: {request_id}")
689
690 # Set instance to BUSY
691 instance.set_status(InstanceStatus.BUSY)
692
693 try:
694 await write_frame(instance.writer, cmd_msg.to_dict())
695
696 # Wait for response
697 result = await asyncio.wait_for(
698 future,
699 timeout=timeout_ms / 1000,
700 )
701
702 # Convert COMMAND_RESULT to RESPONSE
703 return ResponseMessage(
704 id=request_id,
705 success=result.get("success", False),
706 data=result.get("data"),
707 error=result.get("error"),
708 relay_version=self._relay_version,
709 bridge_version=instance.bridge_version,
710 ).to_dict()

Callers 2

_process_queueMethod · 0.95
_handle_requestMethod · 0.95

Calls 11

_wait_for_instanceMethod · 0.95
_enqueue_commandMethod · 0.95
_process_queueMethod · 0.95
CommandMessageClass · 0.85
write_frameFunction · 0.85
ResponseMessageClass · 0.85
from_codeMethod · 0.80
infoMethod · 0.80
set_statusMethod · 0.80
to_dictMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected