Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#3,656 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@ajay206 已经在做这个了。

开始于 2026年10月12日。

  • #2 来自 @ajay206 —— 未关闭
  • #3657 来自 @KaiyiQuan —— 已关闭,未合并

评估

难度
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 内容生成。

描述

bug v1 v2
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)

主要语言
Python
星标
24.5k
派生
4k
平均合并
18 小时 19 分钟
30 天内合并 PR
36

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。