Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990---title: messagessidebarTitle: messages---
# `fastmcp.client.messages`
## Classes
### `MessageHandler` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L11" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
This class is used to handle MCP messages sent to the client: notificationsand transport-level exceptions. Users can override any of the hooks.
Server-initiated *requests* (ping, sampling, roots) never reach thishandler: the stable MCP SDK v2's `message_handler` contract only delivers`ServerNotification | Exception`, so a request has no wire path here.Those are answered through the `Client`'s dedicated callbacks instead —`sampling_handler=`, `roots=`, and `elicitation_handler=`.
**Methods:**
#### `dispatch` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L26" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythondispatch(self, message: Message) -> None```
#### `on_message` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_message(self, message: Message) -> None```
#### `on_notification` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L57" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_notification(self, message: mcp_types.ServerNotification) -> None```
#### `on_exception` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_exception(self, message: Exception) -> None```
#### `on_progress` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L63" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_progress(self, message: mcp_types.ProgressNotification) -> None```
#### `on_logging_message` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L66" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_logging_message(self, message: mcp_types.LoggingMessageNotification) -> None```
#### `on_tool_list_changed` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L71" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_tool_list_changed(self, message: mcp_types.ToolListChangedNotification) -> None```
#### `on_resource_list_changed` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_resource_list_changed(self, message: mcp_types.ResourceListChangedNotification) -> None```
#### `on_prompt_list_changed` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L81" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_prompt_list_changed(self, message: mcp_types.PromptListChangedNotification) -> None```
#### `on_resource_updated` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L86" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_resource_updated(self, message: mcp_types.ResourceUpdatedNotification) -> None```
#### `on_cancelled` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/client/messages.py#L91" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonon_cancelled(self, message: mcp_types.CancelledNotification) -> None```