diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index 42f9573aa..0774522db 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -490,8 +490,17 @@ async def get_tool_servers_data( server_entries = [] for idx, server in enumerate(servers): if server.get("config", {}).get("enable"): - url_path = server.get("path", "openapi.json") - full_url = f"{server.get('url')}/{url_path}" + # 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}" info = server.get("info", {}) diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 710179c12..268be397b 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -346,11 +346,15 @@ export const getToolServersData = async (i18n, servers: object[]) => { .map(async (server) => { const data = await getToolServerData( (server?.auth_type ?? 'bearer') === 'bearer' ? server?.key : localStorage.token, - server?.url + '/' + (server?.path ?? 'openapi.json') + (server?.path ?? '').includes('://') + ? server?.path + : `${server?.url}${(server?.path ?? '').startsWith('/') ? '' : '/'}${server?.path}` ).catch((err) => { toast.error( i18n.t(`Failed to connect to {{URL}} OpenAPI tool server`, { - URL: server?.url + '/' + (server?.path ?? 'openapi.json') + URL: (server?.path ?? '').includes('://') + ? server?.path + : `${server?.url}${(server?.path ?? '').startsWith('/') ? '' : '/'}${server?.path}` }) ); return null; diff --git a/src/lib/components/AddServerModal.svelte b/src/lib/components/AddServerModal.svelte index fb8c66b23..1c9ce46e2 100644 --- a/src/lib/components/AddServerModal.svelte +++ b/src/lib/components/AddServerModal.svelte @@ -53,7 +53,7 @@ if (direct) { const res = await getToolServerData( auth_type === 'bearer' ? key : localStorage.token, - `${url}/${path}` + path.includes('://') ? path : `${url}${path.startsWith('/') ? '' : '/'}${path}` ).catch((err) => { toast.error($i18n.t('Connection failed')); }); @@ -237,12 +237,11 @@