Image/Audio `format=` emits image/jpg, audio/mp3, audio/m4a — unregistered MIME types that disagree with the `path=` suffix table
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 src/mcp/server/fastmcp/utilities/types.py 開始,將現有的路徑後綴表與 Image 和 Audio 對 format= 的處理進行比較;docs/servers/media.md 說明了 data= 的用法。執行相關的 Image 和 Audio MIME 類型測試,並考慮 issue 的參數化案例;完成的標準是已註冊的別名與基於路徑的結果一致,同時未知格式保留其 fallback。
由索引模型根據 Issue 內容生成。
描述
Initial Checks
- I confirm that I'm using the newest release of my release line (2.2.0)
- I have searched GitHub issues and found no similar issue
Release Line
2.x (current stable). The same code exists on v1.x (src/mcp/server/fastmcp/utilities/types.py).
Description
Image and Audio compute the MIME type two different ways. With path= they use a suffix table (.jpg -> image/jpeg, .mp3 -> audio/mpeg, .m4a -> audio/mp4). With format=, which docs/servers/media.md says to pass whenever you use data=, they just do f"image/{format}" / f"audio/{format}". So the same name gives different results depending on which keyword it arrives through, and format= puts non-registered types on the wire:
Image(data=..., format="jpg")->mimeType: "image/jpg"(should beimage/jpeg)Audio(data=..., format="mp3")->audio/mp3(should beaudio/mpeg)Audio(data=..., format="m4a")->audio/m4a(should beaudio/mp4)
This is easy to hit: switching a tool from Image(path="chart.jpg") to Image(data=buf.getvalue(), format="jpg") silently changes the wire output from image/jpeg to image/jpg, and a consumer that validates image MIME types rejects it.
Expected: format="jpg" and path="x.jpg" give the same registered type.
Proposed fix: route format= through the same table the path= branch already has, keeping image/<format> / audio/<format> as the fallback for names outside it (so format="bmp" etc. are unchanged). I have this fix with parametrized tests ready locally (100% branch coverage on types.py, ruff/pyright clean) and would like to open the PR if this is accepted.
Example Code
from pathlib import Path
from mcp.server.mcpserver import Audio, Image
print(Image(data=b"\x00", format="jpg").to_image_content().mime_type) # image/jpg (expected image/jpeg)
print(Audio(data=b"\x00", format="mp3").to_audio_content().mime_type) # audio/mp3 (expected audio/mpeg)
print(Audio(data=b"\x00", format="m4a").to_audio_content().mime_type) # audio/m4a (expected audio/mp4)
# The same helpers get it right when the name arrives as a file suffix:
print(Image(path=Path("x.jpg"))._mime_type) # image/jpeg
Python & MCP Python SDK
Python 3.12.13
mcp 2.2.0 (also reproduced on main @ f1b6589)
Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); I reviewed the report before filing it.
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 7 小時
- 30 天內合併 PR
- 18
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
v1 v2
難度 2/5 1-3 小時 新手友好度 86/100
modelcontextprotocol/python-sdk#3589 ·
維護者通常 1 天內回覆
-
v1 v2
難度 2/5 1-3 小時 新手友好度 70/100
modelcontextprotocol/python-sdk#3578 · 1 則留言 ·
維護者通常 1 天內回覆
-
v1 v2
難度 2/5 1-3 小時 新手友好度 65/100
modelcontextprotocol/python-sdk#3573 · 4 則留言 ·
維護者通常 1 天內回覆
-
v2
難度 2/5 1-3 小時 新手友好度 75/100
modelcontextprotocol/python-sdk#3566 ·
維護者通常 1 天內回覆
-
v1 v2
難度 2/5 1-3 小時 新手友好度 85/100
modelcontextprotocol/python-sdk#3546 · 5 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
docs pydanty:is-working
難度 2/5 1-3 小時 新手友好度 75/100
pydantic/pydantic-ai#8863 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
run-llama/llama_index#23278 ·
維護者通常 2 天內回覆
-
documentation from-review-extraction github-actions priority: low severity:nit
難度 1/5 1 小時以內 新手友好度 92/100
LearningCircuit/local-deep-research#6946 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
oracle/langchain-oracle#323 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
tenstorrent/tt-metal#58057 · 1 則留言 ·
維護者通常 1 天內回覆