fastmcp.resources.resource
Base classes and interfaces for FastMCP resources.
Functions
resource
- Creating resources that will be modified before registration
- Defining resources in modules that are discovered by FileSystemProvider
- Creating reusable resource definitions
uri: URI for the resource (e.g. “resource://my-resource” or “resource://”)name: Optional name for the resourcetitle: Optional title for the resourcedescription: Optional description of the resourceicons: Optional icons for the resourcemime_type: Optional MIME type for the resourcetags: Optional set of tags for categorizing the resourceannotations: Optional annotations about the resource’s behaviormeta: Optional meta information about the resourcetask: Optional task configuration for background execution (default False)
- A decorator function that returns a Resource or ResourceTemplate.
Classes
ResourceContent
Wrapper for resource content with optional MIME type and metadata.
Accepts any value for content - strings and bytes pass through directly,
other types (dict, list, BaseModel, etc.) are automatically JSON-serialized.
Methods:
to_mcp_resource_contents
uri: The URI of the resource (required by MCP types)
- TextResourceContents for str content, BlobResourceContents for bytes
ResourceResult
Canonical result type for resource reads.
Provides explicit control over resource responses: multiple content items,
per-item MIME types, and metadata at both the item and result level.
Methods:
to_mcp_result
uri: The URI of the resource (required by MCP types)
- MCP ReadResourceResult with converted contents
Resource
Base class for all resources.
Methods:
from_function
set_default_mime_type
set_default_name
read
- str: Text content
- bytes: Binary content
- ResourceResult: Full control over contents and result-level meta
convert_result
- In _read() to convert user function return values to ResourceResult
- In tasks_result_handler() to convert Docket task results to ResourceResult
to_mcp_resource
key
register_with_docket
add_to_docket
docket: The Docket instancefn_key: Function lookup key in Docket registry (defaults to self.key)task_key: Redis storage key for the result**kwargs: Additional kwargs passed to docket.add()
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

