diff --git a/python/packages/core/agent_framework/_mcp.py b/python/packages/core/agent_framework/_mcp.py index 28c5f6db6a..81227c7e73 100644 --- a/python/packages/core/agent_framework/_mcp.py +++ b/python/packages/core/agent_framework/_mcp.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio import base64 +import json import logging import re import sys @@ -87,8 +88,6 @@ def _parse_prompt_result_from_mcp( Returns: A string representation of the prompt result. """ - import json - parts: list[str] = [] for message in mcp_type.messages: content = message.content @@ -194,7 +193,7 @@ def _parse_tool_result_from_mcp( result.append(Content.from_text(str(item))) if not result: - result.append(Content.from_text("")) + result.append(Content.from_text("null")) return result diff --git a/python/packages/core/tests/core/test_mcp.py b/python/packages/core/tests/core/test_mcp.py index df3187673a..70aff972fe 100644 --- a/python/packages/core/tests/core/test_mcp.py +++ b/python/packages/core/tests/core/test_mcp.py @@ -195,13 +195,16 @@ def test_parse_tool_result_from_mcp_meta_not_in_string(): def test_parse_tool_result_from_mcp_empty_content(): - """Test that empty content produces list with empty text Content.""" + """Test that empty MCP content normalizes to JSON null text content.""" mcp_result = types.CallToolResult(content=[]) result = _parse_tool_result_from_mcp(mcp_result) assert isinstance(result, list) assert len(result) == 1 assert result[0].type == "text" - assert result[0].text == "" + assert result[0].text == "null" + + function_result = Content.from_function_result(call_id="call_null", result=result) + assert function_result.result == "null" def test_parse_tool_result_from_mcp_audio_content():