{"record":{"id":"af72a3d67fdc71e4","repo":"PrefectHQ/fastmcp","slug":"no-resource-data-available","errorCode":null,"errorMessage":"No resource data available","messagePattern":"No resource data available","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/utilities/types.py","lineNumber":436,"sourceCode":"        annotations: Annotations | None = None,\n    ) -> mcp_types.EmbeddedResource:\n        if self.path:\n            with open(self.path, \"rb\") as f:\n                raw_data = f.read()\n                uri_str = self.path.resolve().as_uri()\n        elif self.data is not None:\n            raw_data = self.data\n            if self._name:\n                extension = (\n                    \"\"\n                    if Path(self._name).suffix\n                    else f\".{self._mime_type.split('/')[1]}\"\n                )\n                uri_str = f\"file:///{self._name}{extension}\"\n            else:\n                uri_str = f\"file:///resource.{self._mime_type.split('/')[1]}\"\n        else:\n            raise ValueError(\"No resource data available\")\n\n        mime = mime_type or self._mime_type\n        # Validate the URI shape, then pass the string form to the SDK types\n        # (their `uri` fields are plain `str` in the v2 SDK).\n        UriType = Annotated[AnyUrl, UrlConstraints(host_required=False)]\n        uri = str(TypeAdapter(UriType).validate_python(uri_str))\n\n        if mime.startswith(\"text/\"):\n            try:\n                text = raw_data.decode(\"utf-8\")\n            except UnicodeDecodeError:\n                text = raw_data.decode(\"latin-1\")\n            resource = mcp_types.TextResourceContents(\n                text=text,\n                mime_type=mime,\n                uri=uri,\n            )\n        else:","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/utilities/types.py#L418-L454","documentation":"`to_resource_content` builds a file:// URI for an EmbeddedResource. If the data object has no text content, no bytes (`data`), and no path, there is nothing to embed, so the method raises `ValueError(\"No resource data available\")`. It is a guard against constructing an empty/malformed resource content block.","triggerScenarios":"Calling `to_resource_content()` on a `ResourceContent`-like object where text is empty/None, `data` is None, and `path` is None — e.g. a resource created without any payload or with a failed data load.","commonSituations":"Fetching a resource whose read returned nothing; constructing the types helper manually with only a name/mime_type and forgetting the payload; tests exercising the empty-data branch.","solutions":["Populate the resource with content before converting: pass `data=...` bytes, `text=...`, or a valid `path`.","Check the payload is non-empty before calling `to_resource_content` (e.g. skip None/empty reads upstream).","If a placeholder URI is acceptable, supply mime_type with data so the fallback `file:///resource.<sub>` branch is used instead.","Wrap the call in try/except ValueError to handle legitimately empty resources."],"exampleFix":"// before\nrc = EmbeddedResource(name=\"out.txt\", mime_type=\"text/plain\")\nblock = rc.to_resource_content()  # ValueError\n// after\nrc = EmbeddedResource(name=\"out.txt\", mime_type=\"text/plain\", text=\"hello\")\nblock = rc.to_resource_content()","handlingStrategy":"validation","validationCode":"def can_convert(rc) -> bool:\n    return bool(getattr(rc, \"text\", None)) or getattr(rc, \"data\", None) is not None or getattr(rc, \"path\", None) is not None\n# skip: if not can_convert(rc): continue","typeGuard":"from typing import Any\ndef has_payload(rc: Any) -> bool:\n    return bool(getattr(rc, \"text\", None)) or getattr(rc, \"data\", None) is not None or getattr(rc, \"path\", None) is not None","tryCatchPattern":"try:\n    block = rc.to_resource_content()\nexcept ValueError as e:\n    if \"No resource data available\" not in str(e):\n        raise\n    block = None  # or skip/log","preventionTips":["Always construct embedded resources with at least one of text/data/path","Validate resource reads are non-empty before conversion","Unit-test the empty-payload branch of your resource loading code"],"tags":["python","resources","value-error"],"backgroundTag":"empty-resource-data","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}