mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-07 02:58:21 +00:00
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:
parent
79baaca3bb
commit
e1248e5cfd
1 changed files with 8 additions and 2 deletions
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue