Improve error handling during request validation in BaseSession #774
+26
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a try block around the handling of
JSONRPCRequest
messages in the_receive_loop
method, mirroring the error handling already present forJSONRPCNotification
. This ensures that validation or processing errors for requests are caught and logged, preventing the receive loop from crashing and improving robustness.Motivation and Context
Previously, only notification handling was wrapped in a try block to catch and log validation or processing errors. However, requests can also fail validation or processing, which would cause the receive loop to crash or propagate exceptions. Wrapping the request handling in a try block ensures that such errors are logged and do not interrupt the session's message processing loop.
Also trying to interact with MCPs like Twilio MCP it crashes when other clients works perfectly.
How Has This Been Tested?
I manually tested it with the next MCP's:
After the changes both MCPs works with no problem.
Breaking Changes
No breaking changes.
Types of changes
Checklist
Additional context