feat: handle SSE comment messages

- Add support for ignoring SSE comment lines that start with ':'
- Add debug logging for comment line processing

Resolves #443

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov 2025-08-07 10:03:41 +01:00
commit d756be1629

View file

@ -12,6 +12,8 @@ import java.util.regex.Pattern;
import org.reactivestreams.FlowAdapters;
import org.reactivestreams.Subscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.modelcontextprotocol.spec.McpError;
import reactor.core.publisher.BaseSubscriber;
@ -31,6 +33,8 @@ import reactor.core.publisher.FluxSink;
*/
class ResponseSubscribers {
private static final Logger logger = LoggerFactory.getLogger(ResponseSubscribers.class);
record SseEvent(String id, String event, String data) {
}
@ -167,6 +171,11 @@ class ResponseSubscribers {
this.currentEventType.set(matcher.group(1).trim());
}
}
else if (line.startsWith(":")) {
// Ignore comment lines starting with ":"
// This is a no-op, just to skip comments
logger.debug("Ignoring comment line: {}", line);
}
else {
// If the response is not successful, emit an error
// TODO: This should be a McpTransportError