Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146---title: componentssidebarTitle: components---
# `fastmcp.utilities.components`
## Functions
### `get_fastmcp_metadata` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L22" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_fastmcp_metadata(meta: dict[str, Any] | None) -> FastMCPMeta```
Extract FastMCP metadata from a component's meta dict.
Handles both the current `fastmcp` namespace and the legacy `_fastmcp`namespace for compatibility with older FastMCP servers.
### `public_result_meta` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonpublic_result_meta(meta: dict[str, Any] | None) -> dict[str, Any] | None```
Strip FastMCP's internal bookkeeping out of component meta.
Component `meta` carries private entries under the `fastmcp` namespace(e.g. `_internal.visibility`) that must never reach the wire. Listingsalready filter these via `FastMCPComponent.get_meta()`; results thatcarry component meta (resource contents, prompt results) need the sametreatment.
Returns None when nothing public remains, so components without usermetadata keep an absent `_meta` rather than an empty object.
## Classes
### `FastMCPMeta` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L16" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
### `FastMCPComponent` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L99" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Base class for FastMCP tools, prompts, resources, and resource templates.
**Methods:**
#### `make_key` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L154" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonmake_key(cls, identifier: str) -> str```
Construct the lookup key for this component type.
**Args:**- `identifier`: The raw identifier (name for tools/prompts, uri for resources)
**Returns:**- A prefixed key like "tool:name" or "resource:uri"
#### `key` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L168" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonkey(self) -> str```
The globally unique lookup key for this component.
Format: "{key_prefix}:{identifier}@{version}" or "{key_prefix}:{identifier}@"e.g. "tool:my_tool@v2", "tool:my_tool@", "resource:file://x.txt@"
The @ suffix is ALWAYS present to enable unambiguous parsing of keys(URIs may contain @ characters, so we always include the delimiter).
Subclasses should override this to use their specific identifier.Base implementation uses name.
Prefer `.key` over ad-hoc `name or uri or uri_template` logic for anycross-component identity work (dedupe, grouping, collision detection,lookup tables). It encodes type, identifier, and version, so variantsof the same component don't falsely collide with each other, andcross-type identifiers (e.g. a tool and a resource both named "foo")can't clash.
#### `get_meta` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L190" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_meta(self) -> dict[str, Any]```
Get the meta information about the component.
Returns a dict that always includes a `fastmcp` key containing:- `tags`: sorted list of component tags- `version`: component version (only if set)
Internal keys (prefixed with `_`) are stripped from the fastmcp namespace.
#### `enable` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L238" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonenable(self) -> None```
Removed in 3.0. Use server.enable(keys=[...]) instead.
#### `disable` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L245" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythondisable(self) -> None```
Removed in 3.0. Use server.disable(keys=[...]) instead.
#### `copy` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L252" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoncopy(self) -> Self```
Create a copy of the component.
#### `get_span_attributes` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/utilities/components.py#L256" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_span_attributes(self) -> dict[str, Any]```
Return span attributes for telemetry.
Subclasses should call super() and merge their specific attributes.