Skip to content

Deleting the session logs a warning if the server responds with HTTP 204 #696

Closed
@nbarbettini

Description

@nbarbettini

Describe the bug
When sending an HTTP DELETE request to end the current session, this client SDK will log a warning if the server responds with 204 instead of 200:

elif response.status_code != 200:
logger.warning(f"Session termination failed: {response.status_code}")

HTTP 204 is an acceptable status code for a DELETE that has no response payload.

To Reproduce
Given this simple client:

async def run():
    # Connect to a streamable HTTP server
    async with streamablehttp_client(
        "<server_url>",
        headers=headers,
    ) as (
        read_stream,
        write_stream,
        _,
    ):
        # Create a session using the client streams
        async with ClientSession(read_stream, write_stream) as session:
            # Initialize the connection
            await session.initialize()

            # List available tools
            tools = await session.list_tools()

Running it produces:

❯ python main.py
Session termination failed: 204

Expected behavior
No warning. 204 is the correct response code to return for a body-less response, per RFC 7231.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions