-
Notifications
You must be signed in to change notification settings - Fork 353
fix: Add an exception handling function to WebFluxSseClientTransport #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
*/ | ||
private BiFunction<Throwable, ServerSentEvent<String>, Mono<? extends JSONRPCMessage>> sseErrorHandler = (error, | ||
event) -> { | ||
logger.warn("Failed to handle SSE event {}", event, error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -215,12 +226,26 @@ else if (MESSAGE_EVENT_TYPE.equals(event.event())) { | |||
else { | |||
s.error(new McpError("Received unrecognized SSE event type: " + event.event())); | |||
} | |||
}).transform(handler)).subscribe(); | |||
}).onErrorResume(e -> sseErrorHandler.apply(e, event)).transform(handler)).subscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `sseErrorHandler` is used to handle errors when processing SSE events and situations where an unrecognized event type is received. - Add unit tests to verify. Signed-off-by: YunKui Lu <[email protected]>
i met the same matter how to solve it? 2025-05-09 16:07:23 INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-9004"] |
This issue arises because the server did not strictly follow the MCP protocol when sending messages. If you are using spring-ai, you need to remove
|
sseErrorHandler
is used to handle errors when processing SSE events and situations where an unrecognized event type is received.Motivation and Context
Users can use custom handlers when they encounter the following exceptions:
#93
spring-projects/spring-ai#2936
All other clients are compatible with this, but the WebFlux client throws an exception, which is necessary to fix.
Although the MCP protocol does not allow any message types other than JSON-PRC, users should have a way to handle it instead of having the client stop. Therefore, I did not attempt to ignore it. Instead, I simply made it clearly visible in the log without interrupting the connection.
How Has This Been Tested?
Breaking Changes
I've provided a default error handler that prints the exception. User can also override it with the set method.
Types of changes
Checklist
Additional context
Since I added a new field to catch exceptions, I need Member to confirm that the design conforms to the future path of Mcp Java Sdk. Thus avoiding the introduction of an AD hoc solution.