Skip to main content
mcp-use allows you to handle these notifications by providing a message_handler to the MCPClient.

Server-Side: Sending Notifications

On the server (using fastmcp), you can send notifications from within a tool’s context (ctx). Here’s an example of a tool that sends multiple types of notifications, including progress updates.

Available Notification Types

The fastmcp server context provides several methods for sending specific notifications. Here are the ones you can use and the corresponding type to check for in your client’s message_handler:
  • ctx.report_progress(...) sends a types.ProgressNotification. This is used to report the progress of a long-running operation.
  • ctx.send_tool_list_changed() sends a types.ToolListChangedNotification. This signals that the tool list has changed (see Tools documentation).
  • ctx.send_resource_list_changed() sends a types.ResourceListChangedNotification. This signals that the resource list has changed (see Resources documentation).
  • ctx.send_prompt_list_changed() sends a types.PromptListChangedNotification. This signals that the prompt list has changed (see Prompts documentation).

Client-Side: Handling Notifications

On the client, you create a message_handler function and pass it to the MCPClient. This function will receive all messages from the server, including notifications. Since the message_handler receives all message types (requests, notifications, exceptions), you need to check the type of the incoming message to handle it correctly. Notifications are of type mcp.types.ServerNotification, and their specific type is stored in the .root attribute.
// ⚠️ Notification handlers are not yet supported in the TypeScript library.
// Support is coming soon! If you need this feature now, please open an issue:
// https://github.com/mcp-use/mcp-use

// When supported, the API will look similar to:
/*
import { MCPClient, types } from 'mcp-use'

// The message handler receives all server-sent messages
async function handleMessages(message: any) {
    // Check notification types and handle accordingly
    // ...
}

const config = {
    mcpServers: {
        PrimitiveServer: { url: `${primitiveServer}/mcp` }
    }
}

const client = new MCPClient(config, { messageHandler: handleMessages })
*/
The message_handler is a powerful catch-all for any message from the server. By inspecting the message type, you can build rich, responsive applications that react to server-side events in real time.