From c82e1faa4e1a5a5f62f89c4353afb8a6d7dab07b Mon Sep 17 00:00:00 2001 From: Josh Rubin Date: Tue, 30 Sep 2025 14:59:44 -0400 Subject: [PATCH] Fixed so only converted fastmcp types --- src/fastmcp/tools/tool.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py index 721917abf..c922dc9d2 100644 --- a/src/fastmcp/tools/tool.py +++ b/src/fastmcp/tools/tool.py @@ -544,10 +544,15 @@ def _convert_to_content( if all(isinstance(item, ContentBlock) for item in result): return result - # Convert items that are not ContentBlocks - return [ - _convert_to_single_content_block(item, serializer) - if not isinstance(item, ContentBlock) - else item - for item in result - ] + # 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): + return [ + _convert_to_single_content_block(item, serializer) + if isinstance(item, (Image, Audio, File)) + 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))]