Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262---title: visibilitysidebarTitle: visibility---
# `fastmcp.server.transforms.visibility`
Visibility transform for marking component visibility state.
Each Visibility instance marks components via internal metadata. Multiplevisibility transforms can be stacked - later transforms override earlier ones.Final filtering happens at the Provider level.
## Functions
### `is_enabled` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L271" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonis_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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L300" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_visibility_rules(context: Context) -> list[dict[str, Any]]```
Load visibility rule dicts from session state.
### `save_visibility_rules` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L305" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonsave_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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L332" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoncreate_visibility_transforms(rules: list[dict[str, Any]]) -> list[Visibility]```
Convert rule dicts to Visibility transforms.
### `get_session_transforms` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L360" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_session_transforms(context: Context) -> list[Visibility]```
Get session-specific Visibility transforms from state store.
### `enable_components` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L372" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonenable_components(context: Context) -> None```
Enable components matching criteria for this session only.
Session rules override global transforms. Rules accumulate - each calladds 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., {"tool\:my_tool@v1"}).- `version`: Component version spec to match.- `tags`: Tags to match (component must have at least one).- `components`: Component types to match (e.g., {"tool", "prompt"}).- `match_all`: If True, matches all components regardless of other criteria.
### `disable_components` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L426" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythondisable_components(context: Context) -> None```
Disable components matching criteria for this session only.
Session rules override global transforms. Rules accumulate - each calladds 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., {"tool\:my_tool@v1"}).- `version`: Component version spec to match.- `tags`: Tags to match (component must have at least one).- `components`: Component types to match (e.g., {"tool", "prompt"}).- `match_all`: If True, matches all components regardless of other criteria.
### `reset_visibility` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L480" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonreset_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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L497" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonapply_session_transforms(components: Sequence[ComponentT]) -> Sequence[ComponentT]```
Apply session-specific visibility transforms to components.
This helper applies session-level enable/disable rules by markingcomponents with their visibility state. Session transforms overrideglobal 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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L196" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]```
Mark tools by visibility state.
#### `get_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L200" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_tool(self, name: str, call_next: GetToolNext) -> Tool | None```
Mark tool if found.
#### `list_resources` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L213" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_resources(self, resources: Sequence[Resource]) -> Sequence[Resource]```
Mark resources by visibility state.
#### `get_resource` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L217" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_resource(self, uri: str, call_next: GetResourceNext) -> Resource | None```
Mark resource if found.
#### `list_resource_templates` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L234" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_resource_templates(self, templates: Sequence[ResourceTemplate]) -> Sequence[ResourceTemplate]```
Mark resource templates by visibility state.
#### `get_resource_template` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L240" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_resource_template(self, uri: str, call_next: GetResourceTemplateNext) -> ResourceTemplate | None```
Mark resource template if found.
#### `list_prompts` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L257" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_prompts(self, prompts: Sequence[Prompt]) -> Sequence[Prompt]```
Mark prompts by visibility state.
#### `get_prompt` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L261" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_prompt(self, name: str, call_next: GetPromptNext) -> Prompt | None```
Mark prompt if found.