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

Image/Audio `format=` emits image/jpg, audio/mp3, audio/m4a — unregistered MIME types that disagree with the `path=` suffix table

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

从 src/mcp/server/fastmcp/utilities/types.py 开始,将现有的路径后缀表与 Image 和 Audio 对 format= 的处理进行比较;docs/servers/media.md 说明了 data= 的用法。运行相关的 Image 和 Audio MIME 类型测试,并考虑 issue 的参数化用例;完成的标准是已注册的别名与基于路径的结果一致,同时未知格式保留其 fallback。

由索引模型根据 Issue 内容生成。

描述

v1 v2
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 be image/jpeg)
  • Audio(data=..., format="mp3") -> audio/mp3 (should be audio/mpeg)
  • Audio(data=..., format="m4a") -> audio/m4a (should be audio/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.4k
派生
4k
平均合并
1 天 7 小时
30 天内合并 PR
18

环境准备

从这里开始

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

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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