Skip to content

Commit abda067

Browse files
committed
add decorator for handling cancelation
1 parent dfb3686 commit abda067

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/mcp/server/lowlevel/server.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,22 @@ async def handler(req: types.ProgressNotification):
441441

442442
return decorator
443443

444+
def cancel_notification(self):
445+
def decorator(
446+
func: Callable[[str | int, str | None], Awaitable[None]],
447+
):
448+
logger.debug("Registering handler for ProgressNotification")
449+
450+
async def handler(req: types.CancelledNotification):
451+
await func(
452+
req.params.requestId, req.params.reason
453+
)
454+
455+
self.notification_handlers[types.CancelledNotification] = handler
456+
return func
457+
458+
return decorator
459+
444460
def completion(self):
445461
"""Provides completions for prompts and resource templates"""
446462

@@ -587,12 +603,14 @@ async def _handle_notification(self, notify: Any):
587603
assert type(notify) in self.notification_handlers
588604

589605
handler = self.notification_handlers[type(notify)]
590-
logger.debug(f"Dispatching notification of type {type(notify).__name__}")
606+
print(f"Dispatching notification of type {type(notify).__name__}")
591607

592608
try:
593609
await handler(notify)
594610
except Exception as err:
595611
logger.error(f"Uncaught exception in notification handler: {err}")
612+
else:
613+
print(f"Not handling {notify}")
596614

597615

598616
async def _ping_handler(request: types.PingRequest) -> types.ServerResult:

0 commit comments

Comments
 (0)