From 198df553eb399edf901a64f58babe739dbafdd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=9A=80=20Jack?= Date: Tue, 5 May 2026 21:58:15 +1000 Subject: [PATCH 1/2] fix: correct MCPClient.__exit__ and stop() type annotations Fixes #2247 --- src/strands/tools/mcp/mcp_client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/strands/tools/mcp/mcp_client.py b/src/strands/tools/mcp/mcp_client.py index 1884ce9bc..080983d7a 100644 --- a/src/strands/tools/mcp/mcp_client.py +++ b/src/strands/tools/mcp/mcp_client.py @@ -178,7 +178,12 @@ def __enter__(self) -> "MCPClient": """ return self.start() - def __exit__(self, exc_type: BaseException, exc_val: BaseException, exc_tb: TracebackType) -> None: + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + exc_tb: TracebackType | None, + ) -> None: """Context manager exit point that cleans up resources.""" self.stop(exc_type, exc_val, exc_tb) @@ -318,7 +323,7 @@ def remove_consumer(self, consumer_id: Any, **kwargs: Any) -> None: # MCP-specific methods - def stop(self, exc_type: BaseException | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None: + def stop(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None: """Signals the background thread to stop and waits for it to complete, ensuring proper cleanup of all resources. This method is defensive and can handle partial initialization states that may occur From ac77634b525697091f8d0b9af62c2c300ed6bb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=9A=80=20Jack?= Date: Wed, 6 May 2026 05:44:42 +1000 Subject: [PATCH 2/2] fix: format stop() signature to satisfy line length lint --- src/strands/tools/mcp/mcp_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/strands/tools/mcp/mcp_client.py b/src/strands/tools/mcp/mcp_client.py index 080983d7a..270012fde 100644 --- a/src/strands/tools/mcp/mcp_client.py +++ b/src/strands/tools/mcp/mcp_client.py @@ -323,7 +323,12 @@ def remove_consumer(self, consumer_id: Any, **kwargs: Any) -> None: # MCP-specific methods - def stop(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None: + def stop( + self, + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + exc_tb: TracebackType | None, + ) -> None: """Signals the background thread to stop and waits for it to complete, ensuring proper cleanup of all resources. This method is defensive and can handle partial initialization states that may occur