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
This commit is contained in:
Classic298 2026-10-01 18:27:58 +02:00 • committed by GitHub
parent 79baaca3bb
commit e1248e5cfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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',