Skip to content

Send DELETE request when closing a Streamable HTTP session on the client #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2025

Conversation

halter73
Copy link
Contributor

This updates StreamableHttpClientSessionTransport.DisposeAsyncto send a delete request.

  1. Clients that no longer need a particular session (e.g., because the user is leaving the client application) SHOULD send an HTTP DELETE to the MCP endpoint with the Mcp-Session-Id header, to explicitly terminate the session.
  • The server MAY respond to this request with HTTP 405 Method Not Allowed, indicating that the server does not allow clients to terminate sessions.

https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http

halter73 added 4 commits June 17, 2025 15:13
- Catch and log errors
- Send _negotiatedProtocolVersion
…sposed multiple times

- This is the same approach we use in McpEndpoint and SseWriter
- I went for a minimal change, but I can copy this to TransportBase if we like to use it for all derived types
- We could also update AutoDetectingClientSessionTransport.InitializeAsync to avoid this, but we shouldn't have to
@halter73
Copy link
Contributor Author

I updated this PR to now log any exceptions that might be thrown while sending the delete request.

I also included a fix for #512 so we don't have to wait on the auth PR. I scoped the ODE fix down to the StreamableHttpClientSessionTransport for now, but I could move this down to TransportBase in a later PR if we like the approach.

And finally, I also included a workaround for the race in Kestrel I describe in dotnet/aspnetcore#62385 that was causing some of our tests to hang. Until Kestrel is fixed, Kestrel may still think that it's waiting on the client to close the connection during shutdown causing Kestrel to unnecessarily wait an extra 30 seconds when the race condition occurs, but at least the tests should finish.

@halter73 halter73 requested a review from stephentoub June 19, 2025 00:44
@halter73 halter73 merged commit a4b4eda into modelcontextprotocol:main Jun 19, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants