Skip to content

Comments

fix(startup): auto-initialize tool servers from TOOL_SERVER_CONNECTIONS env var#20914

Closed
SpootyMcSpoot wants to merge 13 commits intoopen-webui:devfrom
SpootyMcSpoot:fix/tool-server-connections-auto-init
Closed

fix(startup): auto-initialize tool servers from TOOL_SERVER_CONNECTIONS env var#20914
SpootyMcSpoot wants to merge 13 commits intoopen-webui:devfrom
SpootyMcSpoot:fix/tool-server-connections-auto-init

Conversation

@SpootyMcSpoot
Copy link
Contributor

@SpootyMcSpoot SpootyMcSpoot commented Jan 24, 2026

Pull Request Checklist

Before submitting, make sure you've checked the following:

  • Target branch: Verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request down below.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: No documentation update required - uses existing TOOL_SERVER_CONNECTIONS env var.
  • Dependencies: No new dependencies added.
  • Testing: Comprehensive manual and automated testing performed (see Testing section below).
  • Agentic AI Code: This PR has gone through manual review and extensive manual testing in Kubernetes environment.
  • Code review: Self-review completed, follows existing code patterns in lifespan().
  • Title Prefix: fix

Changelog Entry

Description

Fix the issue where TOOL_SERVER_CONNECTIONS environment variable is set but tool servers are not actually initialized until the user manually visits the Admin Panel and clicks Save.

Problem: TOOL_SERVER_CONNECTIONS is a PersistentConfig that only pre-populates the Admin Panel settings. The tools don't become available until set_tool_servers() is called, which currently only happens when a user manually saves the config.

Solution: Call set_tool_servers() during application startup (in the lifespan() function) when TOOL_SERVER_CONNECTIONS has entries. This makes tools available immediately without requiring manual intervention.

Added

  • Startup initialization in lifespan() function to call set_tool_servers() when TOOL_SERVER_CONNECTIONS is configured
  • Import of set_tool_servers from open_webui.utils.tools

Changed

  • N/A

Deprecated

  • N/A

Removed

  • N/A

Fixed

Security

  • N/A

Breaking Changes

  • N/A

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:

  1. Set TOOL_SERVER_CONNECTIONS env var
  2. Wait for pod to start
  3. Manually log into Admin Panel
  4. Navigate to External Tools
  5. Click Save (without changing anything)
  6. Tools finally become available

With 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_CACHE initialization 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:

Test Name Description Result
initialization_called_when_connections_exist Verifies set_tool_servers() is called when TOOL_SERVER_CONNECTIONS has entries PASS
initialization_skipped_when_no_connections Verifies set_tool_servers() is NOT called when empty PASS
error_handling_on_initialization_failure Verifies errors are caught and logged, app continues PASS
multiple_tool_servers_count Verifies multiple servers are all counted PASS
tool_servers_populated_in_app_state Verifies TOOL_SERVERS populated in app.state PASS
openapi_server_config_format Validates OpenAPI server config format PASS
mcp_server_config_format Validates MCP server config format PASS
authenticated_server_config_format Validates bearer auth config format PASS
logging_message_format Validates log message format PASS
empty_list_vs_none_handling Verifies empty list and None both skip init PASS

Integration Testing in Kubernetes

Environment:

  • Kubernetes cluster (MicroK8s)
  • Open-WebUI deployed via Helm chart
  • MCPO (MCP-to-OpenAPI proxy) tool servers

Test Configuration:

env:
  - name: TOOL_SERVER_CONNECTIONS
    value: '[{"url":"http://mcpo-filesystem:8080/openapi.json","info":{"id":"filesystem","name":"Filesystem"},"type":"openapi","auth_type":"none"},{"url":"http://mcpo-fetch:8080/openapi.json","info":{"id":"fetch","name":"Fetch"},"type":"openapi","auth_type":"none"},{"url":"http://mcpo-memory:8080/openapi.json","info":{"id":"memory","name":"Memory"},"type":"openapi","auth_type":"none"},{"url":"http://mcpo-sequential-thinking:8080/openapi.json","info":{"id":"sequential-thinking","name":"Sequential Thinking"},"type":"openapi","auth_type":"none"},{"url":"http://mcpo-time:8080/openapi.json","info":{"id":"time","name":"Time"},"type":"openapi","auth_type":"none"}]'

Test Results:

  1. Startup Initialization Test

    • Method: Deployed pod and observed startup logs
    • Expected: Log message "Initializing N tool server(s) from TOOL_SERVER_CONNECTIONS..."
    • Actual:
      INFO | open_webui.main:lifespan:653 - Initializing 5 tool server(s) from TOOL_SERVER_CONNECTIONS...
      INFO | open_webui.main:lifespan:674 - Tool servers initialized successfully
      
    • Result: PASS
  2. Health Check Test

    • Method: curl http://localhost:8080/health
    • Expected: {"status":true}
    • Actual: {"status":true}
    • Result: PASS
  3. Pod Stability Test

    • Method: Observed pod status over 10+ minutes
    • Expected: Pod remains Running, no restarts
    • Actual: open-webui-xxx 1/1 Running 0 12m
    • Result: PASS
  4. Regression Test - Manual Save

    • Method: After startup, navigated to Admin Panel > External Tools and clicked Save
    • Expected: Manual save flow still works, tools remain available
    • Actual: Save completed without error, tools working
    • Result: PASS
  5. Empty Configuration Test

    • Method: Deployed without TOOL_SERVER_CONNECTIONS env var
    • Expected: No initialization log, app starts normally
    • Actual: No "Initializing" log, app started normally
    • Result: PASS
  6. Error Handling Test

    • Method: Configured unreachable tool server URL
    • Expected: Error logged, app continues to start
    • Actual: ERROR | Failed to initialize tool servers: ..., app continued
    • Result: PASS

