diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py index a4b20d5bb..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, ContentBlock) 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 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",