[Developer] add KB Select AI Team ORDS MCP tool

This commit is contained in:
devmrko
2026-07-08 06:43:29 +09:00
parent 1cb8052045
commit 61f7e4c775
11 changed files with 635 additions and 2 deletions

View File

@@ -0,0 +1,99 @@
package com.cloudhandson.vpdbackoffice.service;
import static org.assertj.core.api.Assertions.assertThat;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.List;
import org.junit.jupiter.api.Test;
class McpSseServiceTest {
private final ObjectMapper objectMapper = new ObjectMapper();
private final SelectAiAgentOrdsService selectAiAgentOrdsService = new CapturingSelectAiAgentOrdsService();
private final McpSseService service = new McpSseService(
new EmptyToolRegistry(),
null,
selectAiAgentOrdsService,
objectMapper
);
@Test
void listsSelectAiRouterToolWithPromptAndBearerInputs() {
ObjectNode response = service.handle("default", request(1, "tools/list"));
var tools = response.path("result").path("tools");
var tool = tools.findValuesAsText("name").indexOf("ords.agent.kb_select_ai_router");
assertThat(tool).isGreaterThanOrEqualTo(0);
var router = tools.get(tool);
assertThat(router.path("inputSchema").path("required"))
.extracting(node -> node.asText())
.contains("bearerToken", "prompt");
assertThat(router.path("inputSchema").path("properties").has("conversationId")).isTrue();
}
@Test
void callsSelectAiRouterThroughOrdsService() {
ObjectNode request = request(2, "tools/call");
ObjectNode params = (ObjectNode) request.putObject("params");
params.put("name", "ords.agent.kb_select_ai_router");
ObjectNode arguments = params.putObject("arguments");
arguments.put("bearerToken", "user-bearer");
arguments.put("prompt", "고객 수를 세는 SQL을 만들어줘");
arguments.put("conversationId", "smoke-1");
ObjectNode response = service.handle("default", request);
CapturingSelectAiAgentOrdsService agentService =
(CapturingSelectAiAgentOrdsService) selectAiAgentOrdsService;
assertThat(agentService.bearerToken).isEqualTo("user-bearer");
assertThat(agentService.prompt).isEqualTo("고객 수를 세는 SQL을 만들어줘");
assertThat(agentService.conversationId).isEqualTo("smoke-1");
assertThat(response.path("error").isMissingNode()).isTrue();
assertThat(response.path("result").path("isError").asBoolean()).isFalse();
assertThat(response.path("result").path("content").get(0).path("text").asText())
.contains("KB_SELECT_AI_ROUTER_TEAM")
.contains("SELECT COUNT(*) FROM KB_CUSTOMERS");
}
private ObjectNode request(int id, String method) {
ObjectNode request = objectMapper.createObjectNode();
request.put("jsonrpc", "2.0");
request.put("id", id);
request.put("method", method);
return request;
}
private static final class EmptyToolRegistry extends McpToolRegistry {
private EmptyToolRegistry() {
super(null);
}
@Override
public List<com.cloudhandson.vpdbackoffice.domain.mcp.McpToolView> listTools() {
return List.of();
}
}
private static final class CapturingSelectAiAgentOrdsService extends SelectAiAgentOrdsService {
private String bearerToken;
private String prompt;
private String conversationId;
private CapturingSelectAiAgentOrdsService() {
super(null, null, new ObjectMapper());
}
@Override
public JsonNode run(String bearerToken, String prompt, String conversationId) {
this.bearerToken = bearerToken;
this.prompt = prompt;
this.conversationId = conversationId;
return new ObjectMapper().createObjectNode()
.put("team", "KB_SELECT_AI_ROUTER_TEAM")
.put("answer", "SELECT COUNT(*) FROM KB_CUSTOMERS");
}
}
}