Skip to content

Commit b8cb367

Browse files
authored
Close server session after handle stateless request (#1116)
1 parent a10fec7 commit b8cb367

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/mcp/server/streamable_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,15 @@ async def _handle_delete_request(self, request: Request, send: Send) -> None:
612612
if not await self._validate_request_headers(request, send):
613613
return
614614

615-
await self._terminate_session()
615+
await self.terminate()
616616

617617
response = self._create_json_response(
618618
None,
619619
HTTPStatus.OK,
620620
)
621621
await response(request.scope, request.receive, send)
622622

623-
async def _terminate_session(self) -> None:
623+
async def terminate(self) -> None:
624624
"""Terminate the current session, closing all streams.
625625
626626
Once terminated, all requests with this session ID will receive 404 Not Found.

src/mcp/server/streamable_http_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ async def run_stateless_server(*, task_status: TaskStatus[None] = anyio.TASK_STA
190190
# Handle the HTTP request and return the response
191191
await http_transport.handle_request(scope, receive, send)
192192

193+
# Terminate the transport after the request is handled
194+
await http_transport.terminate()
195+
193196
async def _handle_stateful_request(
194197
self,
195198
scope: Scope,

0 commit comments

Comments
 (0)