Skip to content

Commit 4532b61

Browse files
committed
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 <[email protected]>
1 parent 0327165 commit 4532b61

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mcp/src/main/java/io/modelcontextprotocol/client/transport/ResponseSubscribers.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import org.reactivestreams.FlowAdapters;
1414
import org.reactivestreams.Subscription;
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
1517

1618
import io.modelcontextprotocol.spec.McpError;
1719
import reactor.core.publisher.BaseSubscriber;
@@ -31,6 +33,8 @@
3133
*/
3234
class ResponseSubscribers {
3335

36+
private static final Logger logger = LoggerFactory.getLogger(ResponseSubscribers.class);
37+
3438
record SseEvent(String id, String event, String data) {
3539
}
3640

@@ -167,6 +171,11 @@ else if (line.startsWith("event:")) {
167171
this.currentEventType.set(matcher.group(1).trim());
168172
}
169173
}
174+
else if (line.startsWith(":")) {
175+
// Ignore comment lines starting with ":"
176+
// This is a no-op, just to skip comments
177+
logger.debug("Ignoring comment line: {}", line);
178+
}
170179
else {
171180
// If the response is not successful, emit an error
172181
// TODO: This should be a McpTransportError

0 commit comments

Comments
 (0)