Skip to content

fix(client): surface streamable http transport errors#2872

Open
go165 wants to merge 5 commits into
modelcontextprotocol:mainfrom
go165:go165/streamable-http-transport-errors
Open

fix(client): surface streamable http transport errors#2872
go165 wants to merge 5 commits into
modelcontextprotocol:mainfrom
go165:go165/streamable-http-transport-errors

Conversation

@go165

@go165 go165 commented Jun 15, 2026

Copy link
Copy Markdown

Fixes #915.

Summary

  • catch httpx.HTTPError inside Streamable HTTP per-request tasks before it escapes the transport task group
  • return a JSON-RPC INTERNAL_ERROR to the pending request so ClientSessionGroup.connect_to_server() fails with a catchable MCPError
  • add a regression test for unreachable streamable HTTP servers that guards against the cancel-scope RuntimeError path

Validation

  • PYTHONPATH=src /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pytest tests/issues/test_915_streamable_http_unreachable.py tests/client/test_notification_response.py -q
  • /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m ruff check src/mcp/client/streamable_http.py tests/issues/test_915_streamable_http_unreachable.py
  • /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m ruff format --check src/mcp/client/streamable_http.py tests/issues/test_915_streamable_http_unreachable.py
  • /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python -m pyright --pythonpath /home/ubuntu/modelcontextprotocol-python-sdk/.venv/bin/python src/mcp/client/streamable_http.py tests/issues/test_915_streamable_http_unreachable.py

@go165 go165 force-pushed the go165/streamable-http-transport-errors branch from ba61116 to 3bcaf66 Compare June 15, 2026 05:22
@go165 go165 force-pushed the go165/streamable-http-transport-errors branch from 3bcaf66 to 602e59d Compare June 15, 2026 05:26
@koriyoshi2041

Copy link
Copy Markdown

I checked this locally on the current PR head. The focused transport path looks good to me:

uv run pytest tests/issues/test_915_streamable_http_unreachable.py tests/client/test_notification_response.py -q
uv run ruff check src/mcp/client/streamable_http.py tests/issues/test_915_streamable_http_unreachable.py
uv run ruff format --check src/mcp/client/streamable_http.py tests/issues/test_915_streamable_http_unreachable.py
git diff --check origin/main...HEAD

Results: 9 pytest cases passed, ruff passed, format check passed, and diff whitespace check passed.

I also looked at one of the Ubuntu CI failures. The test suite itself got to 1785 passed / 4 skipped / 1 xfailed; the failure is from strict-no-cover reporting existing pragma: no cover lines in src/mcp/client/session_group.py, not from this PR's touched files. The new regression covers the important behavior I was worried about: connect errors become a catchable MCPError instead of escaping as the cancel-scope task error.

@go165 go165 force-pushed the go165/streamable-http-transport-errors branch from 42b1761 to be95105 Compare June 15, 2026 06:23
@go165

go165 commented Jun 15, 2026

Copy link
Copy Markdown
Author

Validation update for latest head e974b7f: GitHub CI is now green across pre-commit, readme snippets, Python 3.10-3.14 test matrix on Ubuntu/Windows, client/server conformance, zizmor, and all-green. Local checks also passed with the current worktree: PYTHONPATH=src .venv/bin/python -m pytest tests/client/test_session_group.py::test_client_session_group_establish_session_closes_stack_on_initialize_error tests/client/test_session_group.py::test_client_session_group_establish_session_parameterized tests/issues/test_915_streamable_http_unreachable.py -q, git diff --check, and python -m py_compile for the touched client/test files. Latest commit is GitHub verified (reason=valid).

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.

Exception in ClientSessionGroup if streamable_http MCP server is not available

2 participants