Skip to content

Commit e37d8aa

Browse files
authored
fix: close SSE stream writers in terminate() to allow graceful completion
1 parent 686d483 commit e37d8aa

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/mcp/server/streamable_http.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,11 @@ async def terminate(self) -> None:
771771
self._terminated = True
772772
logger.info(f"Terminating session: {self.mcp_session_id}")
773773

774+
# Close all SSE stream writers to allow EventSourceResponse to complete gracefully
775+
for writer in list(self._sse_stream_writers.values()):
776+
writer.close()
777+
self._sse_stream_writers.clear()
778+
774779
# We need a copy of the keys to avoid modification during iteration
775780
request_stream_keys = list(self._request_streams.keys())
776781

0 commit comments

Comments
 (0)