refs #726: add Select AI SHOWPROMPT diagnostic tool
This commit is contained in:
@@ -10,11 +10,11 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/** MCP boundary exposing a configured Select AI generation and read-only execution tool. */
|
||||
/** MCP boundary exposing Select AI query and read-only prompt diagnostic tools. */
|
||||
@Service
|
||||
public class McpSseService {
|
||||
|
||||
private static final String SELECT_AI_VPD_QUERY_PATH = "/mcp (tools/call)";
|
||||
private static final String SELECT_AI_TOOL_PATH = "/mcp (tools/call)";
|
||||
|
||||
private final SelectAiService selectAiService;
|
||||
private final ObjectMapper objectMapper;
|
||||
@@ -67,9 +67,9 @@ public class McpSseService {
|
||||
return response;
|
||||
}
|
||||
|
||||
/** The only tool registered by this MCP server. */
|
||||
/** Tools registered by this MCP server. */
|
||||
public List<McpToolView> registeredTools() {
|
||||
return List.of(selectAiVpdQueryView());
|
||||
return List.of(selectAiQueryView(), selectAiShowpromptView());
|
||||
}
|
||||
|
||||
private ObjectNode initializeResult(String contextPath) {
|
||||
@@ -88,15 +88,16 @@ public class McpSseService {
|
||||
private ObjectNode toolsListResult() {
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
ArrayNode tools = objectMapper.createArrayNode();
|
||||
tools.add(selectAiVpdQueryTool());
|
||||
tools.add(toolDefinition(selectAiQueryView()));
|
||||
tools.add(toolDefinition(selectAiShowpromptView()));
|
||||
result.set("tools", tools);
|
||||
return result;
|
||||
}
|
||||
|
||||
private ObjectNode selectAiVpdQueryTool() {
|
||||
private ObjectNode toolDefinition(McpToolView toolView) {
|
||||
ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("name", toolName());
|
||||
item.put("description", selectAiVpdQueryView().description());
|
||||
item.put("name", toolView.name());
|
||||
item.put("description", toolView.description());
|
||||
|
||||
ObjectNode schema = objectMapper.createObjectNode();
|
||||
schema.put("type", "object");
|
||||
@@ -118,9 +119,11 @@ public class McpSseService {
|
||||
}
|
||||
|
||||
private ObjectNode toolsCallResult(JsonNode params, String vpdBearerToken) {
|
||||
String toolName = params.path("name").asText("");
|
||||
if (!toolName().equals(toolName)) {
|
||||
throw new AppException("등록되지 않은 MCP tool입니다: " + toolName);
|
||||
String calledToolName = params.path("name").asText("");
|
||||
boolean queryTool = toolName().equals(calledToolName);
|
||||
boolean showpromptTool = showpromptToolName().equals(calledToolName);
|
||||
if (!queryTool && !showpromptTool) {
|
||||
throw new AppException("등록되지 않은 MCP tool입니다: " + calledToolName);
|
||||
}
|
||||
|
||||
JsonNode arguments = params.path("arguments");
|
||||
@@ -130,15 +133,18 @@ public class McpSseService {
|
||||
}
|
||||
JsonNode response;
|
||||
try {
|
||||
response = selectAiService.generateAndExecute(token, arguments.path("prompt").asText(""));
|
||||
String prompt = arguments.path("prompt").asText("");
|
||||
response = queryTool
|
||||
? selectAiService.generateAndExecute(token, prompt)
|
||||
: selectAiService.generatePrompt(token, prompt);
|
||||
} catch (VpdTokenAccessDeniedException ignored) {
|
||||
return tokenAccessDeniedResult();
|
||||
}
|
||||
|
||||
ObjectNode payload = objectMapper.createObjectNode();
|
||||
payload.put("toolName", toolName());
|
||||
payload.put("toolName", calledToolName);
|
||||
payload.put("profile", selectAiProfile());
|
||||
payload.put("ordsPath", SELECT_AI_VPD_QUERY_PATH);
|
||||
payload.put("ordsPath", SELECT_AI_TOOL_PATH);
|
||||
payload.set("response", response);
|
||||
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
@@ -168,14 +174,25 @@ public class McpSseService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private McpToolView selectAiVpdQueryView() {
|
||||
private McpToolView selectAiQueryView() {
|
||||
String profile = selectAiProfile();
|
||||
return new McpToolView(
|
||||
toolName(),
|
||||
profile + " 프로파일로 " + toolDescription(),
|
||||
-1L,
|
||||
toolLabel(),
|
||||
SELECT_AI_VPD_QUERY_PATH
|
||||
SELECT_AI_TOOL_PATH
|
||||
);
|
||||
}
|
||||
|
||||
private McpToolView selectAiShowpromptView() {
|
||||
String profile = selectAiProfile();
|
||||
return new McpToolView(
|
||||
showpromptToolName(),
|
||||
profile + " 프로파일로 " + showpromptToolDescription(),
|
||||
-1L,
|
||||
showpromptToolLabel(),
|
||||
SELECT_AI_TOOL_PATH
|
||||
);
|
||||
}
|
||||
|
||||
@@ -205,6 +222,24 @@ public class McpSseService {
|
||||
return mcpProperties == null ? "업무 데이터에서 조회할 내용을 자연어로 입력합니다." : mcpProperties.resolvedPromptDescription();
|
||||
}
|
||||
|
||||
private String showpromptToolName() {
|
||||
return mcpProperties == null
|
||||
? "oracle.select_ai.data_showprompt"
|
||||
: mcpProperties.resolvedShowpromptToolName();
|
||||
}
|
||||
|
||||
private String showpromptToolLabel() {
|
||||
return mcpProperties == null
|
||||
? "업무 데이터 SHOWPROMPT"
|
||||
: mcpProperties.resolvedShowpromptToolLabel();
|
||||
}
|
||||
|
||||
private String showpromptToolDescription() {
|
||||
return mcpProperties == null
|
||||
? "Select AI가 SQL 생성에 사용한 prompt를 조회하는 읽기 전용 진단 도구입니다."
|
||||
: mcpProperties.resolvedShowpromptToolDescription();
|
||||
}
|
||||
|
||||
private String pretty(Object value) {
|
||||
try {
|
||||
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(value);
|
||||
|
||||
Reference in New Issue
Block a user