notifyResourceUpdated method
Notify clients about a resource update
uri The URI of the updated resource
content Optional resource content. If provided, sends ResourceContentInfo format.
If omitted, sends only URI (MCP 2025-03-26 standard compliant).
Implementation
void notifyResourceUpdated(String uri, {ResourceContent? content}) {
// Invalidate cache
_resourceCache.remove(uri);
if (!isConnected || !capabilities.hasResources) return;
final subscribers = _resourceSubscriptions[uri];
if (subscribers == null || subscribers.isEmpty) return;
// Build notification based on whether content is provided
final Map<String, dynamic> notification;
if (content != null) {
// Extended format with ResourceContentInfo structure
notification = {
'uri': uri,
'content': {
'uri': uri,
'text': content.text,
'blob': content.blob,
'mimeType': content.mimeType,
},
};
} else {
// Standard MCP 2025-03-26 format (URI only)
notification = {
'uri': uri,
};
}
for (final sessionId in subscribers) {
if (_sessions.containsKey(sessionId)) {
_sendNotification(sessionId, 'notifications/resources/updated', notification);
}
}
}