Model Context Protocol – Advanced Patterns for Production By the end of this lesson, students should be able to: What notifications are. MCP notifications are server-to-client messages that do not require a response. They inform the client that something has changed – a resource has been updated, the tool list has changed, a long-running operation has progressed. Clients can act on notifications or ignore them based on their implementation. When to use notifications vs. polling. Without notifications, clients poll the server for changes – sending list_resources or list_tools requests periodically to check for updates. For resources that change infrequently, polling wastes transport overhead. For resources that change frequently, polling may miss changes between intervals. Notifications are appropriate when: Resource change notifications. “`python await app.notify_resource_updated("docs://api-reference") await app.notify_resources_list_changed() “` Clients that receive a resource update notification can re-read the resource to get fresh content. Clients that receive a resource list changed notification can re-request the resource list. Tool list change notifications. “`python await app.notify_tools_list_changed() “` Use this when your server dynamically enables or disables tools based on state – for example, a tool that is only available after the user has authenticated, or a tool that is disabled when a dependent service is unavailable. Progress notifications for long-running tools. For tools that take significant time (database migrations, large file processing, report generation), progress notifications let the client track status without the tool call blocking: “`python await app.notify_progress(token, current=50, total=100) “` Clients can surface progress to the user in real time. Verify current progress notification API at modelcontextprotocol.io. A developer builds a document monitoring MCP server that watches a directory for file changes. When a file changes, the server sends a resource update notification for that file's resource URI. Claude Code (the client) re-reads the resource and has the current document content without the developer needing to manually refresh or re-prompt. The notification-driven approach eliminates the need to restart Claude Code sessions when documents change during a work session. Notifications increase server-to-client traffic. For servers monitoring high-frequency data sources (stock ticks, sensor data, log streams), notification-per-change can flood the client. Implement notification debouncing or batching for high-frequency sources – emit one notification summarizing multiple changes rather than one notification per change. Log in and enroll to access lesson quizzes.
Lesson 2: Notifications and Real-Time Updates
Lesson Objectives
Lesson Content
Notify client that a resource has changed
Notify client that the resource list has changed
Notify client that the available tools have changed
Send progress update during a long tool execution
Practical Example
Safety Notes