Skip to content

Commit e0fa11f

Browse files
sakurachanclaude
andcommitted
Fix status file timing issue and restore parameterless command support
- Fix status file timing issue: Remove fallback to most recent file when target hash not found This prevents reading wrong instance's status in multi-instance scenarios - Fix broken parameterless commands: Convert None params to empty dict instead of returning error This restores support for commands like 'ping' that don't require parameters - Update type annotation: Use explicit `dict[str, Any] | None` instead of implicit Optional Addresses critical feedback from maintainer and CodeRabbit review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 328ff49 commit e0fa11f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

MCPForUnity/UnityMcpServer~/src/unity_connection.py

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

229-
def send_command(self, command_type: str, params: dict[str, Any] = None) -> dict[str, Any]:
229+
def send_command(self, command_type: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
230230
"""Send a command with retry/backoff and port rediscovery. Pings only when requested."""
231231
# Defensive guard: catch empty/placeholder invocations early
232232
if not command_type:
233233
raise ValueError("MCP call missing command_type")
234234
if params is None:
235-
return MCPResponse(success=False, error="MCP call received with no parameters (client placeholder?)")
235+
params = {}
236236
attempts = max(config.max_retries, 5)
237237
base_backoff = max(0.5, config.retry_delay)
238238

@@ -251,7 +251,10 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
251251
if status_path.stem.endswith(target_hash):
252252
with status_path.open('r') as f:
253253
return json.load(f)
254-
# Fallback: return most recent regardless of hash
254+
# Target hash not found - don't fallback to avoid reading wrong instance's status
255+
logger.debug(f"Status file for hash '{target_hash}' not found, available: {[p.stem for p in status_files[:3]]}")
256+
return None
257+
# Only return most recent when no specific hash requested
255258
with status_files[0].open('r') as f:
256259
return json.load(f)
257260
except Exception:

Server/unity_connection.py

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

229-
def send_command(self, command_type: str, params: dict[str, Any] = None) -> dict[str, Any]:
229+
def send_command(self, command_type: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
230230
"""Send a command with retry/backoff and port rediscovery. Pings only when requested."""
231231
# Defensive guard: catch empty/placeholder invocations early
232232
if not command_type:
233233
raise ValueError("MCP call missing command_type")
234234
if params is None:
235-
return MCPResponse(success=False, error="MCP call received with no parameters (client placeholder?)")
235+
params = {}
236236
attempts = max(config.max_retries, 5)
237237
base_backoff = max(0.5, config.retry_delay)
238238

@@ -251,7 +251,10 @@ def read_status_file(target_hash: str | None = None) -> dict | None:
251251
if status_path.stem.endswith(target_hash):
252252
with status_path.open('r') as f:
253253
return json.load(f)
254-
# Fallback: return most recent regardless of hash
254+
# Target hash not found - don't fallback to avoid reading wrong instance's status
255+
logger.debug(f"Status file for hash '{target_hash}' not found, available: {[p.stem for p in status_files[:3]]}")
256+
return None
257+
# Only return most recent when no specific hash requested
255258
with status_files[0].open('r') as f:
256259
return json.load(f)
257260
except Exception:

0 commit comments

Comments
 (0)