Skip to content

Conversation

@cliffhall
Copy link
Member

  • In server/src/index.ts

    • add delete handler for /mcp endpoint
      • gets the server transport for the sessionId
      • calls terminateSession on it
      • removes the webapp and server transports for the sessionId from the maps
      • returns status 200 to the client.
  • In client/src/lib/hooks/useConnection.ts

    • import Transport
    • add useState for clientTransport, type Transport or null initialized to null
    • in connect() function
      • move creation of client transport down a ways, just before calling client.connect with it
      • immendiately efter calling client.connect, call setClientTransport with the connected transport (has to happen after, so that what's saved has the abort controller, etc. otherwise it doesn't work to save it prior.
      • in disconnect() function
        • immediately call clientTransport.terminateSession if transportType is "streamable-http"
        • setClientTransport to null

Motivation and Context

For StreamableHttp transport, the spec says

Screenshot 2025-05-29 at 7 56 06 PM

How Has This Been Tested?

Manually connect to the everything server, and then disconnect.

Browser devtools console

Screenshot 2025-05-29 at 7 58 26 PM

Inspector proxy server

Screenshot 2025-05-29 at 8 01 26 PM

Everything server

Screenshot 2025-05-29 at 8 01 03 PM

NOTE

The sessionIds differ in the above reports for the Inspector proxy and the everything MCP server because there are two transports each direction. I.e.,

  • Client -> Proxy sessionId = 967785de-3cb1-4c6a-987f-505ce56ae947
  • Proxy -> MCP sessionId = 84cbb2d2-b853-49c4-8b4b-9c79b0172db3

Breaking Changes

Nope.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

DO NOT MERGE UNTIL #428 is merged, this PR is a branch off that one to separate the functionality.

* In server/src/index.ts
  - add delete handler for /mcp endpoint
    - gets the server transport for the sessionId
    - calls terminateSession on it
    - removes the webapp and server transports for the sessionId from the maps
    - returns status 200 to the client.

* In client/src/lib/hooks/useConnection.ts
  - import Transport
  - add useState for clientTransport, type Transport or null initialized to null
  - in connect() function
    - move creation of client transport down a ways, just before calling client.connect with it
    - immendiately efter calling client.connect, call setClientTransport with the connected transport (has to happen after, so that what's saved has the abort controller, etc. otherwise it doesn't work to save it prior.
    - in disconnect() function
      - immediately call clientTransport.terminateSession if transportType is "streamable-http"
      - setClientTransport to null
@cliffhall cliffhall marked this pull request as ready for review May 30, 2025 15:57
@cliffhall cliffhall mentioned this pull request May 30, 2025
10 tasks
@evalstate
Copy link
Member

LGTM after some testing :)

@cliffhall cliffhall merged commit 7df0ac4 into modelcontextprotocol:main Jun 2, 2025
2 checks passed
@cliffhall cliffhall deleted the send-delete-on-streamable-http-disconnect branch June 2, 2025 14:05
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.

2 participants