fix: handle the client disconnect so that the server does not crash.
I noticed that the Inspector can only connect to a server once. Once disconnected, nothing appears to work. Upon some debugging, I realized that it is because the server got an error in its SSE message in the case where the client is disconnected.
Motivation and Context
With this change, the "Restart" and "Disconnect" buttons at the bottom of the SideBar will work as expected.
How Has This Been Tested?
Yes. The test scenario is pretty straightforward:
- After starting the application, configure it to connect to a MCP server using stdio mode
- Click Restart and confirm that everything still works as expected (before the fix, everything stops working at this point)
- Click Disconnect, the button changes to Connect as expected
- Click Connect and confirm everything works as expected (before the fix Connect button does not do anything at this point)
Breaking Changes
No.
Types of changes
- [x] 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
- [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
Before I realized it was the server that was crashing, I was looking into client-server communication. In that process, I cleaned up the console logging so that it is clear which API on the server was called without having to remember the code. I believe that makes an easier troubleshooting experience although I understand those changes are not related to the bug fix. I am happy to submit a separate PR for the logging enhancement if that is better.