pub struct ResourceSubscriptions(/* private fields */);Expand description
Tracks which MCP resource URIs the client has subscribed to.
The hot read path (pump tasks checking before sending notifications) uses
a RwLock so concurrent readers do not block each other.
Implementations§
Source§impl ResourceSubscriptions
impl ResourceSubscriptions
Sourcepub async fn subscribe(&self, uri: String) -> Result<bool, SubscriptionError>
pub async fn subscribe(&self, uri: String) -> Result<bool, SubscriptionError>
Add a URI to the subscription set.
Returns Ok(true) if newly inserted, Ok(false) if already present.
§Errors
Returns SubscriptionError::LimitReached if the set has already
reached MAX_SUBSCRIPTIONS and uri is not already a member.
Sourcepub async fn is_empty(&self) -> bool
pub async fn is_empty(&self) -> bool
Check whether the subscription set is empty.
Used as a fast path in the diagnostics pump to skip URI construction when no client has subscribed yet.
Sourcepub async fn unsubscribe(&self, uri: &str) -> bool
pub async fn unsubscribe(&self, uri: &str) -> bool
Remove a URI from the subscription set.
Tries uri directly against the canonical set first, then falls back
to resolving it as a recorded raw alias (see Self::record_alias,
crate-private) – covers a caller that could not canonicalize the path at
unsubscribe time (e.g. the file was deleted since subscribing) and so
passed the same raw URI it originally subscribed with.
Returns true if a subscription was found and removed.