mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: normalize empty MCP tool output to null (#4683)
* Python: normalize empty MCP tool output to null * Python: hardcode null for empty MCP output
This commit is contained in:
committed by
GitHub
Unverified
parent
c67d3523ae
commit
052ba7be07
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user