{"record":{"id":"6c3d5fe1ac018aac","repo":"PrefectHQ/fastmcp","slug":"cannot-pass-both-metadata-and-individual-paramet-6c3d5f","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":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/resources/function_resource.py","lineNumber":133,"sourceCode":"                x is not None\n                for x in [\n                    name,\n                    version,\n                    title,\n                    description,\n                    icons,\n                    mime_type,\n                    tags,\n                    annotations,\n                    meta,\n                    auth,\n                ]\n            )\n            or uri is not None\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        # Build metadata from kwargs if not provided\n        if metadata is None:\n            if uri is None:\n                raise TypeError(\"uri is required when metadata is not provided\")\n            metadata = ResourceMeta(\n                uri=str(uri),\n                name=name,\n                version=version,\n                title=title,\n                description=description,\n                icons=icons,\n                tags=tags,\n                mime_type=mime_type,\n                annotations=annotations,","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/resources/function_resource.py#L115-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"Refactoring calls from individual params to metadata but leaving one legacy kwarg behind; copying example code that mixes both styles.","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"],"exampleFix":"// before\nfrom_function(fn, metadata=ResourceMeta(uri=\"data://x\"), description=\"d\")\n// after\nfrom_function(fn, metadata=ResourceMeta(uri=\"data://x\", description=\"d\"))","handlingStrategy":"validation","validationCode":"def check_from_function_kwargs(**kw):\n    individual = [k for k in (\"uri\", \"name\", \"title\", \"description\", \"version\") if kw.get(k) is not None]\n    if kw.get(\"metadata\") is not None and individual:\n        raise TypeError(\"metadata and individual params are mutually exclusive\")","typeGuard":"def is_valid_from_function_call(metadata, **kwargs) -> bool:\n    individual = any(v is not None for v in kwargs.values())\n    return not (metadata is not None and individual)","tryCatchPattern":"try:\n    res = FunctionResource.from_function(fn, metadata=meta, uri=uri)\nexcept TypeError as e:\n    res = FunctionResource.from_function(fn, metadata=meta)  # drop stray kwargs","preventionTips":["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"],"tags":["python","resources","api-misuse"],"backgroundTag":"conflicting-parameters","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}