mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-24 22:37:38 -05:00
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:
1 parent
6122544801
commit
4eefe65bd4
1 file changed
+1
-1
@@ -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]}'
|
||||
|
||||
Reference in new issue
Block a user