python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Fix flaky SSE tests: test_sse_client_basic_connection_mounted_app and test_request_context_isolation

Open maxisbey opened this issue 11 months ago • 1 comments

Initial Checks

  • [x] I confirm that I'm using the latest version of MCP Python SDK
  • [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue

Description

Two SSE tests in tests/shared/test_sse.py are flaky:

Affected tests:

  • test_sse_client_basic_connection_mounted_app (line 326)
  • test_request_context_isolation (line 462)

CI evidence: https://github.com/modelcontextprotocol/python-sdk/actions/runs/19330649603/job/55292600721?pr=1586

Test locations:

  • tests/shared/test_sse.py:326 - test_sse_client_basic_connection_mounted_app
  • tests/shared/test_sse.py:462 - test_request_context_isolation

Related Issues

  • #737 - RuntimeError: Received request before initialization was complete (SSE)
  • #1573 - Similar flaky test pattern in streamable HTTP (404 instead of 200)

Python & MCP Python SDK

Latest SDK version

AI Disclaimer

maxisbey avatar Dec 11 '25 14:12 maxisbey

Opened a PR to fix this: #2073

Two changes:

  1. Enhanced wait_for_server() with a two-stage readiness check — after TCP connect succeeds, it now makes an actual HTTP request to confirm the ASGI app is handling requests (not just that the port is open)
  2. Removed unreachable dead code after blocking server.run() calls in run_server() and run_mounted_server()

BabyChrist666 avatar Feb 17 '26 04:02 BabyChrist666