fix: improve SSE event handling to gracefully ignore unrecognized events #423
+37
−6
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.
This change improves client resilience by gracefully handling unknown events instead of failing, allowing clients to continue processing valid events even when encountering unexpected ones.
This improves client resilience when servers send non-standard or future SSE event types.
Resolves #272 , #223 , #93, #421
Improve SSE event handling to gracefully ignore unrecognized events instead of throwing errors
Motivation and Context
Previously, when MCP clients received unrecognized Server-Sent Events (SSE) from servers, they would throw
McpError
exceptions and terminate the connection. This created fragility when::
) are sent, which should be ignored per the SSE specificationHow Has This Been Tested?
testCommentSseMessage()
to verify SSE comment lines are properly ignored:
prefixed lines)Breaking Changes
No breaking changes. This is a backward-compatible improvement that makes clients more resilient. Existing functionality remains unchanged.
Types of changes
Checklist
Additional context
Implementation Details:
sink.success()
with debug log instead ofsink.error()