Skip to main content

Documentation Index

Fetch the complete documentation index at: https://gofastmcp.com/llms.txt

Use this file to discover all available pages before exploring further.

fastmcp.server.transforms.visibility

Visibility transform for marking component visibility state. Each Visibility instance marks components via internal metadata. Multiple visibility transforms can be stacked - later transforms override earlier ones. Final filtering happens at the Provider level.

Functions

is_enabled

is_enabled(component: FastMCPComponent) -> bool
Check if component is enabled. Returns True if:
  • No visibility mark exists (default is enabled)
  • Visibility mark is True
Returns False if visibility mark is False. Args:
  • component: Component to check.
Returns:
  • True if component should be enabled/visible to clients.

get_visibility_rules

get_visibility_rules(context: Context) -> list[dict[str, Any]]
Load visibility rule dicts from session state.

save_visibility_rules

save_visibility_rules(context: Context, rules: list[dict[str, Any]]) -> None
Save visibility rule dicts to session state and send notifications. Args:
  • context: The context to save rules for.
  • rules: The visibility rules to save.
  • components: Optional hint about which component types are affected. If None, sends notifications for all types (safe default). If provided, only sends notifications for specified types.

create_visibility_transforms

create_visibility_transforms(rules: list[dict[str, Any]]) -> list[Visibility]
Convert rule dicts to Visibility transforms.

get_session_transforms

get_session_transforms(context: Context) -> list[Visibility]
Get session-specific Visibility transforms from state store.

enable_components

enable_components(context: Context) -> None
Enable components matching criteria for this session only. Session rules override global transforms. Rules accumulate - each call adds a new rule to the session. Later marks override earlier ones (Visibility transform semantics). Sends notifications to this session only: ToolListChangedNotification, ResourceListChangedNotification, and PromptListChangedNotification. Args:
  • context: The context for this session.
  • names: Component names or URIs to match.
  • keys: Component keys to match (e.g., ).
  • version: Component version spec to match.
  • tags: Tags to match (component must have at least one).
  • components: Component types to match (e.g., ).
  • match_all: If True, matches all components regardless of other criteria.

disable_components

disable_components(context: Context) -> None
Disable components matching criteria for this session only. Session rules override global transforms. Rules accumulate - each call adds a new rule to the session. Later marks override earlier ones (Visibility transform semantics). Sends notifications to this session only: ToolListChangedNotification, ResourceListChangedNotification, and PromptListChangedNotification. Args:
  • context: The context for this session.
  • names: Component names or URIs to match.
  • keys: Component keys to match (e.g., ).
  • version: Component version spec to match.
  • tags: Tags to match (component must have at least one).
  • components: Component types to match (e.g., ).
  • match_all: If True, matches all components regardless of other criteria.

reset_visibility

reset_visibility(context: Context) -> None
Clear all session visibility rules. Use this to reset session visibility back to global defaults. Sends notifications to this session only: ToolListChangedNotification, ResourceListChangedNotification, and PromptListChangedNotification. Args:
  • context: The context for this session.

apply_session_transforms

apply_session_transforms(components: Sequence[ComponentT]) -> Sequence[ComponentT]
Apply session-specific visibility transforms to components. This helper applies session-level enable/disable rules by marking components with their visibility state. Session transforms override global transforms due to mark-based semantics (later marks win). Args:
  • components: The components to apply session transforms to.
Returns:
  • The components with session transforms applied.

Classes

Visibility

Sets visibility state on matching components. Does NOT filter inline - just marks components with visibility state. Later transforms in the chain can override earlier marks. Final filtering happens at the Provider level after all transforms run. Methods:

list_tools

list_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]
Mark tools by visibility state.

get_tool

get_tool(self, name: str, call_next: GetToolNext) -> Tool | None
Mark tool if found.

list_resources

list_resources(self, resources: Sequence[Resource]) -> Sequence[Resource]
Mark resources by visibility state.

get_resource

get_resource(self, uri: str, call_next: GetResourceNext) -> Resource | None
Mark resource if found.

list_resource_templates

list_resource_templates(self, templates: Sequence[ResourceTemplate]) -> Sequence[ResourceTemplate]
Mark resource templates by visibility state.

get_resource_template

get_resource_template(self, uri: str, call_next: GetResourceTemplateNext) -> ResourceTemplate | None
Mark resource template if found.

list_prompts

list_prompts(self, prompts: Sequence[Prompt]) -> Sequence[Prompt]
Mark prompts by visibility state.

get_prompt

get_prompt(self, name: str, call_next: GetPromptNext) -> Prompt | None
Mark prompt if found.