package com.peanut.modules.springai; import io.modelcontextprotocol.client.McpSyncClient; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.List; @Service public class McpHeartbeatService { private final List mcpClients; public McpHeartbeatService(List mcpClients) { this.mcpClients = mcpClients; } @Scheduled(fixedRate = 120000) // 每2分钟1次发送心跳 public void sendHeartbeat() { try { this.mcpClients.parallelStream().forEach(client -> {client.ping();}); } catch (Exception e) { e.printStackTrace(); } } }