Skip to content

Commit d75adb6

Browse files
committed
feat(sse): expand accepted HTTP status codes for SSE stream connection
Accept HTTP status codes 200, 201, 202, and 206 as valid responses for SSE stream connection. Improves error message to include actual status code. Removes unused main method. Resolves #68
1 parent a424b36 commit d75adb6

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

mcp/src/main/java/org/springframework/ai/mcp/client/transport/FlowSseClient.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -198,39 +198,14 @@ public void onComplete() {
198198
info -> subscriberFactory.apply(lineSubscriber));
199199

200200
future.thenAccept(response -> {
201-
if (response.statusCode() != 200) {
202-
throw new RuntimeException("Failed to connect to SSE stream: " + response.statusCode());
201+
int status = response.statusCode();
202+
if (status != 200 && status != 201 && status != 202 && status != 206) {
203+
throw new RuntimeException("Failed to connect to SSE stream. Unexpected status code: " + status);
203204
}
204205
}).exceptionally(throwable -> {
205206
eventHandler.onError(throwable);
206207
return null;
207208
});
208209
}
209210

210-
// public static void main(String[] args) {
211-
212-
// FlowSseClient sseClient = new FlowSseClient(
213-
// HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build());
214-
215-
// var eventHandler = new SSEEventHandler() {
216-
// @Override
217-
// public void onEvent(SSEEvent event) {
218-
// System.out.println("Received event: " + event);
219-
// }
220-
221-
// @Override
222-
// public void onError(Throwable error) {
223-
// System.out.println("Error: " + error);
224-
// }
225-
// };
226-
// sseClient.subscribe("http://localhost:8080/sse", eventHandler);
227-
228-
// try {
229-
// Thread.sleep(100000);
230-
// }
231-
// catch (InterruptedException e) {
232-
// e.printStackTrace();
233-
// }
234-
// }
235-
236211
}

0 commit comments

Comments
 (0)