strawgate Copilot commited on
Commit
12077f6
·
unverified ·
1 Parent(s): b62084c

Apply suggestions from code review

Browse files

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

src/fastmcp/tools/tool.py CHANGED
@@ -197,13 +197,11 @@ def _convert_to_content(
197
  else:
198
  other_content.append(item)
199
 
200
- if len(other_content) == 1:
201
  other_content = _convert_to_content(
202
- other_content[0], serializer=serializer, _process_as_single_item=True
203
- )
204
- elif len(other_content) > 1:
205
- other_content = _convert_to_content(
206
- other_content, serializer=serializer, _process_as_single_item=True
207
  )
208
 
209
  return other_content + mcp_types
 
197
  else:
198
  other_content.append(item)
199
 
200
+ if other_content:
201
  other_content = _convert_to_content(
202
+ other_content[0] if len(other_content) == 1 else other_content,
203
+ serializer=serializer,
204
+ _process_as_single_item=True,
 
 
205
  )
206
 
207
  return other_content + mcp_types
tests/tools/test_tool.py CHANGED
@@ -1,6 +1,6 @@
1
  import pytest
2
  from mcp.types import EmbeddedResource, ImageContent, TextContent, TextResourceContents
3
- from pydantic import AnyUrl, BaseModel
4
 
5
  from fastmcp import FastMCP, Image
6
  from fastmcp.client import Client
@@ -520,7 +520,7 @@ class TestConvertResultToContent:
520
  assert image_item.data == "ZmFrZWltYWdlZGF0YQ=="
521
 
522
  def test_list_of_mixed_types_list(self):
523
- """Test that a list of mixed types is converted correctly."""
524
  content1 = TextContent(type="text", text="hello")
525
  image_obj = Image(data=b"fakeimagedata")
526
  basic_data = [{"a": 1}, {"b": 2}]
 
1
  import pytest
2
  from mcp.types import EmbeddedResource, ImageContent, TextContent, TextResourceContents
3
+ from pydantic import AnyUrl
4
 
5
  from fastmcp import FastMCP, Image
6
  from fastmcp.client import Client
 
520
  assert image_item.data == "ZmFrZWltYWdlZGF0YQ=="
521
 
522
  def test_list_of_mixed_types_list(self):
523
+ """Test that a list of mixed types, including a list as one of the elements, is converted correctly."""
524
  content1 = TextContent(type="text", text="hello")
525
  image_obj = Image(data=b"fakeimagedata")
526
  basic_data = [{"a": 1}, {"b": 2}]