inspector icon indicating copy to clipboard operation
inspector copied to clipboard

fix: handle the client disconnect so that the server does not crash.

Open wolfdancer opened this issue 8 months ago • 0 comments

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:

  1. After starting the application, configure it to connect to a MCP server using stdio mode
  2. Click Restart and confirm that everything still works as expected (before the fix, everything stops working at this point)
  3. Click Disconnect, the button changes to Connect as expected
  4. 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.

wolfdancer avatar May 06 '25 22:05 wolfdancer