[PR #298] Handle cancelled MCP session operations #246

Open
opened 2026-10-18 21:12:58 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/mcpo/pull/298
Author: @dongyikuan919
Created: 6/13/2026
Status: 🔄 Open

Base: main ← Head: codex/handle-cancelled-mcp-session


📝 Commits (1)

  • 84f3b47 Handle cancelled MCP session operations

📊 Changes

3 files changed (+130 additions, -8 deletions)

View changed files

📝 src/mcpo/main.py (+7 -7)
📝 src/mcpo/tests/test_main.py (+71 -1)
📝 src/mcpo/utils/main.py (+52 -0)

📄 Description

Summary

Fixes part of the stale/zombie MCP session behavior described in #90 by handling asyncio.CancelledError during MCP session operations instead of letting it escape the request path.

Changes:

  • close and clear the current MCP session when an initialize/call/reconnect operation is cancelled
  • return a normal HTTP 500 response for the affected tool call instead of allowing cancellation to bubble through ASGI lifespan handling
  • make MCP connection cleanup tolerate CancelledError while unwinding partially opened sessions/transports
  • preserve existing HTTPException details from tool errors instead of wrapping them as Unexpected error
  • add regression coverage for cancelled session operations and HTTPException preservation

Validation

  • python -m py_compile src/mcpo/main.py src/mcpo/utils/main.py src/mcpo/tests/test_main.py
  • python -m pytest src/mcpo/tests/test_main.py -> 18 passed

I also attempted the broader test run through uv run, but dependency installation failed while fetching https://pypi.org/simple/cryptography/ due to a network timeout in this environment.


🔄 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/298 **Author:** [@dongyikuan919](https://github.com/dongyikuan919) **Created:** 6/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/handle-cancelled-mcp-session` --- ### 📝 Commits (1) - [`84f3b47`](https://github.com/open-webui/mcpo/commit/84f3b47968ca087d86d9905aeaa27785025e3d43) Handle cancelled MCP session operations ### 📊 Changes **3 files changed** (+130 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/mcpo/main.py` (+7 -7) 📝 `src/mcpo/tests/test_main.py` (+71 -1) 📝 `src/mcpo/utils/main.py` (+52 -0) </details> ### 📄 Description ## Summary Fixes part of the stale/zombie MCP session behavior described in #90 by handling `asyncio.CancelledError` during MCP session operations instead of letting it escape the request path. Changes: - close and clear the current MCP session when an initialize/call/reconnect operation is cancelled - return a normal HTTP 500 response for the affected tool call instead of allowing cancellation to bubble through ASGI lifespan handling - make MCP connection cleanup tolerate `CancelledError` while unwinding partially opened sessions/transports - preserve existing `HTTPException` details from tool errors instead of wrapping them as `Unexpected error` - add regression coverage for cancelled session operations and HTTPException preservation ## Validation - `python -m py_compile src/mcpo/main.py src/mcpo/utils/main.py src/mcpo/tests/test_main.py` - `python -m pytest src/mcpo/tests/test_main.py` -> 18 passed I also attempted the broader test run through `uv run`, but dependency installation failed while fetching `https://pypi.org/simple/cryptography/` due to a network timeout in this environment. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
open-webui/mcpo#246
No description provided.