{"record":{"id":"a5232f76aa184031","repo":"PrefectHQ/fastmcp","slug":"cannot-pass-both-metadata-and-individual-paramet-a5232f","errorCode":null,"errorMessage":"Cannot pass both 'metadata' and individual parameters to from_function(). Use metadata alone or individual parameters alone.","messagePattern":"Cannot pass both 'metadata' and individual parameters to from_function\\(\\)\\. Use metadata alone or individual parameters alone\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/tools/function_tool.py","lineNumber":269,"sourceCode":"                    name,\n                    version,\n                    title,\n                    description,\n                    icons,\n                    tags,\n                    annotations,\n                    meta,\n                    task,\n                    timeout,\n                    auth,\n                    run_in_thread,\n                ]\n            )\n            or output_schema is not NotSet\n        )\n\n        if metadata is not None and individual_params_provided:\n            raise TypeError(\n                \"Cannot pass both 'metadata' and individual parameters to from_function(). \"\n                \"Use metadata alone or individual parameters alone.\"\n            )\n\n        if metadata is None and not individual_params_provided:\n            fmeta = get_fastmcp_meta(fn)\n            if isinstance(fmeta, ToolMeta):\n                metadata = fmeta\n\n        # Build metadata from kwargs if not provided\n        if metadata is None:\n            metadata = ToolMeta(\n                name=name,\n                version=version,\n                title=title,\n                description=description,\n                icons=icons,\n                tags=tags,","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/tools/function_tool.py#L251-L287","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nFunctionTool.from_function(fn, metadata=meta, name=\"my_tool\", tags={\"a\"})\n// after\nFunctionTool.from_function(fn, metadata=meta)  # all config in meta\n// or\nFunctionTool.from_function(fn, name=\"my_tool\", tags={\"a\"})","handlingStrategy":"validation","validationCode":"def check_from_function_args(metadata=None, **kwargs):\n    individual = [k for k, v in kwargs.items() if v is not None]\n    if metadata is not None and individual:\n        raise TypeError(f\"Pass metadata OR individual params, not both: {individual}\")","typeGuard":null,"tryCatchPattern":"try:\n    tool = FunctionTool.from_function(fn, metadata=meta, name=\"x\")\nexcept TypeError as e:\n    if \"both 'metadata' and individual\" in str(e):\n        tool = FunctionTool.from_function(fn, metadata=meta)","preventionTips":["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"],"tags":["python","api-misuse","tool-definition"],"backgroundTag":"conflicting-parameters","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}