From 0a8f48226470cbb6426f9d24f43d8bda2ba6b0c4 Mon Sep 17 00:00:00 2001 From: Konosuke Kachi Date: Mon, 28 Jul 2025 23:32:05 +0900 Subject: [PATCH] fix: properly handle full URLs in form_data.path --- backend/open_webui/routers/configs.py | 8 ++++++-- backend/open_webui/utils/tools.py | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/routers/configs.py b/backend/open_webui/routers/configs.py index a329584ca2..f8c361badc 100644 --- a/backend/open_webui/routers/configs.py +++ b/backend/open_webui/routers/configs.py @@ -7,7 +7,11 @@ from open_webui.utils.auth import get_admin_user, get_verified_user from open_webui.config import get_config, save_config from open_webui.config import BannerModel -from open_webui.utils.tools import get_tool_server_data, get_tool_servers_data +from open_webui.utils.tools import ( + get_tool_server_data, + get_tool_servers_data, + build_tool_server_url, +) router = APIRouter() @@ -135,7 +139,7 @@ async def verify_tool_servers_config( elif form_data.auth_type == "session": token = request.state.token.credentials - url = f"{form_data.url}/{form_data.path}" + url = build_tool_server_url(form_data.url, form_data.path) return await get_tool_server_data(token, url) except Exception as e: raise HTTPException( diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index 02c8b3a86b..e5f7f27384 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -489,15 +489,7 @@ async def get_tool_servers_data( if server.get("config", {}).get("enable"): # Path (to OpenAPI spec URL) can be either a full URL or a path to append to the base URL openapi_path = server.get("path", "openapi.json") - if "://" in openapi_path: - # If it contains "://", it's a full URL - full_url = openapi_path - else: - if not openapi_path.startswith("/"): - # Ensure the path starts with a slash - openapi_path = f"/{openapi_path}" - - full_url = f"{server.get('url')}{openapi_path}" + full_url = build_tool_server_url(server.get("url"), openapi_path) info = server.get("info", {}) @@ -643,3 +635,16 @@ async def execute_tool_server( error = str(err) log.exception(f"API Request Error: {error}") return {"error": error} + + +def build_tool_server_url(url: Optional[str], path: str) -> str: + """ + Build the full URL for a tool server, given a base url and a path. + """ + if "://" in path: + # If it contains "://", it's a full URL + return path + if not path.startswith("/"): + # Ensure the path starts with a slash + path = f"/{path}" + return f"{url}{path}"