forked from kimhyungsik/ax_hub_mcp_tool
feat: add tool service manifest and scaffold generation
Some checks failed
Deploy Tools / deploy (push) Has been cancelled
Some checks failed
Deploy Tools / deploy (push) Has been cancelled
This commit is contained in:
@@ -5,6 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.dat.lib.config
|
||||
@@ -32,6 +33,24 @@ public class McpProperties {
|
||||
public static class Manifest {
|
||||
private String bundleId;
|
||||
private String namePrefix;
|
||||
private List<RoutingFunction> routingFunctions = List.of();
|
||||
}
|
||||
|
||||
}
|
||||
@Data
|
||||
public static class RoutingFunction {
|
||||
private String name;
|
||||
private String description;
|
||||
private String serverId;
|
||||
private String categoryKey;
|
||||
private String productBoundary;
|
||||
private String businessDomain;
|
||||
private String businessOutcome;
|
||||
private List<String> primaryEntities = List.of();
|
||||
private List<String> capabilities = List.of();
|
||||
private String selectIf;
|
||||
private String rejectIf;
|
||||
private List<String> confidenceServerIds = List.of();
|
||||
private String decisionPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,6 +62,20 @@ public class ToolManifestService {
|
||||
return new ToolManifestResponse(bundleId, revision(bundleId, tools), tools);
|
||||
}
|
||||
|
||||
public ToolServiceManifestResponse currentToolServiceManifest() {
|
||||
McpProperties.Manifest manifest = properties.getManifest();
|
||||
String bundleId = manifest == null ? null : manifest.getBundleId();
|
||||
List<McpProperties.RoutingFunction> routingFunctions = manifest == null
|
||||
? List.of() : defaultRoutingList(manifest.getRoutingFunctions());
|
||||
try {
|
||||
String source = objectMapper.writeValueAsString(Map.of("bundleId", bundleId,
|
||||
"routingFunctions", routingFunctions));
|
||||
return new ToolServiceManifestResponse(bundleId, sha256(source), routingFunctions);
|
||||
} catch (Exception exception) {
|
||||
throw new IllegalStateException("Failed to build Tool Service manifest", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMatchCategory(String requestedCategory, String toolCategory, String bundleId) {
|
||||
if (requestedCategory == null) {
|
||||
return true;
|
||||
@@ -168,4 +182,15 @@ public class ToolManifestService {
|
||||
private List<String> defaultList(List<String> value) {
|
||||
return value == null ? List.of() : List.copyOf(value);
|
||||
}
|
||||
|
||||
private List<McpProperties.RoutingFunction> defaultRoutingList(List<McpProperties.RoutingFunction> value) {
|
||||
return value == null ? List.of() : List.copyOf(value);
|
||||
}
|
||||
|
||||
private String sha256(String value) throws Exception {
|
||||
byte[] digest = MessageDigest.getInstance("SHA-256").digest(value.getBytes(StandardCharsets.UTF_8));
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (byte item : digest) result.append(String.format("%02x", item));
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.shinhanlife.dat.lib.manifest;
|
||||
|
||||
import io.shinhanlife.dat.lib.config.McpProperties;
|
||||
import java.util.List;
|
||||
|
||||
/** Server-level routing metadata loaded from tool-service-manifest.yml. */
|
||||
public record ToolServiceManifestResponse(String bundleId, String revision,
|
||||
List<McpProperties.RoutingFunction> routingFunctions) {
|
||||
}
|
||||
@@ -44,11 +44,24 @@ public class PodScaffolder {
|
||||
envSourceDir = System.getenv("AXHUB_SOURCE_DIR");
|
||||
}
|
||||
Path rootDir = envSourceDir != null ? Paths.get(envSourceDir) : Paths.get(".");
|
||||
return scaffoldPod(rootDir, moduleName, portStr, shortName, author, createDate);
|
||||
return scaffoldPod(rootDir, moduleName, portStr, shortName, author, createDate, null);
|
||||
}
|
||||
|
||||
public static String scaffoldPod(String moduleName, String portStr, String shortName, String author,
|
||||
String createDate, String toolServiceManifest) throws IOException {
|
||||
String envSourceDir = System.getProperty("AXHUB_SOURCE_DIR");
|
||||
if (envSourceDir == null || envSourceDir.isBlank()) envSourceDir = System.getenv("AXHUB_SOURCE_DIR");
|
||||
Path rootDir = envSourceDir != null ? Paths.get(envSourceDir) : Paths.get(".");
|
||||
return scaffoldPod(rootDir, moduleName, portStr, shortName, author, createDate, toolServiceManifest);
|
||||
}
|
||||
|
||||
static String scaffoldPod(Path rootDir, String moduleName, String portStr, String shortName,
|
||||
String author, String createDate) throws IOException {
|
||||
return scaffoldPod(rootDir, moduleName, portStr, shortName, author, createDate, null);
|
||||
}
|
||||
|
||||
static String scaffoldPod(Path rootDir, String moduleName, String portStr, String shortName,
|
||||
String author, String createDate, String toolServiceManifest) throws IOException {
|
||||
Path modulePath = rootDir.resolve(Paths.get(moduleName));
|
||||
if (Files.exists(modulePath)) {
|
||||
return "[오류] 이미 존재하는 모듈입니다: " + moduleName;
|
||||
@@ -129,6 +142,8 @@ public class PodScaffolder {
|
||||
spring:
|
||||
application:
|
||||
name: %s
|
||||
config:
|
||||
import: optional:classpath:tool-service-manifest.yml
|
||||
profiles:
|
||||
active: local
|
||||
logging:
|
||||
@@ -146,6 +161,10 @@ public class PodScaffolder {
|
||||
""".formatted(portStr, moduleName, moduleName.replace("dap-", ""));
|
||||
writeUtf8(resPath.resolve("application.yml"), applicationYml);
|
||||
|
||||
String manifest = toolServiceManifest == null || toolServiceManifest.isBlank()
|
||||
? defaultToolServiceManifest(moduleName) : toolServiceManifest.trim() + System.lineSeparator();
|
||||
writeUtf8(resPath.resolve("tool-service-manifest.yml"), manifest);
|
||||
|
||||
String applicationLocalYml = """
|
||||
# Local 환경 전용 설정 (H2 메모리 DB 등)
|
||||
spring:
|
||||
@@ -363,6 +382,28 @@ public class PodScaffolder {
|
||||
Files.writeString(path, content, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static String defaultToolServiceManifest(String moduleName) {
|
||||
String key = moduleName.replace("dat-was-", "");
|
||||
return """
|
||||
mcp:
|
||||
manifest:
|
||||
routing-functions:
|
||||
- name: route_to_%s
|
||||
description: %s 업무 서버로 요청을 라우팅합니다.
|
||||
server-id: %s
|
||||
category-key: %s
|
||||
product-boundary: insurance
|
||||
business-domain: %s 업무
|
||||
business-outcome: %s 관련 업무를 처리합니다.
|
||||
primary-entities: []
|
||||
capabilities: []
|
||||
select-if: %s 관련 요청인 경우
|
||||
reject-if: 다른 업무 영역이 주된 요청인 경우
|
||||
confidence-server-ids: [%s]
|
||||
decision-policy: 요청의 주요 업무 영역을 기준으로 서버를 선택합니다.
|
||||
""".formatted(moduleName.replace("-", "_"), key, moduleName, key, key, key, key, moduleName);
|
||||
}
|
||||
|
||||
private static String capitalize(String str) {
|
||||
if (str == null || str.isEmpty()) return str;
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.shinhanlife.dat.mcc.presentation;
|
||||
|
||||
import io.shinhanlife.dat.lib.manifest.ToolManifestResponse;
|
||||
import io.shinhanlife.dat.lib.manifest.ToolManifestService;
|
||||
import io.shinhanlife.dat.lib.manifest.ToolServiceManifestResponse;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -33,6 +34,11 @@ public class ToolManifestController {
|
||||
return handleManifest(toolManifestService.currentManifest(categoryKey), ifNoneMatch);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/tool-service-manifest", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<ToolServiceManifestResponse> getToolServiceManifest() {
|
||||
return ResponseEntity.ok(toolManifestService.currentToolServiceManifest());
|
||||
}
|
||||
|
||||
private ResponseEntity<ToolManifestResponse> handleManifest(ToolManifestResponse manifest, String ifNoneMatch) {
|
||||
String eTag = '"' + manifest.revision() + '"';
|
||||
if (eTag.equals(ifNoneMatch)) {
|
||||
@@ -40,4 +46,4 @@ public class ToolManifestController {
|
||||
}
|
||||
return ResponseEntity.ok().eTag(eTag).body(manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user