/
CyberSys
/
unity-mcp-bridge
Обзор
Документация
Войти
/
CyberSys
/
unity-mcp-bridge
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Server/src/models/unity_response.py
47 строк
1 KB
Marcus Sanatan
HTTP Server, uvx, C# only custom tools (#375)
25 ноя 2025, 06:21
Не верифицирован
25 ноя 2025, 06:21
a034ab0
Код
Авторство
О чём код?
"""Utilities for normalizing Unity transport responses.""" from __future__ import annotations from typing import Any def normalize_unity_response(response: Any) -> Any: """Normalize Unity's {status,result} payloads into MCPResponse shape.""" if not isinstance(response, dict): return response status = response.get("status") result = response.get("result") if isinstance( response.get("result"), dict) else response.get("result") # Already MCPResponse-shaped if "success" in response: return response if isinstance(result, dict) and "success" in result: return result if status is None: return response payload = result if isinstance(result, dict) else {} success = status == "success" message = payload.get("message") or response.get("message") error = payload.get("error") or response.get("error") data = payload.get("data") if data is None and isinstance(payload, dict) and payload: data = {k: v for k, v in payload.items() if k not in { "message", "error", "status", "code"}} if not data: data = None normalized: dict[str, Any] = { "success": success, "message": message, "error": error if not success else None, "data": data, } if not success and not normalized["error"]: normalized["error"] = message or "Unity command failed" return normalized