fix(mcpserver): normalize Image and Audio format to registered MIME types (#3585)
Closed
MU
1mo ago+114+114+012345678901234567890123456789-19-19-01234567890123456789
Summary
Closes #3585.
Currently, Image and Audio compute MIME types inconsistently depending on whether path= or format= is passed:
- With
path=, a suffix table is used (.jpg->image/jpeg,.mp3->audio/mpeg,.m4a->audio/mp4). - With
format=, the code naively interpolatedf"image/{format}"/f"audio/{format}". Passingformat="jpg",format="mp3", orformat="m4a"resulted in unregistered MIME types (image/jpg,audio/mp3,audio/m4a), which fails validation on downstream consumers.
Solution
- Defined
IMAGE_MIME_TYPESandAUDIO_MIME_TYPESmapping tables. - Route
format=through the same table aspath=, falling back tof"image/{fmt}"/f"audio/{fmt}"for formats outside the table (e.g.bmp,opus). - Normalized formats with
.lower().lstrip(".")for consistent matching. - Added comprehensive unit tests in
tests/server/mcpserver/test_media_types.pycovering format and path MIME type resolution, defaults, and fallbacks with 100% statement and branch coverage.
Disclosure: Implemented with AI assistance under human review.