PrefectHQ/fastmcp · error · TypeError
Cannot pass both 'metadata' and individual parameters to fro
Error message
Cannot pass both 'metadata' and individual parameters to from_function(). Use metadata alone or individual parameters alone.
What it means
FunctionResource.from_function supports two mutually exclusive configuration styles: a single metadata=ResourceMeta(...) object, or the individual keyword parameters (uri, name, title, description, etc.). Passing metadata together with any individual parameter is ambiguous, so it raises this TypeError.
Source
Thrown at fastmcp_slim/fastmcp/resources/function_resource.py:133
x is not None
for x in [
name,
version,
title,
description,
icons,
mime_type,
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,View on GitHub (pinned to 1f02114297)
Solutions
- Move all parameters into a single ResourceMeta(...) and pass only metadata=
- Or delete the metadata argument and keep the individual keyword arguments
- Check for falsy-but-set kwargs like name=None defaulting patterns in wrapper code
Example fix
// before from_function(fn, metadata=ResourceMeta(uri="data://x"), description="d") // after from_function(fn, metadata=ResourceMeta(uri="data://x", description="d"))
Defensive patterns
Strategy: validation
Validate before calling
def check_from_function_kwargs(**kw):
individual = [k for k in ("uri", "name", "title", "description", "version") if kw.get(k) is not None]
if kw.get("metadata") is not None and individual:
raise TypeError("metadata and individual params are mutually exclusive") Type guard
def is_valid_from_function_call(metadata, **kwargs) -> bool:
individual = any(v is not None for v in kwargs.values())
return not (metadata is not None and individual) Try / catch
try:
res = FunctionResource.from_function(fn, metadata=meta, uri=uri)
except TypeError as e:
res = FunctionResource.from_function(fn, metadata=meta) # drop stray kwargs Prevention
- Pick one configuration style per call site and stick to it
- When migrating to metadata=, remove all individual kwargs in the same commit
- Lint wrapper helpers that forward **kwargs into from_function
When it happens
Trigger: from_function(fn, metadata=ResourceMeta(uri=...), uri="data://x"); from_function(fn, metadata=m, name="n"); any combination where metadata is not None AND (name or title or description or version or uri ...) is not None.
Common situations: Refactoring calls from individual params to metadata but leaving one legacy kwarg behind; copying example code that mixes both styles.
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()
- uri is required when metadata is not provided
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/6c3d5fe1ac018aac.
Report an issue: GitHub.