fastmcp.resources.resource
Base classes and interfaces for FastMCP resources.
Classes
Resource
Base class for all resources.
Methods:
enable
disable
from_function
set_default_mime_type
set_default_name
read
to_mcp_resource
key
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