Skip to content

Commit 7ed8dd1

Browse files
author
David Padbury
committed
fix: close mcp client event loop
1 parent a64a851 commit 7ed8dd1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/strands/tools/mcp/mcp_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,11 @@ def _background_task(self) -> None:
638638
"""
639639
self._log_debug_with_thread("setting up background task event loop")
640640
self._background_thread_event_loop = asyncio.new_event_loop()
641-
asyncio.set_event_loop(self._background_thread_event_loop)
642-
self._background_thread_event_loop.run_until_complete(self._async_background_thread())
641+
try:
642+
asyncio.set_event_loop(self._background_thread_event_loop)
643+
self._background_thread_event_loop.run_until_complete(self._async_background_thread())
644+
finally:
645+
self._background_thread_event_loop.close()
643646

644647
def _map_mcp_content_to_tool_result_content(
645648
self,

0 commit comments

Comments
 (0)