admin管理员组文章数量:1414628
Why is this place broadcast to all sessions, if one MCPClient initiates the call, other McPclients will also receive the call results of other clients? thanks for help
/**
* Broadcasts a message to all connected clients through their SSE connections. The
* message is serialized to JSON and sent as an SSE event with type "message". If any
* errors occur during sending to a particular client, they are logged but don't
* prevent sending to other clients.
* @param message The JSON-RPC message to broadcast to all connected clients
* @return A Mono that completes when the broadcast attempt is finished
*/
@Override
public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
return Mono.fromRunnable(() -> {
if (sessions.isEmpty()) {
logger.debug("No active sessions to broadcast message to");
return;
}
try {
String jsonText = objectMapper.writeValueAsString(message);
logger.debug("Attempting to broadcast message to {} active sessions", sessions.size());
sessions.values().forEach(session -> {
try {
session.sseBuilder.id(session.id).event(MESSAGE_EVENT_TYPE).data(jsonText);
}
catch (Exception e) {
logger.error("Failed to send message to session {}: {}", session.id, e.getMessage());
session.sseBuilder.error(e);
}
});
}
catch (IOException e) {
logger.error("Failed to serialize message: {}", e.getMessage());
}
});
}
本文标签: spring aiJAVA MCP SDK WebFlux Server Transport sendMessage is BroadcastsStack Overflow
版权声明:本文标题:spring ai - JAVA MCP SDK WebFlux Server Transport sendMessage is Broadcasts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745172003a2646032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论