Skip to content

Handle cancelled MCP session operations#298

Open
dongyikuan919 wants to merge 1 commit into
open-webui:mainfrom
dongyikuan919:codex/handle-cancelled-mcp-session
Open

Handle cancelled MCP session operations#298
dongyikuan919 wants to merge 1 commit into
open-webui:mainfrom
dongyikuan919:codex/handle-cancelled-mcp-session

Conversation

@dongyikuan919

Copy link
Copy Markdown

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.

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.

1 participant