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)
Initial Checks
Release line
2.x
Description
mcp.server.mcpserver.utilities.types.Audiorejects an empty byte payload thatImageaccepts.Audio.__init__checksif not bool(path) ^ bool(data), sodata=b""is treated as missing and raisesValueError("Either path or data can be provided").Image.__init__checkspath is None and data is None/path is not None and data is not None, soImage(data=b"")builds content withdata="".Empty bytes are a valid payload here: the schema's
AudioContent.datais a base64 string with no minimum length, andbase64.b64encode(b"")is"".Audio.to_audio_content()itself already usesself.data is not None. The truthiness check also produces the same misleading message when bothpathanddataare passed.Using the same two
is Nonechecks asImagewould fix both. I'm happy to send that change with a test if you'd like an outside PR for it.Example Code
Python & MCP Python SDK
Python 3.13, Windows 11;
mainat 91941ed (src/mcp/server/mcpserver/utilities/types.py:66)