Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b49e191

Browse files
committed
Update MCPApplication.java
1 parent accd36d commit b49e191

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/main/java/org/tinystruct/mcp/MCPApplication.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public String shutdown(Response response) throws ApplicationException {
103103
return jsonRpcHandler.createErrorResponse("Not in ready state", ErrorCodes.NOT_INITIALIZED);
104104
}
105105

106-
sseHandler.closeAllConnections();
106+
sseHandler.closeAll();
107107
sessionState = SessionState.DISCONNECTED;
108108

109109
JsonRpcResponse jsonResponse = new JsonRpcResponse();
@@ -131,13 +131,12 @@ public String events(Response response, Request request) throws ApplicationExcep
131131
}
132132

133133
String clientId = UUID.randomUUID().toString();
134-
SSEHandler.SSESession session = sseHandler.createSession(clientId);
134+
sseHandler.registerClient(clientId, response);
135135
sseHandler.setupSSEHeaders(response);
136-
137-
// Send initial connection event
138-
session.sendEvent(Events.CONNECTED, "{\"clientId\":\"" + clientId + "\"}");
139-
return session.getOutput();
140-
136+
// 发送初始连接事件
137+
sseHandler.sendEvent(clientId, Events.CONNECTED, "{\"clientId\":\"" + clientId + "\"}");
138+
// SSE 连接应保持打开,返回空字符串即可
139+
return "";
141140
} catch (Exception e) {
142141
LOGGER.log(Level.SEVERE, "SSE connection failed", e);
143142
response.setStatus(ResponseStatus.INTERNAL_SERVER_ERROR);
@@ -239,7 +238,7 @@ protected void handleShutdown(JsonRpcRequest request, JsonRpcResponse response)
239238
return;
240239
}
241240

242-
sseHandler.closeAllConnections();
241+
sseHandler.closeAll();
243242
sessionState = SessionState.DISCONNECTED;
244243

245244
response.setId(request.getId());

0 commit comments

Comments
 (0)