From 2a65c0848e8815a50135ce266b515a46c36807f3 Mon Sep 17 00:00:00 2001 From: davenpi Date: Thu, 22 May 2025 17:52:39 -0400 Subject: [PATCH] Feat(client): add cancel notification method --- src/fastmcp/client/client.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/fastmcp/client/client.py b/src/fastmcp/client/client.py index 19552ea35..f6333fb08 100644 --- a/src/fastmcp/client/client.py +++ b/src/fastmcp/client/client.py @@ -210,6 +210,23 @@ class Client: result = await self.session.send_ping() return isinstance(result, mcp.types.EmptyResult) + async def cancel( + self, + request_id: str | int, + reason: str | None = None, + ) -> None: + """Send a cancellation notification for an in-progress request.""" + notification = mcp.types.ClientNotification( + mcp.types.CancelledNotification( + method="notifications/cancelled", + params=mcp.types.CancelledNotificationParams( + requestId=request_id, + reason=reason, + ), + ) + ) + await self.session.send_notification(notification) + async def progress( self, progress_token: str | int,