fix: MCP list results from FastMCP servers reach the model twice (#32726)

When a tool on a server built with the standalone FastMCP package returned a list, the model got the list twice, once as plain text and once as structured data, so every list result cost two to three times the tokens. That package sends the whole list as a single piece of text, a format Open WebUI did not recognise as a duplicate. The list now reaches the model once, and structured data that the text does not already contain is still passed along.

Fixes #32719
This commit is contained in:
Classic298 2026-10-20 21:46:02 +02:00 • committed by GitHub
parent cd74e6d126
commit 217766ed0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,6 +219,9 @@ class MCPClient:
# FastMCP wraps scalar/list results while keeping their original text blocks.
values = structured_content.get('result')
# The standalone fastmcp package sends the whole list as one text block.
if structured_content.keys() == {'result'} and text_jsons == [JSONCodec.dumps(values, sort_keys=True)]:
return result_content
values = values if isinstance(values, list) else [values]
if (
structured_content.keys() == {'result'}