Example
Anatomy of a Resource
When a client callsresources/list, the server returns metadata for each resource. Resources with URI templates (like {section}) are returned via resources/templates/list instead.
Here’s the JSON-RPC response that the example above produces when a client calls resources/templates/list:
Static Resources
Resources without URI parameters are static - they always return at the same URI:Resource Templates
Use{param} placeholders in the URI to create dynamic resources:
user://123 and the function receives user_id="123".
Multiple Parameters
Templates support multiple parameters:Async Resources
Resources can be async for I/O operations:Binary Resources
Return bytes for binary content:Resource Subscriptions
Clients can subscribe to resources and receive notifications when they change. This follows the MCP resource subscriptions spec.How It Works
- Client sends
resources/subscribewith a resource URI - Your server updates the resource and calls
notify_resource_updated() - All subscribed clients receive a
notifications/resources/updatednotification - Clients re-read the resource to get the new content
notify_resource_updated() when your resource changes.
Example
data://price and then any client calls update_price, all subscribers receive the notification and can re-read the resource.
Subscriptions are session-scoped - they’re automatically cleaned up when a client disconnects. If the server restarts, clients need to re-subscribe.