fastmcp.resources.template
Resource template functionality.
Functions
extract_query_params
{?param1,param2} syntax.
The explode modifier is stripped, so {?tags*} yields {"tags"}. Use
extract_exploded_query_params to find which names carried it.
extract_exploded_query_params
{?tags*} marks tags as repeatable — ?tags=a&tags=b collects into a
list rather than collapsing to the first value.
encode_literal
ucschar (file:///docs/café/) or a space — and section 3.1
requires those to be UTF-8 percent-encoded in the expanded URI. Reserved
and unreserved characters are structural and stay as written, and existing
%XX triplets pass through so an already-encoded literal is not encoded
twice.
A resource URI reaches the server as an AnyUrl, which percent-encodes it,
so the encoded form is what matching has to line up with.
build_regex
{var}- simple path parameter{var*}- wildcard path parameter (captures multiple segments){?var1,var2}- query parameters (ignored in path matching)
match_uri_template
- Path params:
{var},{var*} - Query params:
{?var1,var2},{?list*}(repeated keys)
list_params names non-exploded query params that hold lists. Per RFC 6570
section 3.2.8 their value is comma-joined, with literal commas separating
items and %2C inside an item, so they are split before decoding.
expand_uri_template
match_uri_template.
Supports the same RFC 6570 subset:
- Path params:
{var},{var*} - Query params:
{?var1,var2}
forward_uri
uri_template with params, but the query string
is carried over from the incoming uri byte for byte. Re-expanding it would
decode and re-encode values, and the forwarding layer does not know which
{?name} params hold comma-joined lists, so ?tags=a%2Cb,c would arrive as
one item instead of two.
Classes
ResourceTemplate
A template for dynamically creating resources.
Methods:
resolve_security
security overrides the server default.
INHERIT_SECURITY (the field default) inherits server_default;
an explicit None disables screening for this template.
from_function
set_default_mime_type
matches
read
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 reads match the MIME type the template advertises
in resources/templates/list.

