inspector icon indicating copy to clipboard operation
inspector copied to clipboard

Send HTTP DELETE on streamable transport disconnect

Open cliffhall opened this issue 6 months ago • 1 comments

  • 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)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation update

Checklist

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

Additional context

DO NOT MERGE UNTIL https://github.com/modelcontextprotocol/inspector/pull/428 is merged, this PR is a branch off that one to separate the functionality.

cliffhall avatar May 30 '25 00:05 cliffhall

LGTM after some testing :)

evalstate avatar May 30 '25 22:05 evalstate