2.9.1
Use this when you need to react to server-side changes like tool list updates or resource modifications.
MCP servers can send notifications to inform clients about state changes. The message handler provides a unified way to process these notifications.
Handling Notifications
The simplest approach is a function that receives all messages and filters for the notifications you care about:MessageHandler Class
For fine-grained targeting, subclassMessageHandler to use specific hooks:
Handler Template
List Change Notifications
A practical example of maintaining a tool cache that refreshes when tools change:Server Requests
While the message handler receives server-initiated requests, you should use dedicated callback parameters for most interactive scenarios:- Sampling requests: Use
sampling_handler - Elicitation requests: Use
elicitation_handler - Progress updates: Use
progress_handler - Log messages: Use
log_handler

