--- title: visibility sidebarTitle: visibility --- # `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): 1. If component key is in _disabled_keys → HIDDEN 2. If any component tag is in _disabled_tags → HIDDEN 3. If _default_enabled is False and component not in allowlist → HIDDEN 4. Otherwise → VISIBLE The `only=True` flag on enable() switches to allowlist mode: - Sets _default_enabled = False - Clears existing allowlists - Adds specified keys/tags to allowlist **Methods:** #### `disable` ```python disable(self) -> None ``` Add to blocklist (hide components). **Args:** - `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` ```python enable(self) -> None ``` Remove from blocklist, or set allowlist with only=True. **Args:** - `keys`: Component keys to show - `tags`: Tags to show - `only`: 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. #### `reset` ```python reset(self) -> None ``` Reset to default state (everything enabled, no filters). #### `is_enabled` ```python is_enabled(self, component: FastMCPComponent) -> bool ``` Check if component is enabled. Blocklist wins over allowlist. #### `list_tools` ```python list_tools(self, call_next: ListToolsNext) -> Sequence[Tool] ``` Filter tools by visibility. #### `get_tool` ```python get_tool(self, name: str, call_next: GetToolNext) -> Tool | None ``` Get tool if enabled, None otherwise. #### `list_resources` ```python list_resources(self, call_next: ListResourcesNext) -> Sequence[Resource] ``` Filter resources by visibility. #### `get_resource` ```python get_resource(self, uri: str, call_next: GetResourceNext) -> Resource | None ``` Get resource if enabled, None otherwise. #### `list_resource_templates` ```python list_resource_templates(self, call_next: ListResourceTemplatesNext) -> Sequence[ResourceTemplate] ``` Filter resource templates by visibility. #### `get_resource_template` ```python get_resource_template(self, uri: str, call_next: GetResourceTemplateNext) -> ResourceTemplate | None ``` Get resource template if enabled, None otherwise. #### `list_prompts` ```python list_prompts(self, call_next: ListPromptsNext) -> Sequence[Prompt] ``` Filter prompts by visibility. #### `get_prompt` ```python get_prompt(self, name: str, call_next: GetPromptNext) -> Prompt | None ``` Get prompt if enabled, None otherwise.