inspector
inspector copied to clipboard
Send HTTP DELETE on streamable transport disconnect
-
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.
- add delete handler for /mcp endpoint
-
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
How Has This Been Tested?
Manually connect to the everything server, and then disconnect.
Browser devtools console
Inspector proxy server
Everything server
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.
LGTM after some testing :)