PrefectHQ/fastmcp · error · ValueError

No audio data available

Error message

No audio data available

What it means

Audio.to_audio_content() base64-encodes the audio from path or data to build MCP AudioContent. If the object has neither a truthy path nor data at call time, it raises ValueError('No audio data available') — the instance holds no usable audio source.

Source

Thrown at fastmcp_slim/fastmcp/utilities/types.py:366

        if self.path:
            return mapping.get(
                self.path.suffix.lower().lstrip("."), "application/octet-stream"
            )
        return "audio/wav"  # default for raw binary data

    def to_audio_content(
        self,
        mime_type: str | None = None,
        annotations: Annotations | None = None,
    ) -> mcp_types.AudioContent:
        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 audio data available")

        return mcp_types.AudioContent(
            type="audio",
            data=data,
            mime_type=mime_type or self._mime_type,
            annotations=annotations or self.annotations,
        )


class File:
    """Helper class for returning file data from tools."""

    def __init__(
        self,
        path: str | Path | None = None,
        data: bytes | None = None,
        format: str | None = None,
        name: str | None = None,

View on GitHub (pinned to 1f02114297)

Solutions

  1. Recreate the Audio with a valid path or non-empty bytes before converting
  2. Check audio.path / audio.data before calling to_audio_content()
  3. Ensure the path is a non-empty string and the file exists

Example fix

// before
audio = Audio(path='')  # no usable source
block = audio.to_audio_content()  # raises
// after
audio = Audio(path='clip.wav')
block = audio.to_audio_content()
Defensive patterns

Strategy: type-guard

Validate before calling

def to_audio(audio: Audio):
    if not audio.path and audio.data is None:
        raise ValueError("Audio has no path or data; rebuild it")
    return audio.to_audio_content()

Type guard

def has_audio_data(audio: Audio) -> bool:
    return bool(audio.path) or audio.data is not None

Try / catch

try:
    block = audio.to_audio_content()
except ValueError:
    block = None  # skip or reload the audio from the original source

Prevention

When it happens

Trigger: Calling to_audio_content() (directly or via get_audio / _convert_to_single_content_block) on an Audio with path=None/'' and data=None, e.g. after deserialization or post-construction mutation.

Common situations: Audio objects round-tripped through serialization losing the data attribute; empty-string paths; building Audio in one component and clearing data before conversion.

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


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/4c44b921f5deb028. Report an issue: GitHub.