Audio(data=b"") raises "Either path or data can be provided", while Image(data=b"") works
维护者通常 1 天内回复
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
相关代码位于 src/mcp/server/mcpserver/utilities/types.py,具体是第 66 行附近的 Audio.__init__ 方法。将真值检查 if not bool(path) ^ bool(data) 替换为 path is None and data is None / path is not None and data is not None 检查,与 Image 类的实现保持一致。为 Audio(data=b"") 添加一个测试,以确认它不再引发 ValueError,并生成空的 base64 数据,与 Image 的行为一致。新测试通过且 Audio(data=b"") 按预期工作时,即为完成。
由索引模型根据 Issue 内容生成。
描述
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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)
- 主要语言
- Python
- 星标
- 24.5k
- 派生
- 4k
- 平均合并
- 18 小时 19 分钟
- 30 天内合并 PR
- 36
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/python-sdk 的其他 Issue
-
bug v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/python-sdk#3685 ·
维护者通常 1 天内回复
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.py可能重新可做 关联的 PR 已关闭且未合并。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 84/100
modelcontextprotocol/python-sdk#3673 · 3 条评论 ·
维护者通常 1 天内回复
-
Streamable HTTP server rejects a mixed-case Content-Type with 415可能已有人在做 @CRYPTONIKAV 于 1 天前认领。 未关闭bug v1 v2
难度 2/5 1-3 小时 新手友好度 75/100
modelcontextprotocol/python-sdk#3670 · 4 条评论 ·
维护者通常 1 天内回复
-
Bug in the MCP Apps documentation.可能已有人在做 @Kludex 于 1 天前认领。 未关闭documentation v2
难度 2/5 1-3 小时 新手友好度 82/100
modelcontextprotocol/python-sdk#3662 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 66/100
modelcontextprotocol/python-sdk#3655 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
good first issue No-AI
难度 2/5 1-3 小时 新手友好度 69/100
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
-
🐛 Bug: Calendar work items cannot be opened on mobile可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复