Skip to content

fix(server): handle POST body disconnects gracefully - #3249

Open
Linxiushen wants to merge 1 commit into
modelcontextprotocol:mainfrom
Linxiushen:fix/client-disconnect-post
Open

fix(server): handle POST body disconnects gracefully#3249
Linxiushen wants to merge 1 commit into
modelcontextprotocol:mainfrom
Linxiushen:fix/client-disconnect-post

Conversation

@Linxiushen

Copy link
Copy Markdown

Summary

  • handle Starlette ClientDisconnect while reading a Streamable HTTP POST body as a normal client-side event
  • return without attempting to send an HTTP 500 response to a client that has already disconnected
  • keep the disconnect out of the internal session stream because no JSON-RPC message was parsed or dispatched
  • add direct ASGI regression coverage for the partial-body disconnect path

Fixes #1648.

Verification

  • uv run --frozen pytest tests/server/test_streamable_http_router.py -q (4 passed)
  • uv run --frozen ruff check src/mcp/server/streamable_http.py tests/server/test_streamable_http_router.py
  • uv run --frozen ruff format --check src/mcp/server/streamable_http.py tests/server/test_streamable_http_router.py
  • uv run --frozen pyright src/mcp/server/streamable_http.py tests/server/test_streamable_http_router.py (0 errors)

The full scripts/test -n 0 run collected 5,592 tests but could not complete on this Windows host because unrelated stdio interaction tests were unable to spawn child Python processes (PermissionError: [WinError 5]).

AI assistance was used during investigation and implementation. I reviewed the final diff and take responsibility for the change.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

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.

ClientDisconnect returns HTTP 500

1 participant