Code Review Checklist

  • Import added at correct location (line 63, with other utils imports)
  • Follows existing code pattern (same as ENABLE_BASE_MODELS_CACHE init at lines 628-647)
  • Uses proper async/await
  • Includes error handling with try/except
  • Logs initialization start and success/failure
  • References issue number in comment
  • No security vulnerabilities introduced (uses internal mock request only)

Screenshots or Videos

Startup logs showing auto-initialization:

INFO     | open_webui.main:lifespan:605 - Installing external dependencies of functions and tools...
INFO     | open_webui.main:lifespan:653 - Initializing 5 tool server(s) from TOOL_SERVER_CONNECTIONS...
INFO     | open_webui.main:lifespan:674 - Tool servers initialized successfully

Health endpoint confirms service running:

$ curl http://localhost:8080/health
{"status":true}

Pod status (stable, no restarts):

NAME                        READY   STATUS    RESTARTS   AGE
open-webui-xxx              1/1     Running   0          12m

Unit test results:

======================================================================
Tool Server Startup Initialization Tests
======================================================================

Running tests...

  PASS: initialization_called_when_connections_exist
  PASS: initialization_skipped_when_no_connections
  PASS: error_handling_on_initialization_failure
  PASS: multiple_tool_servers_count
  PASS: tool_servers_populated_in_app_state
  PASS: openapi_server_config_format
  PASS: mcp_server_config_format
  PASS: authenticated_server_config_format
  PASS: logging_message_format
  PASS: empty_list_vs_none_handling

----------------------------------------------------------------------
Results: 10 passed, 0 failed
----------------------------------------------------------------------

All tests passed!

Testing Confirmation

  • I have personally tested ALL changes in this PR
  • How I tested:
    • Created and ran 10 unit tests (all passed)
    • Deployed to Kubernetes with 5 MCPO tool servers
    • Verified startup initialization logs
    • Verified health endpoint
    • Verified pod stability (no restarts)
    • Verified no regression in manual Admin Panel save flow
    • Tested error handling with unreachable server
    • Tested empty configuration (no env var set)
  • Verified no regressions - existing manual save flow in Admin Panel still works as expected

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.

tjbck and others added 13 commits November 23, 2025 22:10
* refac

* fix: python pip install dep issue

* Merge pull request open-webui#20085 from joaoback/patch-19

Update translation.json (pt-BR)

* fix/refac: stt default content type

* fix/refac: temp chat image handling

* fix/refac: image action button

* chore: bump

---------

Co-authored-by: joaoback <[email protected]>
…NS env var

- Add set_tool_servers call during application startup when
  TOOL_SERVER_CONNECTIONS is configured via environment variable
- This ensures tool servers are available immediately without
  requiring manual save in Admin Panel > Settings > External Tools

Fixes open-webui#18140
@pr-validator-bot
Copy link

🚫 STOP

@SpootyMcSpoot, you are trying to merge to the main branch!

This repository does not allow direct merges to the main branch! Please retarget your PR to the dev branch ASAP or your PR will be closed!


🚫 STOP: MISSING CLA

@SpootyMcSpoot, your PR description is missing the Contributor License Agreement confirmation.
Please use the PR template when creating your pull request. The template includes the required CLA text and helps ensure you provide all necessary information.
The CLA is absolutely required for ALL PRs. Your PR will be closed due to the missing CLA.
You can find more information about our CLA in the repository documentation, the /docs repository, the PR template and the contributing guideline.


👋 Welcome and Thank You for Contributing!

We appreciate you taking the time to submit a pull request to Open WebUI!

⚠️ Important: Testing Requirements

We've recently seen an increase in PRs that have significant issues:

  • PRs that don't actually fix the bug they claim to fix
  • PRs that don't implement the feature they describe
  • PRs that break existing functionality
  • PRs that are clearly AI-generated without proper testing being done by the author
  • PRs that simply don't work as intended

These untested PRs consume significant time from maintainers and volunteer contributors who review and test PRs in their free time.
Time that could be spent testing other PRs or improving Open WebUI in other ways.

Before marking your PR as "Ready for Review":

Please explicitly confirm:

  1. ✅ You have personally tested ALL changes in this PR
  2. How you tested it (specific steps you took to verify it works)
  3. Visual evidence where applicable (screenshots or videos showing the feature/fix working) - if applicable to your specific PR

If you're not certain your PR works exactly as intended, please leave it in DRAFT mode until you've thoroughly tested it.

Thank you for helping us maintain quality and respecting the time of our community! 🙏

@SpootyMcSpoot SpootyMcSpoot changed the base branch from main to dev January 24, 2026 00:58
@SpootyMcSpoot SpootyMcSpoot reopened this Jan 24, 2026
@SpootyMcSpoot
Copy link
Contributor Author

I've updated the PR, docs and addressed requirements.

@flefevre
Copy link
Contributor

I hope it will be integrated since we cannot use tools due to this missing feature as we are using kubernetes

@tjbck
Copy link
Contributor

tjbck commented Feb 15, 2026

Addressed with f20cc6d!

@tjbck tjbck closed this Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

issue: tools does not appear on chat Window when configure with TOOL_SERVER_CONNECTIONS env

4 participants