fastmcp.resources.function_resource
Standalone @resource decorator for FastMCP.
Functions
resource
Classes
DecoratedResource
Protocol for functions decorated with @resource.
ResourceMeta
Metadata attached to functions by the @resource decorator.
FunctionResource
A resource that defers data loading by wrapping a function.
The function is only called when the resource is read, allowing for lazy loading
of potentially expensive data. This is particularly useful when listing resources,
as the function won’t be called until the resource is actually accessed.
The function can return:
- str for text content (default)
- bytes for binary content
- other types will be converted to JSON
from_function
fn: The function to wrapuri: The URI for the resource (required if metadata not provided)metadata: ResourceMeta object with all configuration. If provided, individual parameters must not be passed.name, title, etc.: Individual parameters for backwards compatibility. Cannot be used together with metadata parameter.

