Skip to content

Allow controlling session termination - don't automatically send DELETE on disposal #621

@cristipufu

Description

@cristipufu

Problem

The StreamableHttpClientSessionTransport class automatically sends a DELETE request to terminate the session when the transport is disposed (in the DisposeAsync method). This behavior cannot be controlled by the consumer and may not always be desired.

Also, a consumer may need multiple transports to share the same session id. How could that be implemented?

Current Behavior

public override async ValueTask DisposeAsync()
{
    // ...
    // Send DELETE request to terminate the session. Only send if we have a session ID, per MCP spec.
    if (!string.IsNullOrEmpty(SessionId))
    {
        await SendDeleteRequest();
    }
    // ...
}

Requested Enhancement

Provide a way to control whether the DELETE request should be sent automatically on disposal. This could be implemented as:

  • Add a boolean property/option (e.g., AutoTerminateSession) to SseClientTransportOptions that defaults to true for backward compatibility
  • Add a separate public method like TerminateSessionAsync() that can be called explicitly

Use Case

There are scenarios where:

  • The session should persist beyond the transport's lifetime
  • Session termination should be handled at a different layer
  • Multiple transports might share the same session
  • The application wants to handle session cleanup differently based on the disposal reason

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