Skip to content

Commit 020fe3f

Browse files
sakurachanclaude
andcommitted
Fix critical regression: restore dict return for reload preflight
The previous commit (2cf6608) introduced a critical regression by returning MCPResponse instead of dict when Unity is reloading. This broke the reload retry loop because _is_reloading_response() only handles dict responses and immediately returns False for non-dict types, causing the retry helper to exit instead of waiting through domain reloads. Changes: - Revert reload preflight return from MCPResponse to dict format - Restore return type annotation to dict[str, Any] (remove | MCPResponse) - Preserve all reload detection fields: success, state, retry_after_ms, error - Applied to both Server/ and MCPForUnity/ versions The dict return format ensures _is_reloading_response() correctly detects reload state via resp.get("state") == "reloading" check, maintaining the polite retry loop behavior during Unity domain reloads. Addresses CodeRabbit critical feedback: - #360 (review) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 2cf6608 commit 020fe3f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

MCPForUnity/UnityMcpServer~/src/unity_connection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def receive_full_response(self, sock, buffer_size=config.buffer_size) -> bytes:
225225
logger.error(f"Error during receive: {str(e)}")
226226
raise
227227

228-
def send_command(self, command_type: str, params: dict[str, Any] | None = None) -> dict[str, Any] | MCPResponse:
228+
def send_command(self, command_type: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
229229
"""Send a command with retry/backoff and port rediscovery. Pings only when requested."""
230230
# Defensive guard: catch empty/placeholder invocations early
231231
if not command_type:
@@ -276,12 +276,12 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
276276
try:
277277
status = read_status_file(target_hash)
278278
if status and (status.get('reloading') or status.get('reason') == 'reloading'):
279-
return MCPResponse(
280-
success=False,
281-
error="Unity domain reload in progress, please try again shortly",
282-
data={"state": "reloading", "retry_after_ms": int(
283-
config.reload_retry_ms)}
284-
)
279+
return {
280+
"success": False,
281+
"state": "reloading",
282+
"retry_after_ms": int(config.reload_retry_ms),
283+
"error": "Unity domain reload in progress, please try again shortly",
284+
}
285285
except Exception:
286286
pass
287287

Server/unity_connection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def receive_full_response(self, sock, buffer_size=config.buffer_size) -> bytes:
225225
logger.error(f"Error during receive: {str(e)}")
226226
raise
227227

228-
def send_command(self, command_type: str, params: dict[str, Any] | None = None) -> dict[str, Any] | MCPResponse:
228+
def send_command(self, command_type: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
229229
"""Send a command with retry/backoff and port rediscovery. Pings only when requested."""
230230
# Defensive guard: catch empty/placeholder invocations early
231231
if not command_type:
@@ -276,12 +276,12 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
276276
try:
277277
status = read_status_file(target_hash)
278278
if status and (status.get('reloading') or status.get('reason') == 'reloading'):
279-
return MCPResponse(
280-
success=False,
281-
error="Unity domain reload in progress, please try again shortly",
282-
data={"state": "reloading", "retry_after_ms": int(
283-
config.reload_retry_ms)}
284-
)
279+
return {
280+
"success": False,
281+
"state": "reloading",
282+
"retry_after_ms": int(config.reload_retry_ms),
283+
"error": "Unity domain reload in progress, please try again shortly",
284+
}
285285
except Exception:
286286
pass
287287

0 commit comments

Comments
 (0)