fix: include pattern in mcp tool schema generation and scaffold output
All checks were successful
Deploy Tools / deploy (push) Successful in 2m20s

This commit is contained in:
jade
2026-08-19 10:31:46 +09:00
parent 6646741665
commit 317f9865b8
3 changed files with 17 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.validation.constraints.Pattern;
/**
@@ -71,6 +72,11 @@ public class JsonSchemaGenerator {
requiredList.add(field.getName());
}
Pattern patternAnnotation = field.getAnnotation(Pattern.class);
if (patternAnnotation != null && !patternAnnotation.regexp().isEmpty()) {
fieldSchema.put("pattern", patternAnnotation.regexp());
}
Schema schemaAnnotation = field.getAnnotation(Schema.class);
if (schemaAnnotation != null) {
if (!schemaAnnotation.description().isEmpty() && !fieldSchema.containsKey("description")) {

View File

@@ -1442,6 +1442,9 @@ public class ToolScaffolder {
properties.append(" ").append(field.name().trim()).append(":\n")
.append(" type: ").append(jsonSchemaType(field.type())).append("\n")
.append(" description: ").append(yamlText(richDescription(field))).append("\n");
if (field.pattern() != null && !field.pattern().isBlank()) {
properties.append(" pattern: ").append(yamlText(field.pattern())).append("\n");
}
if ("Enum".equals(field.type()) && field.enumValues() != null && !field.enumValues().isEmpty()) {
properties.append(" enum: [").append(field.enumValues().stream()
.filter(value -> value != null && !value.isBlank()).map(String::trim)
@@ -1456,6 +1459,9 @@ public class ToolScaffolder {
properties.append(" ").append(itemField.name()).append(":\n")
.append(" type: ").append(jsonSchemaType(itemField.type())).append("\n")
.append(" description: ").append(yamlText(richDescription(itemField))).append("\n");
if (itemField.pattern() != null && !itemField.pattern().isBlank()) {
properties.append(" pattern: ").append(yamlText(itemField.pattern())).append("\n");
}
}
}
}