fix: chats fail when an MCP server from Tether is enabled (#34728)

MCP servers added in Tether have IDs with colons, and Open WebUI puts the server ID in front of every MCP tool name it offers to the model. OpenAI-compatible providers only accept letters, digits, underscores and dashes in tool names, so every chat with such a server turned on was rejected with `Invalid 'tools[0].function.name'`. The same happened for MCP servers whose admin-chosen ID has dots or spaces. Characters outside that set are now replaced with underscores, so these tools reach the model and their calls still go to the right MCP server. Names that were already valid are unchanged.

Fixes #34718
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-23 19:15:19 +04:00
1 parent 6122544801
commit 4eefe65bd4
1 file changed
+1 -1
+1 -1
View File
@@ -2760,7 +2760,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
tool_function = await make_tool_function(client, tool_spec['name'])
tool_name = f'{server_id}_{tool_spec["name"]}'
tool_name = re.sub(r'[^a-zA-Z0-9_-]', '_', 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]}'