Skip to main content

fastmcp.utilities.components

Functions

get_fastmcp_metadata

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.

Classes

FastMCPMeta

FastMCPComponent

Base class for FastMCP tools, prompts, resources, and resource templates. Methods:

make_key

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

The globally unique lookup key for this component. Format: ”:@” or ”:@” 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 any cross-component identity work (dedupe, grouping, collision detection, lookup tables). It encodes type, identifier, and version, so variants of the same component don’t falsely collide with each other, and cross-type identifiers (e.g. a tool and a resource both named “foo”) can’t clash.

get_meta

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

Removed in 3.0. Use server.enable(keys=[…]) instead.

disable

Removed in 3.0. Use server.disable(keys=[…]) instead.

copy

Create a copy of the component.

get_span_attributes

Return span attributes for telemetry. Subclasses should call super() and merge their specific attributes.