fix: restore tool category metadata

This commit is contained in:
jade
2026-08-06 01:01:05 +09:00
parent a88122bd09
commit e92a0b7699
22 changed files with 30 additions and 30 deletions

View File

@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
public @interface ToolHint {
boolean register() default false;
boolean requiresApproval() default false;
String group() default "";
String categoryKey() default "com";
String mappingId() default "";
String inputSchemaResource() default "";
String outputSchemaResource() default "";

View File

@@ -107,8 +107,8 @@ public class ToolRegistryHeartbeatSender {
meta.setTimeoutMillis(5000L);
meta.setEnabled(true);
meta.setDescription(functionAnnotation.description());
meta.setCategoryKey(hintAnnotation == null || hintAnnotation.group().isBlank()
? "default" : hintAnnotation.group());
meta.setCategoryKey(hintAnnotation == null || hintAnnotation.categoryKey().isBlank()
? "common" : hintAnnotation.categoryKey());
meta.setIntegrationType("REST");
meta.setMciServiceId(hintAnnotation != null ? hintAnnotation.mappingId() : "");
meta.setPodUrl(podUrl);

View File

@@ -12,15 +12,15 @@ public final class ToolSourceUpdater {
private ToolSourceUpdater() {
}
public static void updateToolSource(String toolName, String domainGroup, String description,
public static void updateToolSource(String toolName, String categoryKey, String description,
boolean register, Boolean requiresApproval) throws IOException {
String configuredSourceDirectory = System.getenv("AXHUB_SOURCE_DIR");
Path rootDirectory = configuredSourceDirectory == null || configuredSourceDirectory.isBlank()
? Paths.get(".") : Paths.get(configuredSourceDirectory);
updateToolSource(rootDirectory, toolName, domainGroup, description, register, requiresApproval);
updateToolSource(rootDirectory, toolName, categoryKey, description, register, requiresApproval);
}
static void updateToolSource(Path rootDirectory, String toolName, String domainGroup, String description,
static void updateToolSource(Path rootDirectory, String toolName, String categoryKey, String description,
boolean register, Boolean requiresApproval) throws IOException {
Path targetFile = findToolSource(rootDirectory, toolName);
if (targetFile == null) {
@@ -29,7 +29,7 @@ public final class ToolSourceUpdater {
String content = Files.readString(targetFile);
content = updateMcpTool(content, toolName, description);
content = updateToolHint(content, domainGroup, register, requiresApproval);
content = updateToolHint(content, categoryKey, register, requiresApproval);
Files.writeString(targetFile, content);
}
@@ -61,7 +61,7 @@ public final class ToolSourceUpdater {
return description == null ? content : replaceAttribute(content, range, "description", quote(description));
}
private static String updateToolHint(String content, String domainGroup, boolean register, Boolean requiresApproval) {
private static String updateToolHint(String content, String categoryKey, boolean register, Boolean requiresApproval) {
AnnotationRange range = annotationArguments(content, "ToolHint", null);
if (range == null) {
throw new IllegalArgumentException("ToolHint declaration not found next to McpTool");
@@ -72,8 +72,8 @@ public final class ToolSourceUpdater {
updated = replaceAttribute(updated, range, "requiresApproval", Boolean.toString(requiresApproval));
range = annotationArguments(updated, "ToolHint", null);
}
if (domainGroup != null && !domainGroup.isBlank()) {
updated = replaceAttribute(updated, range, "group", quote(domainGroup));
if (categoryKey != null && !categoryKey.isBlank()) {
updated = replaceAttribute(updated, range, "categoryKey", quote(categoryKey));
}
return updated;
}

View File

@@ -32,6 +32,6 @@ class ToolSourceUpdaterTest {
String updated = Files.readString(source);
assertTrue(updated.contains("@McpTool(name = \"oth.cmm.sample.search\", description = \"new\")"));
assertTrue(updated.contains("@ToolHint(register = true, requiresApproval = true"));
assertTrue(updated.contains("group = \"customer\""), updated);
assertTrue(updated.contains("categoryKey = \"customer\""), updated);
}
}