Skip to content

Commit af37bcc

Browse files
committed
Fix
1 parent c76d0bb commit af37bcc

5 files changed

Lines changed: 19 additions & 15 deletions

File tree

MCPForUnity/Editor/Resources/Editor/ToolStates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static object HandleCommand(JObject @params)
4949
["is_built_in"] = tool.IsBuiltIn,
5050
["structured_output"] = tool.StructuredOutput,
5151
["requires_polling"] = tool.RequiresPolling,
52-
["poll_action"] = tool.PollAction,
52+
["poll_action"] = tool.PollAction ?? "status",
5353
["max_poll_seconds"] = tool.MaxPollSeconds,
5454
["parameters"] = paramsArray
5555
});

MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ private async Task SendRegisterToolsAsync(CancellationToken token)
540540
["description"] = tool.Description,
541541
["structured_output"] = tool.StructuredOutput,
542542
["requires_polling"] = tool.RequiresPolling,
543-
["poll_action"] = tool.PollAction,
543+
["poll_action"] = tool.PollAction ?? "status",
544544
["max_poll_seconds"] = tool.MaxPollSeconds,
545545
["group"] = string.IsNullOrWhiteSpace(tool.Group) ? "core" : tool.Group
546546
};

Server/src/services/tools/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ async def sync_tool_visibility_from_unity(
193193
name=p.get("name", ""),
194194
description=p.get("description", ""),
195195
type=p.get("type", "string"),
196-
required=p.get("required", False),
196+
required=p.get("required", True),
197197
default_value=p.get("default_value"),
198198
)
199199
for p in td.get("parameters", [])
@@ -204,7 +204,7 @@ async def sync_tool_visibility_from_unity(
204204
description=td.get("description", ""),
205205
structured_output=td.get("structured_output", True),
206206
requires_polling=td.get("requires_polling", False),
207-
poll_action=td.get("poll_action", "status"),
207+
poll_action=td.get("poll_action") or "status",
208208
max_poll_seconds=td.get("max_poll_seconds", 0),
209209
parameters=params,
210210
)

Server/src/transport/legacy/unity_connection.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -945,19 +945,23 @@ async def async_send_command_with_retry(
945945
# After a successful command, check if the connection was freshly
946946
# established (reconnection after domain reload). If so, re-sync
947947
# tool visibility and custom tool registration from Unity.
948-
# Skip if *this* call is the sync itself to avoid recursion.
949-
if command_type != "get_tool_states":
950-
try:
951-
pool = get_unity_connection_pool()
952-
conn = pool.get_connection(instance_id)
953-
if getattr(conn, "_needs_tool_resync", False):
954-
conn._needs_tool_resync = False
948+
# Always clear the flag, but only schedule the background resync
949+
# when this call is not itself get_tool_states (to avoid recursion).
950+
try:
951+
pool = get_unity_connection_pool()
952+
conn = pool.get_connection(instance_id)
953+
if getattr(conn, "_needs_tool_resync", False):
954+
conn._needs_tool_resync = False
955+
if command_type != "get_tool_states":
955956
logger.info(
956957
"Detected reconnection to Unity; scheduling tool re-sync"
957958
)
958959
asyncio.ensure_future(_resync_tools_after_reconnect(instance_id))
959-
except Exception:
960-
pass # Best-effort; don't fail the actual command
960+
except Exception as exc:
961+
logger.debug(
962+
"Failed to schedule post-reconnection tool re-sync: %s",
963+
exc,
964+
)
961965

962966
return result
963967
except Exception as e:

Server/tests/integration/test_stdio_custom_tool_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ async def test_no_resync_for_get_tool_states():
240240
from transport.legacy.unity_connection import async_send_command_with_retry
241241
await async_send_command_with_retry("get_tool_states", {})
242242

243-
# Flag should NOT be cleared — get_tool_states is excluded
244-
assert mock_conn._needs_tool_resync is True
243+
# Flag should be cleared, but no re-sync task should be scheduled
244+
assert mock_conn._needs_tool_resync is False
245245
mock_resync.assert_not_awaited()
246246

247247

0 commit comments

Comments
 (0)