[PR #194] [MERGED] enh: Allow for startup if some MCPs unavailable, graceful shutdown and better subtask handling #190

Closed
opened 2026-02-15 21:15:16 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/mcpo/pull/194
Author: @taylorwilsdon
Created: 7/12/2025
Status: Merged
Merged: 7/16/2025
Merged by: @tjbck

Base: devHead: smooth_starting


📝 Commits (10+)

  • 101c513 Gracefully shutdown uvicorn.Server on task cancellation in run()
  • 663f731 Merge pull request #162 from 021gink/graceful-uvicorn-shutdown
  • 4758d30 Merge pull request #140 from open-webui/dev
  • 1986204 Merge pull request #175 from open-webui/dev
  • 0b56c45 now correctly handles failed startups, but slowly
  • 70aec45 concurrent startup
  • 3392f9e pin timeout reasonable
  • 05b3eb3 filter out httpinfo
  • 5f42e1d cleanup, sse timeout revert, uvicorn hang fix, docs links when prefix not empty
  • 9360e1e restore connection timeout to 10s

📊 Changes

4 files changed (+197 additions, -106 deletions)

View changed files

📝 src/mcpo/main.py (+184 -89)
📝 src/mcpo/tests/test_main.py (+3 -3)
📝 src/mcpo/utils/auth.py (+9 -13)
📝 uv.lock (+1 -1)

📄 Description

@tjbck this closes:
https://github.com/open-webui/mcpo/issues/193
and several others

Pull Request Checklist

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

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • refactor: Code restructuring for better maintainability, readability, or scalability

Changelog Entry

Description

  • This pull request refactors the server lifecycle management to introduce robust graceful shutdown capabilities and a more resilient, concurrent startup process. These changes improve server stability, provide better diagnostic logging, and ensure cleaner resource management upon termination.

Added

  • GracefulShutdown class to handle SIGINT and SIGTERM signals, ensuring all server tasks are properly cancelled and awaited.
  • Concurrent initialization of MCP servers during startup using asyncio.gather in the main app lifespan for faster launch times.
  • A detailed startup summary is now logged to the console, clearly listing successfully connected and failed MCP servers.
  • Explicit connection status tracking (app.state.is_connected) for sub-applications to reliably determine connectivity.

Changed

  • The application lifespan logic was significantly refactored to support concurrent startup and provide clearer connection status reporting.
  • The main run function now integrates the GracefulShutdown handler to manage the server lifecycle.
  • The main application's description is now dynamically updated to include documentation links for only the servers that connected successfully.
  • Updated mcpo package version from 0.0.14 to 0.0.16 in uv.lock.

Deprecated

  • N/A

Removed

  • N/A

Fixed

  • N/A

Security

  • N/A

Breaking Changes

  • N/A

Additional Information

  • This refactor improves the overall robustness of the MCP server host. By handling system signals gracefully, it prevents orphaned processes and ensures a clean shutdown. The concurrent startup and improved logging make the system easier to manage and debug, especially in environments with multiple configured MCP servers.

Screenshots or Videos

  • N/A

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/mcpo/pull/194 **Author:** [@taylorwilsdon](https://github.com/taylorwilsdon) **Created:** 7/12/2025 **Status:** ✅ Merged **Merged:** 7/16/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `smooth_starting` --- ### 📝 Commits (10+) - [`101c513`](https://github.com/open-webui/mcpo/commit/101c513aebf2744225a17d51deef27f2a2d98ea4) Gracefully shutdown uvicorn.Server on task cancellation in run() - [`663f731`](https://github.com/open-webui/mcpo/commit/663f7312bb98ec17f3af4b6ec573a179da82b111) Merge pull request #162 from 021gink/graceful-uvicorn-shutdown - [`4758d30`](https://github.com/open-webui/mcpo/commit/4758d30f6cb921658c10cb9675320a598b31addb) Merge pull request #140 from open-webui/dev - [`1986204`](https://github.com/open-webui/mcpo/commit/1986204cd1c75a7aee64004880def99d2c07cd44) Merge pull request #175 from open-webui/dev - [`0b56c45`](https://github.com/open-webui/mcpo/commit/0b56c450ab68f0b55d287095e3d659359ef28274) now correctly handles failed startups, but slowly - [`70aec45`](https://github.com/open-webui/mcpo/commit/70aec45815609b3cca56e95f94c7b7478dccddd8) concurrent startup - [`3392f9e`](https://github.com/open-webui/mcpo/commit/3392f9efc951e3e2b65682f8bd92b2532ffd8802) pin timeout reasonable - [`05b3eb3`](https://github.com/open-webui/mcpo/commit/05b3eb314f460c235d564061303458e4f9a24b9c) filter out httpinfo - [`5f42e1d`](https://github.com/open-webui/mcpo/commit/5f42e1da80d9bd0a18b11fc35246588ad0932ddb) cleanup, sse timeout revert, uvicorn hang fix, docs links when prefix not empty - [`9360e1e`](https://github.com/open-webui/mcpo/commit/9360e1edd50c1b0edb5314e65c8411187a9aab82) restore connection timeout to 10s ### 📊 Changes **4 files changed** (+197 additions, -106 deletions) <details> <summary>View changed files</summary> 📝 `src/mcpo/main.py` (+184 -89) 📝 `src/mcpo/tests/test_main.py` (+3 -3) 📝 `src/mcpo/utils/auth.py` (+9 -13) 📝 `uv.lock` (+1 -1) </details> ### 📄 Description @tjbck this closes: https://github.com/open-webui/mcpo/issues/193 and several others # Pull Request Checklist **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [ ] **Testing:** Have you written and run sufficient tests to validate the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **refactor**: Code restructuring for better maintainability, readability, or scalability # Changelog Entry ### Description - This pull request refactors the server lifecycle management to introduce robust graceful shutdown capabilities and a more resilient, concurrent startup process. These changes improve server stability, provide better diagnostic logging, and ensure cleaner resource management upon termination. ### Added - [`GracefulShutdown`](src/mcpo/main.py:18) class to handle `SIGINT` and `SIGTERM` signals, ensuring all server tasks are properly cancelled and awaited. - Concurrent initialization of MCP servers during startup using `asyncio.gather` in the main app [`lifespan`](src/mcpo/main.py:102) for faster launch times. - A detailed startup summary is now logged to the console, clearly listing successfully connected and failed MCP servers. - Explicit connection status tracking (`app.state.is_connected`) for sub-applications to reliably determine connectivity. ### Changed - The application [`lifespan`](src/mcpo/main.py:102) logic was significantly refactored to support concurrent startup and provide clearer connection status reporting. - The main [`run`](src/mcpo/main.py:155) function now integrates the `GracefulShutdown` handler to manage the server lifecycle. - The main application's description is now dynamically updated to include documentation links for only the servers that connected successfully. - Updated `mcpo` package version from `0.0.14` to `0.0.16` in [`uv.lock`](uv.lock:317). ### Deprecated - N/A ### Removed - N/A ### Fixed - N/A ### Security - N/A ### Breaking Changes - N/A --- ### Additional Information - This refactor improves the overall robustness of the MCP server host. By handling system signals gracefully, it prevents orphaned processes and ensures a clean shutdown. The concurrent startup and improved logging make the system easier to manage and debug, especially in environments with multiple configured MCP servers. ### Screenshots or Videos - N/A --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 21:15:16 -05:00
yindo closed this issue 2026-02-15 21:15:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-webui/mcpo#190