Skip to content

Commit 1387929

Browse files
committed
rename require_initialization to standalone_mode
1 parent 58745c7 commit 1387929

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

examples/servers/simple-streamablehttp-stateless/mcp_simple_streamablehttp_stateless/server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ async def run_server():
141141
read_stream,
142142
write_stream,
143143
app.create_initialization_options(),
144-
# This allows the server to run without waiting for initialization
145-
require_initialization=False,
144+
# Runs in standalone mode for stateless deployments
145+
# where clients perform initialization with any node
146+
standalone_mode=True,
146147
)
147148

148149
# Start server task

src/mcp/server/lowlevel/server.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,11 @@ async def run(
479479
# but also make tracing exceptions much easier during testing and when using
480480
# in-process servers.
481481
raise_exceptions: bool = False,
482-
# When True, the server will wait for the client to send an initialization
483-
# message before processing any other messages.
484-
# False should be used for stateless servers.
485-
require_initialization: bool = True,
482+
# When True, the server runs in standalone mode for stateless deployments where
483+
# clients can perform initialization with any node. The client must still follow
484+
# the initialization lifecycle, but can do so with any available node
485+
# rather than requiring initialization for each connection.
486+
standalone_mode: bool = False,
486487
):
487488
async with AsyncExitStack() as stack:
488489
lifespan_context = await stack.enter_async_context(self.lifespan(self))
@@ -491,7 +492,7 @@ async def run(
491492
read_stream,
492493
write_stream,
493494
initialization_options,
494-
require_initialization,
495+
standalone_mode=standalone_mode,
495496
)
496497
)
497498

src/mcp/server/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def __init__(
8585
read_stream: MemoryObjectReceiveStream[types.JSONRPCMessage | Exception],
8686
write_stream: MemoryObjectSendStream[types.JSONRPCMessage],
8787
init_options: InitializationOptions,
88-
require_initialization: bool = True,
88+
standalone_mode: bool = False,
8989
) -> None:
9090
super().__init__(
9191
read_stream, write_stream, types.ClientRequest, types.ClientNotification
9292
)
93-
if require_initialization:
94-
self._initialization_state = InitializationState.NotInitialized
95-
else:
93+
if standalone_mode:
9694
self._initialization_state = InitializationState.Initialized
95+
else:
96+
self._initialization_state = InitializationState.NotInitialized
9797
self._init_options = init_options
9898
self._incoming_message_stream_writer, self._incoming_message_stream_reader = (
9999
anyio.create_memory_object_stream[ServerRequestResponder](0)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)