Skip to content

Commit f83df9d

Browse files
committed
Merge branch 'main' into ihrpr/server-closing-streams
2 parents 526ddff + 74f5fcf commit f83df9d

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/mcp/client/session.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import mcp.types as types
99
from mcp.shared.context import RequestContext
10-
from mcp.shared.message import (
11-
SessionMessage,
12-
)
10+
from mcp.shared.message import SessionMessage
1311
from mcp.shared.session import BaseSession, RequestResponder
1412
from mcp.shared.version import SUPPORTED_PROTOCOL_VERSIONS
1513

src/mcp/server/lowlevel/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,11 @@ async def run(
480480
# but also make tracing exceptions much easier during testing and when using
481481
# in-process servers.
482482
raise_exceptions: bool = False,
483-
# When True, the server runs in standalone mode for stateless deployments where
483+
# When True, the server is stateless and
484484
# clients can perform initialization with any node. The client must still follow
485485
# the initialization lifecycle, but can do so with any available node
486486
# rather than requiring initialization for each connection.
487-
standalone_mode: bool = False,
487+
stateless: bool = False,
488488
):
489489
async with AsyncExitStack() as stack:
490490
lifespan_context = await stack.enter_async_context(self.lifespan(self))
@@ -493,7 +493,7 @@ async def run(
493493
read_stream,
494494
write_stream,
495495
initialization_options,
496-
standalone_mode=standalone_mode,
496+
stateless=stateless,
497497
)
498498
)
499499

src/mcp/server/session.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ def __init__(
8686
read_stream: MemoryObjectReceiveStream[SessionMessage | Exception],
8787
write_stream: MemoryObjectSendStream[SessionMessage],
8888
init_options: InitializationOptions,
89-
standalone_mode: bool = False,
89+
stateless: bool = False,
9090
) -> None:
9191
super().__init__(
9292
read_stream, write_stream, types.ClientRequest, types.ClientNotification
9393
)
94-
if standalone_mode:
95-
self._initialization_state = InitializationState.Initialized
96-
else:
97-
self._initialization_state = InitializationState.NotInitialized
94+
self._initialization_state = (
95+
InitializationState.Initialized
96+
if stateless
97+
else InitializationState.NotInitialized
98+
)
99+
98100
self._init_options = init_options
99101
self._incoming_message_stream_writer, self._incoming_message_stream_reader = (
100102
anyio.create_memory_object_stream[ServerRequestResponder](0)

src/mcp/server/streamable_http.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,9 @@ async def _handle_get_request(self, request: Request, send: Send) -> None:
560560
if not await self._validate_session(request, send):
561561
return
562562
# Handle resumability: check for Last-Event-ID header
563-
if self._event_store:
564-
last_event_id = request.headers.get(LAST_EVENT_ID_HEADER)
565-
if last_event_id:
566-
await self._replay_events(last_event_id, request, send)
567-
return
563+
if last_event_id := request.headers.get(LAST_EVENT_ID_HEADER):
564+
await self._replay_events(last_event_id, request, send)
565+
return
568566

569567
headers = {
570568
"Cache-Control": "no-cache, no-transform",

0 commit comments

Comments
 (0)