Merge pull request #16096 from gkkachi/dev

fix: properly handle full URLs in form_data.path
This commit is contained in:
Tim Jaeryang Baek 2025-07-31 16:45:48 +04:00 committed by GitHub
commit 1f22e1d84c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 11 deletions

View file

@ -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 get_config, save_config
from open_webui.config import BannerModel 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() router = APIRouter()
@ -135,7 +139,7 @@ async def verify_tool_servers_config(
elif form_data.auth_type == "session": elif form_data.auth_type == "session":
token = request.state.token.credentials 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) return await get_tool_server_data(token, url)
except Exception as e: except Exception as e:
raise HTTPException( raise HTTPException(

View file

@ -489,15 +489,7 @@ async def get_tool_servers_data(
if server.get("config", {}).get("enable"): 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 # 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") openapi_path = server.get("path", "openapi.json")
if "://" in openapi_path: full_url = build_tool_server_url(server.get("url"), 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}"
info = server.get("info", {}) info = server.get("info", {})
@ -643,3 +635,16 @@ async def execute_tool_server(
error = str(err) error = str(err)
log.exception(f"API Request Error: {error}") log.exception(f"API Request Error: {error}")
return {"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}"