mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 20:44:17 +02:00
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
158 lines
5.6 KiB
Text
158 lines
5.6 KiB
Text
---
|
|
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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L43" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L120" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L148" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L202" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
reset(self) -> None
|
|
```
|
|
|
|
Reset to default state (everything enabled, no filters).
|
|
|
|
|
|
#### `is_enabled` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L221" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
is_enabled(self, component: FastMCPComponent) -> bool
|
|
```
|
|
|
|
Check if component is enabled. Blocklist wins over allowlist.
|
|
|
|
|
|
#### `list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L241" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
list_tools(self, call_next: ListToolsNext) -> Sequence[Tool]
|
|
```
|
|
|
|
Filter tools by visibility.
|
|
|
|
|
|
#### `get_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L246" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_tool(self, name: str, call_next: GetToolNext) -> Tool | None
|
|
```
|
|
|
|
Get tool if enabled, None otherwise.
|
|
|
|
|
|
#### `list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L259" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
list_resources(self, call_next: ListResourcesNext) -> Sequence[Resource]
|
|
```
|
|
|
|
Filter resources by visibility.
|
|
|
|
|
|
#### `get_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L264" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_resource(self, uri: str, call_next: GetResourceNext) -> Resource | None
|
|
```
|
|
|
|
Get resource if enabled, None otherwise.
|
|
|
|
|
|
#### `list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L281" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
list_resource_templates(self, call_next: ListResourceTemplatesNext) -> Sequence[ResourceTemplate]
|
|
```
|
|
|
|
Filter resource templates by visibility.
|
|
|
|
|
|
#### `get_resource_template` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L288" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_resource_template(self, uri: str, call_next: GetResourceTemplateNext) -> ResourceTemplate | None
|
|
```
|
|
|
|
Get resource template if enabled, None otherwise.
|
|
|
|
|
|
#### `list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L305" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
list_prompts(self, call_next: ListPromptsNext) -> Sequence[Prompt]
|
|
```
|
|
|
|
Filter prompts by visibility.
|
|
|
|
|
|
#### `get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/transforms/visibility.py#L310" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_prompt(self, name: str, call_next: GetPromptNext) -> Prompt | None
|
|
```
|
|
|
|
Get prompt if enabled, None otherwise.
|
|
|