mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #20914] [CLOSED] fix(startup): auto-initialize tool servers from TOOL_SERVER_CONNECTIONS env var #64685
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20914
Author: @SpootyMcSpoot
Created: 1/24/2026
Status: ❌ Closed
Base:
dev← Head:fix/tool-server-connections-auto-init📝 Commits (10+)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/dev6f1486fMerge pull request #19466 from open-webui/devd95f533Merge pull request #19729 from open-webui/deva7271530.6.43 (#20093)6adde20Merge pull request #20394 from open-webui/devf9b0534Merge pull request #20522 from open-webui/dev📊 Changes
1 file changed (+30 additions, -0 deletions)
View changed files
📝
backend/open_webui/main.py(+30 -0)📄 Description
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Fix the issue where
TOOL_SERVER_CONNECTIONSenvironment variable is set but tool servers are not actually initialized until the user manually visits the Admin Panel and clicks Save.Problem:
TOOL_SERVER_CONNECTIONSis aPersistentConfigthat only pre-populates the Admin Panel settings. The tools don't become available untilset_tool_servers()is called, which currently only happens when a user manually saves the config.Solution: Call
set_tool_servers()during application startup (in thelifespan()function) whenTOOL_SERVER_CONNECTIONShas entries. This makes tools available immediately without requiring manual intervention.Added
lifespan()function to callset_tool_servers()whenTOOL_SERVER_CONNECTIONSis configuredset_tool_serversfromopen_webui.utils.toolsChanged
Deprecated
Removed
Fixed
TOOL_SERVER_CONNECTIONSenvironment variable now initialize automatically on startup without requiring manual Admin Panel save (Fixes #18140)Security
Breaking Changes
Additional Information
Use Case: Users deploying Open-WebUI in Kubernetes/containerized environments want to pre-configure tool servers via environment variables for GitOps/IaC workflows. Currently this requires:
TOOL_SERVER_CONNECTIONSenv varWith this fix, steps 3-6 are eliminated - tools work immediately on startup.
Code Pattern: The implementation follows the exact same pattern used for
ENABLE_BASE_MODELS_CACHEinitialization at lines 628-647 in main.py, using a mock Request object.Comprehensive Testing Documentation
Unit Tests (10/10 Passed)
Created standalone unit test suite (
test_tool_server_startup_standalone.py) covering:initialization_called_when_connections_existset_tool_servers()is called when TOOL_SERVER_CONNECTIONS has entriesinitialization_skipped_when_no_connectionsset_tool_servers()is NOT called when emptyerror_handling_on_initialization_failuremultiple_tool_servers_counttool_servers_populated_in_app_stateopenapi_server_config_formatmcp_server_config_formatauthenticated_server_config_formatlogging_message_formatempty_list_vs_none_handlingIntegration Testing in Kubernetes
Environment:
Test Configuration:
Test Results:
Startup Initialization Test
Health Check Test
curl http://localhost:8080/health{"status":true}{"status":true}Pod Stability Test
open-webui-xxx 1/1 Running 0 12mRegression Test - Manual Save
Empty Configuration Test
Error Handling Test
ERROR | Failed to initialize tool servers: ..., app continuedCode Review Checklist
Screenshots or Videos
Startup logs showing auto-initialization:
Health endpoint confirms service running:
Pod status (stable, no restarts):
Unit test results:
Testing Confirmation
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.