Skip to content

Commit 889aa0f

Browse files
author
Soham Dahivalkar
committed
docs: add missing docstrings to core public API methods
Add docstrings to undocumented public methods in the client and server session modules: - ClientSession.initialize(): document handshake flow, return type, and RuntimeError on unsupported protocol version - ServerSession.client_params: document property returning client's InitializeRequestParams - ServerSession.incoming_messages: document the ServerRequestResponder stream property - remove_request_params(): document URL query-stripping utility These are the most user-facing public methods that currently lack docstrings, making IDE tooltips and help() output incomplete.
1 parent 616476f commit 889aa0f

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/mcp/client/session.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ def _receive_notification_adapter(self) -> TypeAdapter[types.ServerNotification]
146146
return types.server_notification_adapter
147147

148148
async def initialize(self) -> types.InitializeResult:
149+
"""Perform the MCP initialization handshake with the server.
150+
151+
Sends an InitializeRequest with the client's capabilities (sampling,
152+
elicitation, roots, tasks) and client_info, waits for the server's
153+
InitializeResult, validates the negotiated protocol version, stores
154+
the result, and sends an InitializedNotification.
155+
156+
Returns:
157+
The server's InitializeResult containing server_info,
158+
capabilities, instructions, and the negotiated protocol_version.
159+
160+
Raises:
161+
RuntimeError: If the server returns an unsupported protocol version.
162+
"""
149163
sampling = (
150164
(self._sampling_capabilities or types.SamplingCapability())
151165
if self._sampling_callback is not _default_sampling_callback

src/mcp/client/sse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919

2020
def remove_request_params(url: str) -> str:
21+
"""Strip query parameters from a URL, returning only scheme + host + path.
22+
23+
Used to derive the base endpoint URL from an SSE connection URL that may
24+
include session identifiers or other transient query parameters.
25+
"""
2126
return urljoin(url, urlparse(url).path)
2227

2328

src/mcp/server/session.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def _receive_notification_adapter(self) -> TypeAdapter[types.ClientNotification]
107107

108108
@property
109109
def client_params(self) -> types.InitializeRequestParams | None:
110+
"""The client's InitializeRequestParams received during handshake.
111+
112+
Contains client_info, capabilities, and the requested protocol_version.
113+
Returns None if the session has not yet been initialized.
114+
"""
110115
return self._client_params
111116

112117
@property
@@ -689,4 +694,9 @@ async def _handle_incoming(self, req: ServerRequestResponder) -> None:
689694

690695
@property
691696
def incoming_messages(self) -> MemoryObjectReceiveStream[ServerRequestResponder]:
697+
"""Stream of incoming client requests wrapped as ServerRequestResponder objects.
698+
699+
Each item in the stream pairs the original client request with a
700+
responder that the server handler uses to send back a result or error.
701+
"""
692702
return self._incoming_message_stream_reader

0 commit comments

Comments
 (0)