From 2a5dd5d5b6c83dc600eefd6086a0c84c30f110bd Mon Sep 17 00:00:00 2001 From: Ratish1 Date: Fri, 26 Dec 2025 17:17:26 +0400 Subject: [PATCH] fix(mcp): prevent agent hang by checking session closure state --- src/strands/tools/mcp/mcp_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/strands/tools/mcp/mcp_client.py b/src/strands/tools/mcp/mcp_client.py index 6ce591bc5..fed635fbc 100644 --- a/src/strands/tools/mcp/mcp_client.py +++ b/src/strands/tools/mcp/mcp_client.py @@ -801,4 +801,10 @@ def _matches_patterns(self, tool: MCPAgentTool, patterns: list[_ToolMatcher]) -> return False def _is_session_active(self) -> bool: - return self._background_thread is not None and self._background_thread.is_alive() + if self._background_thread is None or not self._background_thread.is_alive(): + return False + + if self._close_future is not None and self._close_future.done(): + return False + + return True