Skip to content

Audio(data=b"") raises "Either path or data can be provided", while Image(data=b"") works #3656

Description

@xThreeh

Initial Checks

Release line

2.x

Description

mcp.server.mcpserver.utilities.types.Audio rejects an empty byte payload that Image accepts. Audio.__init__ checks if not bool(path) ^ bool(data), so data=b"" is treated as missing and raises ValueError("Either path or data can be provided"). Image.__init__ checks path is None and data is None / path is not None and data is not None, so Image(data=b"") builds content with data="".

Empty bytes are a valid payload here: the schema's AudioContent.data is a base64 string with no minimum length, and base64.b64encode(b"") is "". Audio.to_audio_content() itself already uses self.data is not None. The truthiness check also produces the same misleading message when both path and data are passed.

Using the same two is None checks as Image would fix both. I'm happy to send that change with a test if you'd like an outside PR for it.

Example Code

from mcp.server.mcpserver.utilities.types import Audio, Image

print(Image(data=b"").to_image_content().data)  # ''
Audio(data=b"")  # ValueError: Either path or data can be provided

Python & MCP Python SDK

Python 3.13, Windows 11; main at 91941ed (src/mcp/server/mcpserver/utilities/types.py:66)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv1Affects the v1.x maintenance linev2Affects the v2 line (2.x on main)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions