refactor: enforce Single Source of Truth for tool metadata by removing YML property overriding logic

This commit is contained in:
jade
2026-07-10 11:08:05 +09:00
parent f84865ab8e
commit 332fa64e2e
3 changed files with 6 additions and 50 deletions

View File

@@ -206,37 +206,7 @@ public class ToolScaffolder {
Files.writeString(serviceDir.resolve(baseName + "Service.java"), serviceContent); Files.writeString(serviceDir.resolve(baseName + "Service.java"), serviceContent);
// Append to YAML
Path resourcesDir = rootDir.resolve(Paths.get(moduleName, "src/main/resources"));
Files.createDirectories(resourcesDir);
Path yamlPath = resourcesDir.resolve("application-local.yml");
String yamlContent = "";
if (Files.exists(yamlPath)) {
yamlContent = Files.readString(yamlPath);
}
String newFunctionYaml = """
%s:
description: "%s"
prompt: "%s"
mappingId: "%s"
""".formatted(toolName, description, description + " 해줘.", interfaceId);
if (yamlContent.contains("functions:")) {
yamlContent = yamlContent.replaceFirst("functions:", "functions:" + newFunctionYaml);
} else {
if (!yamlContent.isEmpty() && !yamlContent.endsWith("\n")) {
yamlContent += "\n";
}
yamlContent += """
mcp:
functions:%s""".formatted(newFunctionYaml);
}
Files.writeString(yamlPath, yamlContent);
log.append("[YAML] ").append(yamlPath).append(" (함수 설정 자동 등록됨)\n");
log.append("\n=========================================\n"); log.append("\n=========================================\n");
log.append(" Scaffolding Complete!\n"); log.append(" Scaffolding Complete!\n");

View File

@@ -26,14 +26,5 @@ import java.util.Map;
public class McpProperties { public class McpProperties {
private String namespace; private String namespace;
private Map<String, FunctionProp> functions;
@Data
public static class FunctionProp {
private String description;
private String prompt;
private String mappingId;
private Boolean register;
private Boolean visible;
}
} }

View File

@@ -85,30 +85,25 @@ public class ToolRegistryHeartbeatSender {
? mcpProperties.getNamespace() + "_" + baseName ? mcpProperties.getNamespace() + "_" + baseName
: baseName; : baseName;
McpProperties.FunctionProp prop = null; boolean isRegister = functionAnnotation.register();
if (mcpProperties.getFunctions() != null) {
prop = mcpProperties.getFunctions().get(baseName);
}
boolean isRegister = prop != null && prop.getRegister() != null ? prop.getRegister() : functionAnnotation.register();
if (!isRegister) { if (!isRegister) {
log.info(" [HeartbeatSender] '{}' 툴은 설정에 의해 외부 등록(Redis) 대상에서 제외되었습니다. (최종 이름: {})", baseName, finalName); log.info(" [HeartbeatSender] '{}' 툴은 어노테이션 설정에 의해 외부 등록(Redis) 대상에서 제외되었습니다. (최종 이름: {})", baseName, finalName);
} }
ToolMetadata meta = new ToolMetadata(); ToolMetadata meta = new ToolMetadata();
meta.setToolName(finalName); meta.setToolName(finalName);
meta.setDescription(prop != null && prop.getDescription() != null ? prop.getDescription() : functionAnnotation.description()); meta.setDescription(functionAnnotation.description());
meta.setDomainGroup(toolAnnotation.group()); meta.setDomainGroup(toolAnnotation.group());
meta.setIntegrationType(toolAnnotation.routingType()); meta.setIntegrationType(toolAnnotation.routingType());
meta.setMciServiceId(prop != null && prop.getMappingId() != null ? prop.getMappingId() : functionAnnotation.mappingId()); meta.setMciServiceId(functionAnnotation.mappingId());
meta.setPodUrl(podUrl); meta.setPodUrl(podUrl);
boolean isVisible = prop != null && prop.getVisible() != null ? prop.getVisible() : functionAnnotation.visible(); boolean isVisible = functionAnnotation.visible();
meta.setVisible(isVisible); meta.setVisible(isVisible);
meta.setRegistered(isRegister); meta.setRegistered(isRegister);
Map<String, String> prompts = new HashMap<>(); Map<String, String> prompts = new HashMap<>();
String promptText = prop != null && prop.getPrompt() != null ? prop.getPrompt() : functionAnnotation.prompt(); String promptText = functionAnnotation.prompt();
prompts.put(finalName, promptText); prompts.put(finalName, promptText);
meta.setActionPrompts(prompts); meta.setActionPrompts(prompts);