PrefectHQ/fastmcp · error
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
FunctionTool.from_function() accepts either a bundled `metadata` object (ToolMeta) or individual keyword parameters (name, description, tags, etc.), but not both. The library raises this TypeError to prevent ambiguity about which source of configuration wins when both are supplied.
Source
Thrown at fastmcp_slim/fastmcp/tools/function_tool.py:269
name,
version,
title,
description,
icons,
tags,
annotations,
meta,
task,
timeout,
auth,
run_in_thread,
]
)
or output_schema is not NotSet
)
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."
)
if metadata is None and not individual_params_provided:
fmeta = get_fastmcp_meta(fn)
if isinstance(fmeta, ToolMeta):
metadata = fmeta
# Build metadata from kwargs if not provided
if metadata is None:
metadata = ToolMeta(
name=name,
version=version,
title=title,
description=description,
icons=icons,
tags=tags,View on GitHub (pinned to 1f02114297)
Solutions
- Remove the individual keyword arguments and put all configuration into the metadata object
- Remove the metadata argument and configure the tool with individual parameters only
- If metadata may or may not be present, pass individual params only when metadata is None
Example fix
// before
FunctionTool.from_function(fn, metadata=meta, name="my_tool", tags={"a"})
// after
FunctionTool.from_function(fn, metadata=meta) # all config in meta
// or
FunctionTool.from_function(fn, name="my_tool", tags={"a"}) Defensive patterns
Strategy: validation
Validate before calling
def check_from_function_args(metadata=None, **kwargs):
individual = [k for k, v in kwargs.items() if v is not None]
if metadata is not None and individual:
raise TypeError(f"Pass metadata OR individual params, not both: {individual}") Try / catch
try:
tool = FunctionTool.from_function(fn, metadata=meta, name="x")
except TypeError as e:
if "both 'metadata' and individual" in str(e):
tool = FunctionTool.from_function(fn, metadata=meta) Prevention
- Pick one configuration style (metadata or kwargs) per codebase and enforce it in review
- Centralize tool creation in a factory function that chooses the style
- When migrating to ToolMeta, delete old kwargs in the same commit
When it happens
Trigger: Calling FunctionTool.from_function(fn, metadata=meta, name='foo') or any combination where metadata is not None AND at least one individual parameter (name, description, tags, annotations, timeout, output_schema, etc.) is also provided.
Common situations: Migrating code from the individual-kwargs API to the metadata API and leaving old kwargs in place; copying an example that uses metadata while a template already passes name=; programmatic tool generation where metadata is conditionally provided.
Related errors
- Cannot pass both 'metadata' and individual parameters to fro
- The @resource decorator requires a URI. Use @resource('uri')
- Expected Prompt or @prompt-decorated function, got {type(pro
- Cannot specify both a name as first argument and as keyword
- You must provide a name for lambda functions
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/a5232f76aa184031.
Report an issue: GitHub.