Description
Describe the bug
When using the MCP Inspector in development, I want to automatically restart the server between code iterations to improve developer experience (DX), without having to restart it manually.
To achieve this, I used tsx to watch for file changes and restart the process. However, after hot reloading, the SDK throws a JSON parsing error.
To Reproduce
Steps to reproduce the behavior:
1.Open an MCP server project
2.Use tsx, nodemon, or a similar tool to hot reload the server and run it with the MCP Inspector
3.Make a change to any source file to trigger a reload
4.Observe JSON parsing errors in the inspector process console
Expected behavior
No errors should be thrown in the console between reloads. The inspector should continue to function correctly after each restart.
Logs
Error from MCP server:
SyntaxError: Unexpected token 'G', "Gracefully"... is not valid JSON
at JSON.parse (<anonymous>)
at deserializeMessage (.../sdk/dist/esm/shared/stdio.js:26:44)
at ReadBuffer.readMessage (.../sdk/dist/esm/shared/stdio.js:19:16)
at StdioClientTransport.processReadBuffer (.../sdk/dist/esm/client/stdio.js:127:50)
at Socket.<anonymous> (.../sdk/dist/esm/client/stdio.js:98:22)
...
Additional context
The error occurs during message deserialization in the SDK and is likely caused by non-JSON output being sent over the stdio stream during shutdown or restart (e.g., messages like "Gracefully restarting..." from tsx).
A possible solution is to add a guard that checks whether a line from the stdio stream is valid JSON before attempting to parse it, and gracefully skip non-JSON lines.
Let me know if you’d prefer a different approach—I'd be happy to submit a PR with a fix 🙏
Metadata
Metadata
Assignees
Labels
Type
Projects
Status