fastmcp.utilities.visibility
Visibility filtering for FastMCP components.
This module provides the VisibilityFilter class which handles blocklist and
allowlist logic for controlling component visibility at both the provider
and server levels.
Classes
VisibilityFilter
Manages component visibility with blocklist and allowlist support.
Both servers and providers use this class to control which components
are visible. 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.

