Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

types: map Image jpg/svg/tif formats to canonical MIME types (#5294)

nate nowack1746b93f0596
diff --git a/fastmcp_slim/fastmcp/utilities/types.py b/fastmcp_slim/fastmcp/utilities/types.py
index ad2ead952..edd070b81 100644
--- a/fastmcp_slim/fastmcp/utilities/types.py
+++ b/fastmcp_slim/fastmcp/utilities/types.py
@@ -269,8 +269,14 @@ class Image:
def _get_mime_type(self) -> str:
"""Get MIME type from format or guess from file extension."""
+ mapping = {
+ "jpg": "image/jpeg",
+ "svg": "image/svg+xml",
+ "tif": "image/tiff",
+ }
+
if self._format:
- return f"image/{self._format.lower()}"
+ return mapping.get(self._format.lower(), f"image/{self._format.lower()}")
if self.path:
# Workaround for WEBP in Py3.10
diff --git a/tests/utilities/test_types.py b/tests/utilities/test_types.py
index 2d384ab11..5623d2f8d 100644
--- a/tests/utilities/test_types.py
+++ b/tests/utilities/test_types.py
@@ -163,6 +163,23 @@ class TestImage:
image = Image(data=b"test", format="jpeg")
assert image._mime_type == "image/jpeg"
+ @pytest.mark.parametrize(
+ "fmt,mime_type",
+ [
+ ("jpg", "image/jpeg"),
+ ("JPG", "image/jpeg"),
+ ("svg", "image/svg+xml"),
+ ("tif", "image/tiff"),
+ ("png", "image/png"),
+ ("avif", "image/avif"),
+ ],
+ )
+ def test_mime_type_from_format(self, fmt, mime_type):
+ """Format aliases map to the same MIME type as the matching file extension."""
+ image = Image(data=b"test", format=fmt)
+ assert image._mime_type == mime_type
+ assert image.to_image_content().mime_type == mime_type
+
def test_missing_data_and_path_raises_error(self):
"""Test that error is raised when neither path nor data is provided."""
with pytest.raises(ValueError, match="Either path or data must be provided"):