Skip to content

Commit b411cbf

Browse files
authored
Chore/385 (#390)
* chore:고정 변경사항 추적 * refactor : 10차 배포로 회귀 * chore/385 10차 배포 서비스로 회귀
1 parent d4dd83b commit b411cbf

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

cs25-service/src/main/java/com/example/cs25service/domain/ai/service/BraveSearchMcpService.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.modelcontextprotocol.spec.McpSchema.CallToolRequest;
77
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
88
import io.modelcontextprotocol.spec.McpSchema.ListToolsResult;
9-
import java.time.Duration;
109
import java.util.List;
1110
import java.util.Map;
1211
import lombok.RequiredArgsConstructor;
@@ -19,8 +18,9 @@
1918
public class BraveSearchMcpService {
2019

2120
private static final String BRAVE_WEB_TOOL = "brave_web_search";
22-
private static final Duration INIT_TIMEOUT = Duration.ofSeconds(60);
21+
2322
private final List<McpSyncClient> mcpClients;
23+
2424
private final ObjectMapper objectMapper;
2525

2626
public JsonNode search(String query, int count, int offset) {
@@ -40,36 +40,23 @@ public JsonNode search(String query, int count, int offset) {
4040
var root = objectMapper.createObjectNode();
4141
root.set("results", content);
4242
return root;
43-
4443
}
45-
}
4644

47-
private void ensureInitialized(McpSyncClient client) {
48-
if (!client.isInitialized()) {
49-
synchronized (client) { // 다중 스레드 초기화 경합 방지
50-
if (!client.isInitialized()) {
51-
log.debug("MCP 클라이언트 초기화 시작…");
52-
client.initialize(); // 매개변수 없는 버전
53-
log.debug("MCP 클라이언트 초기화 완료");
54-
}
55-
}
56-
}
45+
return content != null ? content : objectMapper.createObjectNode();
5746
}
5847

5948
private McpSyncClient resolveBraveClient() {
6049
for (McpSyncClient client : mcpClients) {
61-
try {
62-
ensureInitialized(client); // 초기화
63-
ListToolsResult tools = client.listTools();
64-
if (tools != null && tools.tools() != null &&
65-
tools.tools().stream()
66-
.anyMatch(t -> BRAVE_WEB_TOOL.equalsIgnoreCase(t.name()))) {
50+
ListToolsResult tools = client.listTools();
51+
if (tools != null && tools.tools() != null) {
52+
boolean found = tools.tools().stream()
53+
.anyMatch(tool -> BRAVE_WEB_TOOL.equalsIgnoreCase(tool.name()));
54+
if (found) {
6755
return client;
6856
}
69-
} catch (Exception e) {
70-
log.debug("Brave MCP 클라이언트 후보 실패: {}", e.toString());
7157
}
7258
}
73-
throw new IllegalStateException("Brave MCP 서버에서 '" + BRAVE_WEB_TOOL + "' 툴을 찾을 수 없습니다.");
59+
60+
throw new IllegalStateException("Brave MCP 서버에서 brave_web_search 툴을 찾을 수 없습니다.");
7461
}
7562
}

0 commit comments

Comments
 (0)