-
Notifications
You must be signed in to change notification settings - Fork 609
Open
Description
Description
When using Java 21 McpSyncClient to consume an SSE endpoint, the client only receives the first ~83 events, then stops receiving any further data.
Wireshark confirms that the server continues sending data and TCP transmission is normal, but the Java application layer no longer triggers onNext.
Environment
- Java: 21.0.8
- Spring Boot: 3.5.4
- Server: mcp-spring-webflux 0.11.2
- Client: mcp-spring-webmvc 0.11.2
Problematic Code Snippet
io.modelcontextprotocol.client.transport.ResponseSubscribers$SseLineSubscriber
@Override
protected void hookOnSubscribe(Subscription subscription) {
sink.onRequest(n -> {
subscription.request(n); // Only passively forwards demand
});
sink.onDispose(() -> {
subscription.cancel();
});
}
Root Cause
- The HttpClient uses reactive stream backpressure: data is only pushed when subscription.request(n) is called.
- The current implementation relies on FluxSink.onRequest to passively trigger demand, which is only invoked
- when downstream subscribers request data (e.g., default request(256)).
- Once the initial demand is exhausted (~256 lines), HttpClient stops pushing new data.
Since each my SSE event typically spans 3–4 lines, this results in ~83 events being received before the stream stalls.
Possible Fix
Actively request unlimited demand in hookOnSubscribe:
@Override
protected void hookOnSubscribe(Subscription subscription) {
subscription.request(Long.MAX_VALUE); // Actively drive the stream
sink.onDispose(() -> subscription.cancel());
}
Metadata
Metadata
Assignees
Labels
No labels