{"record":{"id":"d76d0aebbbdc1e0e","repo":"PrefectHQ/fastmcp","slug":"uri-is-required-when-metadata-is-not-provided","errorCode":null,"errorMessage":"uri is required when metadata is not provided","messagePattern":"uri is required when metadata is not provided","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/resources/function_resource.py","lineNumber":141,"sourceCode":"                    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,\n                meta=meta,\n                auth=auth,\n            )\n\n        uri_obj = AnyUrl(metadata.uri)\n\n        # Get function name - use class name for callable objects\n        func_name = (","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/resources/function_resource.py#L123-L159","documentation":"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.","triggerScenarios":"from_function(fn); from_function(fn, name=\"cfg\") with no uri= and no metadata=.","commonSituations":"Convenience helpers wrapping from_function that forward optional kwargs, dropping the uri; tests constructing FunctionResource without a URI.","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"],"exampleFix":"// before\nfrom_function(read_fn, name=\"config\")\n// after\nfrom_function(read_fn, uri=\"config://app\", name=\"config\")","handlingStrategy":"validation","validationCode":"def require_uri(kwargs):\n    if kwargs.get(\"metadata\") is None and kwargs.get(\"uri\") is None:\n        raise TypeError(\"from_function requires uri or metadata\")","typeGuard":"def from_function_args_ok(metadata, uri) -> bool:\n    return metadata is not None or uri is not None","tryCatchPattern":"try:\n    res = FunctionResource.from_function(fn, **kw)\nexcept TypeError:\n    res = FunctionResource.from_function(fn, uri=derive_uri(fn.__name__))","preventionTips":["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"],"tags":["python","resources","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}