fastmcp.resources.base
Base classes and interfaces for FastMCP resources.
Functions
convert_raw_to_resource_result
Resource and ResourceTemplate so both honor the MIME type
the component declares in listings. A component that advertises
text/csv must not serve text/plain on read.
Args:
raw_value: The value returned by the user’s function.mime_type: The component’s declared MIME type, forwarded to content items.meta: Component-level meta (e.g.uimetadata for MCP Apps CSP/permissions) propagated to each content item.
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
InputRequiredResourceResult
The full result of a single multi-round-trip resource read (SEP-2322).
InputRequiredResult is a result type, not a tools/call feature: any
request may resolve to one. When a resource or resource template returns an
InputRequiredResult from its body to ask the client for input, that ask is
the legitimate result of this resources/read — so FastMCP wraps it in this
ResourceResult subclass, mirroring InputRequiredToolResult and
InputRequiredPromptResult, and it flows through the middleware chain as an
ordinary return value.
Invariant: the wrapped InputRequiredResult is never serialized as resource
contents. contents is always empty; the wire handler (_on_read_resource)
reads .input_required and returns it to the runner.
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
mime_type is forwarded so
that ui:// resources (and others with non-default MIME types)
don’t fall back to text/plain.
The resource’s component-level meta (e.g. ui metadata for
MCP Apps CSP/permissions) is propagated to each content item so
that hosts can read it from the resources/read response.

