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

Method _handle_cli_message

relay/server.py:448–492  ·  view source on GitHub ↗

Handle a CLI message

(
        self,
        writer: asyncio.StreamWriter,
        msg: dict[str, Any],
    )

Source from the content-addressed store, hash-verified

446 # ===== CLI Message Handling =====
447
448 async def _handle_cli_message(
449 self,
450 writer: asyncio.StreamWriter,
451 msg: dict[str, Any],
452 ) -> None:
453 """Handle a CLI message"""
454 msg_type = msg.get("type")
455 request_id = msg.get("id", "")
456
457 if msg_type == MessageType.LIST_INSTANCES.value:
458 response = InstancesMessage(
459 id=request_id,
460 success=True,
461 data={"instances": self.registry.list_all()},
462 )
463 await write_frame(writer, response.to_dict())
464
465 elif msg_type == MessageType.SET_DEFAULT.value:
466 instance_id = msg.get("instance", "")
467 success = self.registry.set_default(instance_id)
468 if success:
469 response = ResponseMessage(
470 id=request_id,
471 success=True,
472 data={"message": f"Default instance set to {instance_id}"},
473 )
474 else:
475 response = ErrorMessage.from_code(
476 request_id,
477 ErrorCode.INSTANCE_NOT_FOUND,
478 f"Instance not found: {instance_id}. Check available instances with 'u instances'.",
479 )
480 await write_frame(writer, response.to_dict())
481
482 elif msg_type == MessageType.REQUEST.value:
483 response = await self._handle_request(msg)
484 await write_frame(writer, response)
485
486 else:
487 response = ErrorMessage.from_code(
488 request_id,
489 ErrorCode.PROTOCOL_ERROR,
490 f"Unknown message type: {msg_type}",
491 )
492 await write_frame(writer, response.to_dict())
493
494 async def _handle_request(self, msg: dict[str, Any]) -> dict[str, Any]:
495 """Handle a REQUEST message from CLI"""

Callers 1

_handle_connectionMethod · 0.95

Calls 9

_handle_requestMethod · 0.95
InstancesMessageClass · 0.85
write_frameFunction · 0.85
ResponseMessageClass · 0.85
list_allMethod · 0.80
set_defaultMethod · 0.80
from_codeMethod · 0.80
getMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected