Session validation error
This PR adds exception handling to validation of incoming grpc requests in the session.
Motivation and Context
While the public interface of the session (e.g. session.send_request) makes assumptions about the data types send to the session, the StreamableHttpServerTransport does not use this, and rather sends data directly to the channel. Therefore, the validation of the incoming data in the receive loop of the session may fail. This can be integration tested by sending an invalid method to the server, which crashes the task of the particular session.
How Has This Been Tested?
I added a unit test on the session level that verifies that the session is unresponsive after a bad input. Construction of the session in the test feels a bit awkward, and there might be better ways to test this particular piece of code. One refactor idea might be to move the logic in the session loop to a separate method to better unit test it.
Breaking Changes
This change does not break any public apis. It does however change behaviour, in that the server does not crash on invalid messages, but swallows them, similar how it is already happening for notifications which can not be validated.
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
- [x] I have added or updated documentation as needed