PrefectHQ/fastmcp · error · TypeError
uri is required when metadata is not provided
Error message
uri is required when metadata is not provided
What it means
When from_function() is called without a metadata object, it builds one itself, and uri is the one mandatory field of ResourceMeta. Omitting both metadata and uri leaves the resource without an identity, so a TypeError is raised.
Source
Thrown at fastmcp_slim/fastmcp/resources/function_resource.py:141
tags,
annotations,
meta,
auth,
]
)
or uri is not None
)
if metadata is not None and individual_params_provided:
raise TypeError(
"Cannot pass both 'metadata' and individual parameters to from_function(). "
"Use metadata alone or individual parameters alone."
)
# Build metadata from kwargs if not provided
if metadata is None:
if uri is None:
raise TypeError("uri is required when metadata is not provided")
metadata = ResourceMeta(
uri=str(uri),
name=name,
version=version,
title=title,
description=description,
icons=icons,
tags=tags,
mime_type=mime_type,
annotations=annotations,
meta=meta,
auth=auth,
)
uri_obj = AnyUrl(metadata.uri)
# Get function name - use class name for callable objects
func_name = (View on GitHub (pinned to 1f02114297)
Solutions
- Pass uri="scheme://path" to from_function
- Or construct a ResourceMeta with uri included and pass metadata=
- Ensure wrapper functions don't swallow the uri kwarg before calling from_function
Example fix
// before from_function(read_fn, name="config") // after from_function(read_fn, uri="config://app", name="config")
Defensive patterns
Strategy: validation
Validate before calling
def require_uri(kwargs):
if kwargs.get("metadata") is None and kwargs.get("uri") is None:
raise TypeError("from_function requires uri or metadata") Type guard
def from_function_args_ok(metadata, uri) -> bool:
return metadata is not None or uri is not None Try / catch
try:
res = FunctionResource.from_function(fn, **kw)
except TypeError:
res = FunctionResource.from_function(fn, uri=derive_uri(fn.__name__)) Prevention
- Always supply uri= as the first keyword to from_function
- Check wrapper functions don't drop the uri kwarg
- Define a URI naming convention so callers never omit it
When it happens
Trigger: from_function(fn); from_function(fn, name="cfg") with no uri= and no metadata=.
Common situations: Convenience helpers wrapping from_function that forward optional kwargs, dropping the uri; tests constructing FunctionResource without a URI.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- contents[{i}] must be ResourceContent, got {type(item).__nam
- contents must be str, bytes, or list[ResourceContent], got {
- Either name or uri must be provided
- Subclasses must implement read()
- Cannot pass both 'metadata' and individual parameters to fro
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/d76d0aebbbdc1e0e.
Report an issue: GitHub.