fix(provider): stringify MCP tool results for OpenAI-compatible APIs (#2476)

execute_func_call returns list[ContentElement] for MCP tools, but the
runner assigned that list directly to the tool-message content. The
OpenAI chat-completions spec requires tool-message content to be a
string, so OpenAI-compatible endpoints return HTTP 500 when the raw
list is sent.

Serialize the list to a string before building the tool message, using
ContentElement.__str__ which returns the text payload for text elements
and a human-readable placeholder for images and files. Fixes #2457.
This commit is contained in:
fishzjp
2026-08-27 18:19:04 +08:00
committed by GitHub
parent 95b8736e93
commit b66db86bff
2 changed files with 211 additions and 1 deletions
@@ -619,7 +619,9 @@ class LocalAgentRunner(runner.RequestRunner):
and len(func_ret) > 0
and isinstance(func_ret[0], provider_message.ContentElement)
):
tool_content = func_ret
# OpenAI-compatible APIs require tool-message content to be a
# string; a raw list of ContentElement causes HTTP 500 (#2457).
tool_content = '\n'.join(str(ce) for ce in func_ret)
else:
tool_content = json.dumps(func_ret, ensure_ascii=False)