Resource subscriptions allow clients to receive automatic notifications when specific resources change. This enables real-time data synchronization without polling.
Overview
Resource subscriptions implement the MCP protocol’sresources/subscribe and resources/unsubscribe methods. When a client subscribes to a resource, your server can notify them whenever that resource is updated.
Key Features:
- Automatic notifications: Push updates to clients when resources change
- Session tracking: Per-session subscription management
- Automatic cleanup: Subscriptions are cleaned up when sessions close
- Efficient: No polling required - clients receive updates only when resources change
How It Works
The subscription flow:- Client subscribes to a resource URI
- Server tracks the subscription
- When the resource changes, server notifies all subscribers
- Clients can then fetch the updated resource
Subscribing to Resources
Clients can subscribe to resources to receive automatic notifications when they change. The client API provides subscription methods through the session connector:Notifying Subscribers
When a resource changes, useserver.notifyResourceUpdated() to notify all subscribed clients:
Subscription vs Notifications
Understanding the difference between subscriptions and notifications:| Feature | Resource Subscriptions | Server Notifications |
|---|---|---|
| Purpose | Track resource changes | Broadcast events |
| Direction | Resource-specific | Any custom message |
| Protocol | resources/subscriberesources/updated | notifications/* |
| Use Case | Data synchronization | Status updates, events |
| Client Action | Must subscribe first | Receives without subscribing |
- Clients need to track specific resource changes
- You want resource-level granularity
- Clients should opt-in to updates
- Broadcasting general events to all clients
- Sending progress updates or status changes
- One-way messages that don’t relate to specific resources
Next Steps
- Resources - Learn about creating resources
- Notifications - Understand server notifications
- Tools Guide - Create tools that update resources
- MCP Resources Specification - Official protocol details