pub struct VisibilityLayer<H> { /* private fields */ }Expand description
Progressive disclosure through component visibility control.
A visibility layer that wraps an McpHandler and filters components.
This allows per-session control over which tools, resources, and prompts
are visible to clients through the list_* methods.
Warning: Session overrides stored in this layer must be manually cleaned up
via clear_session or by using a VisibilitySessionGuard
to prevent unbounded memory growth.
Implementations§
Source§impl<H: McpHandler> VisibilityLayer<H>
impl<H: McpHandler> VisibilityLayer<H>
Sourcepub fn with_disabled(self, filter: ComponentFilter) -> Self
pub fn with_disabled(self, filter: ComponentFilter) -> Self
Disable components matching the filter globally.
This affects all sessions unless explicitly enabled per-session.
Disable components with the given tags globally.
Sourcepub fn enable_for_session(&self, session_id: &str, tags: &[String])
pub fn enable_for_session(&self, session_id: &str, tags: &[String])
Enable components with the given tags for a specific session.
Sourcepub fn disable_for_session(&self, session_id: &str, tags: &[String])
pub fn disable_for_session(&self, session_id: &str, tags: &[String])
Disable components with the given tags for a specific session.
Sourcepub fn clear_session(&self, session_id: &str)
pub fn clear_session(&self, session_id: &str)
Clear all session-specific overrides.
Sourcepub fn session_guard(
&self,
session_id: impl Into<String>,
) -> VisibilitySessionGuard
pub fn session_guard( &self, session_id: impl Into<String>, ) -> VisibilitySessionGuard
Create an RAII guard that automatically cleans up session state on drop.
This is the recommended way to manage session visibility lifetime.
§Example
async fn handle_connection<H: McpHandler>(layer: &VisibilityLayer<H>, session_id: &str) {
let _guard = layer.session_guard(session_id);
layer.enable_for_session(session_id, &["admin".to_string()]);
// ... handle requests ...
} // State automatically cleaned up hereSourcepub fn active_sessions_count(&self) -> usize
pub fn active_sessions_count(&self) -> usize
Get the number of active sessions with visibility overrides.
This is useful for monitoring memory usage.
Sourcepub fn into_inner(self) -> H
pub fn into_inner(self) -> H
Unwrap the layer and return the inner handler.
Trait Implementations§
Source§impl<H: Clone> Clone for VisibilityLayer<H>
impl<H: Clone> Clone for VisibilityLayer<H>
Source§fn clone(&self) -> VisibilityLayer<H>
fn clone(&self) -> VisibilityLayer<H>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more