Title: fix: improve SSE event handling to gracefully ignore unrecognized events by tzolov · Pull Request #423 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: fix: improve SSE event handling to gracefully ignore unrecognized events by tzolov · Pull Request #423 · modelcontextprotocol/java-sdk
X Title: fix: improve SSE event handling to gracefully ignore unrecognized events by tzolov · Pull Request #423 · modelcontextprotocol/java-sdk
Description: 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. Replace McpError exceptions with debug/warning logs for unrecognized SSE event types Continue processing instead of failing when encountering unknown SSE events Update transport implementations: WebClientStreamableHttpTransport: return empty tuple instead of throwing WebFluxSseClientTransport: complete stream instead of erroring HttpClientSseClientTransport: call sink.success() instead of sink.error() HttpClientStreamableHttpTransport: return empty Flux for unknown events 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: Servers send non-standard SSE event types Future MCP versions introduce new SSE event types that older clients don't recognize SSE comment lines (starting with :) are sent, which should be ignored per the SSE specification How Has This Been Tested? Added unit test testCommentSseMessage() to verify SSE comment lines are properly ignored Existing transport tests continue to pass, ensuring backward compatibility Tested scenarios include: SSE comment lines (: prefixed lines) Unknown SSE event types Mixed streams with both recognized and unrecognized events Breaking Changes No breaking changes. This is a backward-compatible improvement that makes clients more resilient. Existing functionality remains unchanged. Types of changes 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 I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context Implementation Details: WebClientStreamableHttpTransport: Returns empty tuple instead of throwing WebFluxSseClientTransport: Completes stream with warning log instead of erroring HttpClientSseClientTransport: Calls sink.success() with debug log instead of sink.error() HttpClientStreamableHttpTransport: Returns empty Flux for unknown events
Open Graph Description: 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. Replac...
X Description: 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. Replac...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/pull/423
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:28a50d7c-858f-67ae-39e9-f2cc50e231b4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9D8C:2DDB6E:53A52C2:73BBA51:6A5E97EA |
| html-safe-nonce | 83a02d2482c8122fd62d11c51496abeb31bcd03342526004187f938f159887bd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDhDOjJEREI2RTo1M0E1MkMyOjczQkJBNTE6NkE1RTk3RUEiLCJ2aXNpdG9yX2lkIjoiNjI4ODEwOTY1NTMyNTMxNzA5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2f008451294934a1e2cb352866589e4db20c007911bde625fcb22e1285e4633e |
| hovercard-subject-tag | pull_request:2692179072 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/java-sdk/pull/423/files |
| twitter:image | https://avatars.githubusercontent.com/u/1351573?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1351573?s=400&v=4 |
| og:image:alt | 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. Replac... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7c7e31acb6a895494e518b880f5ccf39604f7fa9a8f2f3c64145efc3b776256d |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 919609219 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/java-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 919609219 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/java-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d2ac9bdd71d5f53f2b731c9330677e38624e301 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width