Skip to content

Commit 3504574

Browse files
plaflammessmails
authored andcommitted
fix: handle empty tool response (langchain-ai#115)
1 parent 781e57c commit 3504574

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

langchain_mcp_adapters/tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def _convert_call_tool_result(
2727
non_text_contents.append(content)
2828

2929
tool_content: str | list[str] = [content.text for content in text_contents]
30-
if len(text_contents) == 1:
30+
if not text_contents:
31+
tool_content = ""
32+
elif len(text_contents) == 1:
3133
tool_content = tool_content[0]
3234

3335
if call_tool_result.isError:

tests/test_tools.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
)
2020

2121

22+
def test_convert_empty_text_content():
23+
# Test with a single text content
24+
result = CallToolResult(
25+
content=[],
26+
isError=False,
27+
)
28+
29+
text_content, non_text_content = _convert_call_tool_result(result)
30+
31+
assert text_content == ""
32+
assert non_text_content is None
33+
34+
2235
def test_convert_single_text_content():
2336
# Test with a single text content
2437
result = CallToolResult(

0 commit comments

Comments
 (0)