python-sdk
python-sdk copied to clipboard
Fix flaky SSE tests: test_sse_client_basic_connection_mounted_app and test_request_context_isolation
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_apptests/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
Opened a PR to fix this: #2073
Two changes:
- 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) - Removed unreachable dead code after blocking
server.run()calls inrun_server()andrun_mounted_server()