From 37af63b6496d545f6f2d4e8067ea01de209e218b Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 24 Oct 2026 23:21:30 +0200 Subject: [PATCH] fix: models get an unreadable dump instead of the MCP server's error message (#32942) * fix: MCP tool errors reach the model as a Python list dump instead of the server's message When an MCP tool server answered a call with an error, the model got a Python dump of the whole result list, with quotes, annotations and meta fields, instead of the error text the server wrote. Line breaks in the message were escaped as well, so a validation error listing the missing argument was hard to read and models tended to retry the same broken call. The model now gets the server's error text as written, the same way successful results already arrive. Fixes #32918 * refac: drop the fallback text for MCP errors with no message The error now carries only the text the server sent. * fix: keep a readable error when an MCP error has no text MCP error results that only carry images, audio or resources now give the model a short error message instead of an empty one. --- backend/open_webui/utils/mcp/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/utils/mcp/client.py b/backend/open_webui/utils/mcp/client.py index d3ec775cbd..15bd5ed46b 100644 --- a/backend/open_webui/utils/mcp/client.py +++ b/backend/open_webui/utils/mcp/client.py @@ -170,9 +170,10 @@ class MCPClient: result_dict = result.model_dump(mode='json', by_alias=True) result_content = result_dict['content'] + texts = [item['text'] for item in result_content if item['type'] == 'text'] if result.is_error: - raise Exception(result_content) + raise Exception('\n'.join(texts) or 'MCP tool call returned an error.') structured_content = result_dict.get('structuredContent') if structured_content is None: @@ -180,7 +181,6 @@ class MCPClient: # Compare serialized JSON: Python equality treats True and 1 as the same value. structured_json = JSONCodec.dumps(structured_content, sort_keys=True) - texts = [item['text'] for item in result_content if item['type'] == 'text'] text_jsons = [] for text in texts: try: