PrefectHQ/fastmcp · error · ValueError
No image data available
Error message
No image data available
What it means
Image._get_data base64-encodes the image from its path or in-memory bytes. If both self.path and self.data are somehow empty at read time (the constructor normally prevents this, but direct instantiation via __new__/deserialization or a falsy path can bypass it), it raises ValueError('No image data available'). This means the object holds no usable image source.
Source
Thrown at fastmcp_slim/fastmcp/utilities/types.py:291
if self.path:
# Workaround for WEBP in Py3.10
mimetypes.add_type("image/webp", ".webp")
resp = mimetypes.guess_type(self.path, strict=False)
if resp and resp[0] is not None:
return resp[0]
return "application/octet-stream"
return "image/png" # default for raw binary data
def _get_data(self) -> str:
"""Get raw image data as base64-encoded string."""
if self.path:
with open(self.path, "rb") as f:
data = base64.b64encode(f.read()).decode()
elif self.data is not None:
data = base64.b64encode(self.data).decode()
else:
raise ValueError("No image data available")
return data
def to_image_content(
self,
mime_type: str | None = None,
annotations: Annotations | None = None,
) -> mcp_types.ImageContent:
"""Convert to MCP ImageContent."""
data = self._get_data()
return mcp_types.ImageContent(
type="image",
data=data,
mime_type=mime_type or self._mime_type,
annotations=annotations or self.annotations,
)
def to_data_uri(self, mime_type: str | None = None) -> str:View on GitHub (pinned to 1f02114297)
Solutions
- Recreate the Image with a valid path or non-empty data
- Check img.path / img.data before calling to_image_content/to_data_uri
- Verify the path is a non-empty string and the file exists
Example fix
// before img = Image(path='') # falsy path, no data content = img.to_image_content() # raises // after img = Image(path='img.png') content = img.to_image_content()
Defensive patterns
Strategy: type-guard
Validate before calling
def to_content(img: Image):
if not img.path and img.data is None:
raise ValueError("Image has no path or data; rebuild it")
return img.to_image_content() Type guard
def has_image_data(img: Image) -> bool:
return bool(img.path) or img.data is not None Try / catch
try:
content = img.to_image_content()
except ValueError:
content = None # or rebuild the Image from the original source Prevention
- Keep a reference to the original path/bytes so the Image can be rebuilt
- Avoid mutating .path/.data on an Image after construction
- If serializing Images, persist data (bytes) rather than relying on a path
- Check has_image_data(img) before conversion calls
When it happens
Trigger: Calling to_image_content() or to_data_uri() on an Image whose path and data are both unset — typically an object created through bypassed validation, unpickled state, or path='' (falsy) with data=None.
Common situations: Deserializing/serializing Image objects where the path attribute was dropped; constructing with an empty-string path that passes neither-check loosely; mutating .path/.data after construction.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Either path or data must be provided
- Only one of path or data can be provided
- No audio data available
- Cannot resolve tool reference: {fn!r}
- Cannot determine tool name for {fn!r}
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/6dd99143c8851d9f.
Report an issue: GitHub.