Skip to content

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

Fix exclusion of content helpers if they are in a list

William Easton664b67d26fad
diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py
index c922dc9d2..d1fd03f64 100644
--- a/src/fastmcp/tools/tool.py
+++ b/src/fastmcp/tools/tool.py
@@ -546,13 +546,12 @@ def _convert_to_content(
# If any item is a ContentBlock, convert non-ContentBlock items to TextContent
# without aggregating them
- if any(isinstance(item, (Image, Audio, File)) for item in result):
+ if any(isinstance(item, ContentBlock | Image | Audio | File) for item in result):
return [
_convert_to_single_content_block(item, serializer)
- if isinstance(item, (Image, Audio, File))
+ if not isinstance(item, ContentBlock)
else item
for item in result
]
-
# If none of the items are ContentBlocks, aggregate all items into a single TextContent
return [TextContent(type="text", text=_serialize_with_fallback(result, serializer))]
diff --git a/tests/tools/test_tool.py b/tests/tools/test_tool.py
index ac6a78041..dc815b5bf 100644
--- a/tests/tools/test_tool.py
+++ b/tests/tools/test_tool.py
@@ -1087,6 +1087,9 @@ class TestConvertResultToContent:
converted = _convert_to_content(result)
assert converted == expected
+ converted = _convert_to_content([result, result])
+ assert converted == expected * 2
+
def test_convert_mixed_content(self):
result = [
"hello",