Skip to content

Fix flaky test test_response in test_streamable_http.py #1573

Description

@maxisbey

Initial Checks

Description

The test is flaky. See: https://github.com/modelcontextprotocol/python-sdk/actions/runs/19020904095/job/54315849330?pr=1565

Output:

basic_server = None, basic_server_url = 'http://127.0.0.1:50695/'

    def test_response(basic_server: None, basic_server_url: str):
        """Test response handling for a valid request."""
        mcp_url = f"{basic_server_url}/mcp"
        response = requests.post(
            mcp_url,
            headers={
                "Accept": "application/json, text/event-stream",
                "Content-Type": "application/json",
            },
            json=INIT_REQUEST,
        )
>       assert response.status_code == 200
E       assert 404 == 200
E        +  where 404 = <Response [404]>.status_code

tests/shared/test_streamable_http.py:624: AssertionError

Example Code

Python & MCP Python SDK

1.19.0

Activity

  1. added
    bugSomething isn't working
    P3Nice to haves, rare edge cases
    on Nov 4, 2025
  2. maxisbey commented on Jun 3, 2026

    @maxisbey
    ContributorAuthor

    The 404 here was the bind-then-close port race: under pytest-xdist, two workers could pick the same ephemeral port, the readiness poll succeeded against the other worker's server, and the request got that server's 404. As of #2767 (with #2764/#2765), test_response and the rest of these files run in process with no sockets or ports at all, so this failure mode no longer exists. Closing.

    AI Disclaimer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions