Skip to content

Commit f96aaa5

Browse files
committed
Add docstring info for cancellable and add TODO note for initialised which states that initialised is not cancellable as per https://modelcontextprotocol.io/specification/2025-03-26/basic/utilities/cancellation
1 parent 235df35 commit f96aaa5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/mcp/client/session.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ async def initialize(self) -> types.InitializeResult:
140140
)
141141
),
142142
types.InitializeResult,
143+
# TODO should set a request_read_timeout_seconds as per
144+
# guidance from BaseSession.send_request not obvious
145+
# what subsequent process should be, refer the following
146+
# specification for more details
147+
# https://modelcontextprotocol.io/specification/2025-03-26/basic/utilities/cancellation
143148
cancellable=False,
144149
)
145150

src/mcp/shared/session.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ async def send_request(
229229
response contains an error. If a request read timeout is provided, it
230230
will take precedence over the session read timeout.
231231
232+
If cancellable is set to False then the request will wait
233+
request_read_timeout_seconds to complete and ignore any attempt to
234+
cancel via the anyio.CancelScope within which this method was called.
235+
236+
If cancellable is set to True (default) if the anyio.CancelScope within
237+
which this method was called is cancelled it will generate a
238+
CancelationNotfication and send this to the server which should then abort
239+
the task however this is not guaranteed.
240+
241+
For further information on the CancelNotification flow refer to
242+
https://modelcontextprotocol.io/specification/2025-03-26/basic/utilities/cancellation
243+
232244
Do not use this method to emit notifications! Use send_notification()
233245
instead.
234246
"""

0 commit comments

Comments
 (0)