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)
Reactions are currently unavailable
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
Python & MCP Python SDK
Python 3.13, Windows 11; main at 91941ed (src/mcp/server/mcpserver/utilities/types.py:66)