fastmcp.server.transforms.visibility
Visibility transform for filtering components based on enable/disable settings.
This module provides the Visibility class which manages component visibility
with blocklist and allowlist support. Components can be hidden by key or tag,
and the visibility state is mutable - changes take effect on subsequent queries.
Classes
Visibility
Filters components based on visibility settings.
Manages blocklist and allowlist logic for controlling component visibility.
Both servers and providers use this class. Visibility is hierarchical: if a
component is hidden at any level (provider or server), it’s hidden to the client.
Filtering logic (blocklist wins over allowlist):
- If component key is in _disabled_keys → HIDDEN
- If any component tag is in _disabled_tags → HIDDEN
- If _default_enabled is False and component not in allowlist → HIDDEN
- Otherwise → VISIBLE
only=True flag on enable() switches to allowlist mode:
- Sets _default_enabled = False
- Clears existing allowlists
- Adds specified keys/tags to allowlist
disable
keys: Component keys to hide (e.g., “tool:my_tool@”, “resource:file://x@”)tags: Tags to hide - any component with these tags will be hidden
enable
keys: Component keys to showtags: Tags to showonly: If True, switches to allowlist mode - ONLY show these keys/tags. This sets default visibility to False, clears existing allowlists, and adds the specified keys/tags to the allowlist.

