From e1248e5cfd01952bd0190cf9a8c2a158007d7750 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 1 Oct 2026 18:27:58 +0200 Subject: [PATCH] fix: chat fails when an MCP server ID plus tool name is longer than 64 characters (#31822) Open WebUI puts the MCP server ID in front of every MCP tool name it offers to the model. When the two together are longer than 64 characters, providers that cap tool names at 64 (the OpenAI API, AWS Bedrock) reject the whole chat request, even if the model never picks that tool. Names over the limit are now cut to 64 characters ending in a short hash, so the same tool always gets the same name and the MCP server is still called with the original tool name. Names that already fit are unchanged. Fixes #31821 --- backend/open_webui/utils/middleware.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 083f478cef..0b67c6deed 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -2,6 +2,7 @@ import ast import asyncio import base64 import copy +import hashlib import html import inspect import json @@ -2970,10 +2971,15 @@ async def process_chat_payload(request, form_data, user, metadata, model): tool_function = await make_tool_function(client, tool_spec['name']) - mcp_tools_dict[f'{server_id}_{tool_spec["name"]}'] = { + tool_name = f'{server_id}_{tool_spec["name"]}' + # Providers reject tool names over 64 characters + if len(tool_name) > 64: + tool_name = f'{tool_name[:55]}_{hashlib.sha256(tool_name.encode()).hexdigest()[:8]}' + + mcp_tools_dict[tool_name] = { 'spec': { **tool_spec, - 'name': f'{server_id}_{tool_spec["name"]}', + 'name': tool_name, }, 'callable': tool_function, 'type': 'mcp',