Skip to content

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

Apply suggestions from code review

William Easton72e999d4be1b
diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py
index 24eb74003..ac583cf62 100644
--- a/src/fastmcp/tools/tool.py
+++ b/src/fastmcp/tools/tool.py
@@ -197,13 +197,11 @@ def _convert_to_content(
else:
other_content.append(item)
- if len(other_content) == 1:
+ if other_content:
other_content = _convert_to_content(
- other_content[0], serializer=serializer, _process_as_single_item=True
- )
- elif len(other_content) > 1:
- other_content = _convert_to_content(
- other_content, serializer=serializer, _process_as_single_item=True
+ other_content[0] if len(other_content) == 1 else other_content,
+ serializer=serializer,
+ _process_as_single_item=True,
)
return other_content + mcp_types
diff --git a/tests/tools/test_tool.py b/tests/tools/test_tool.py
index 7d84e9414..c0d6eac7e 100644
--- a/tests/tools/test_tool.py
+++ b/tests/tools/test_tool.py
@@ -1,6 +1,6 @@
import pytest
from mcp.types import EmbeddedResource, ImageContent, TextContent, TextResourceContents
-from pydantic import AnyUrl, BaseModel
+from pydantic import AnyUrl
from fastmcp import FastMCP, Image
from fastmcp.client import Client
@@ -520,7 +520,7 @@ class TestConvertResultToContent:
assert image_item.data == "ZmFrZWltYWdlZGF0YQ=="
def test_list_of_mixed_types_list(self):
- """Test that a list of mixed types is converted correctly."""
+ """Test that a list of mixed types, including a list as one of the elements, is converted correctly."""
content1 = TextContent(type="text", text="hello")
image_obj = Image(data=b"fakeimagedata")
basic_data = [{"a": 1}, {"b": 2}]