Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉 適合新手
#3,656 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
85/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

相關程式碼位於 src/mcp/server/mcpserver/utilities/types.py,具體是第 66 行附近的 Audio.__init__ 方法。將 truthiness 檢查 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
平均合併
1 天 14 小時
30 天內合併 PR
34

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。