Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion langchain_mcp_adapters/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def _convert_call_tool_result(
non_text_contents.append(content)

tool_content: str | list[str] = [content.text for content in text_contents]
if len(text_contents) == 1:
if not text_contents:
tool_content = ""
elif len(text_contents) == 1:
tool_content = tool_content[0]

if call_tool_result.isError:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
)


def test_convert_empty_text_content():
# Test with a single text content
result = CallToolResult(
content=[],
isError=False,
)

text_content, non_text_content = _convert_call_tool_result(result)

assert text_content == ""
assert non_text_content is None


def test_convert_single_text_content():
# Test with a single text content
result = CallToolResult(
Expand Down