feat: organize tool schemas by category
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 1m58s

This commit is contained in:
jade
2026-08-04 14:42:08 +09:00
parent 4393071212
commit 08ccc043da
7 changed files with 22 additions and 6 deletions

View File

@@ -31,6 +31,6 @@ public @interface McpValidation {
int maxLength() default -1;
String[] allowedValues() default {};
String format() default "";
String defaultValue() default "";
boolean nullable() default false; String defaultValue() default "";
String[] examples() default {};
}

View File

@@ -103,6 +103,14 @@ public class JsonSchemaGenerator {
if (validation != null && validation.examples().length > 0) {
fieldSchema.put("examples", List.of(validation.examples()));
}
if (validation != null && validation.nullable()) {
Map<String, Object> nonNullSchema = new HashMap<>(fieldSchema);
fieldSchema = new HashMap<>();
fieldSchema.put("anyOf", List.of(
nonNullSchema,
Map.of("type", "null")
));
}
properties.put(field.getName(), fieldSchema);
}

View File

@@ -43,11 +43,11 @@ public class ClaimSearchResponse {
private String statusLabel;
@McpParameter(description = "Approved amount. Null before review; do not interpret null as zero.")
@McpValidation(minimum = 0)
@McpValidation(minimum = 0, nullable = true)
private Long approvedAmount;
@McpParameter(description = "Present only when status is REJECTED; otherwise null.")
@McpValidation(maxLength = 200)
@McpValidation(maxLength = 200, nullable = true)
private String rejectionReason;
@McpParameter(description = "Claim summaries, ordered by received date descending.")
@@ -82,7 +82,7 @@ public class ClaimSearchResponse {
private String receivedDate;
@McpParameter(description = "Approved amount. Null before review; do not interpret null as zero.")
@McpValidation(minimum = 0)
@McpValidation(minimum = 0, nullable = true)
private Long approvedAmount;
}
}

View File

@@ -17,8 +17,8 @@ public interface ClaimSearchSchemaSampleUseCase {
name = "sample.claim.search.resource",
description = "Claim search Tool sample using input and output JSON Schema resources.",
prompt = "Search an insurance claim by claim number or contract number.",
inputSchemaResource = "classpath:tool-schemas/claim-search-resource-input-schema.json",
inputSchemaResource = "classpath:tool-schemas/cmm/claim-search-resource-input-schema.json",
outputSchemaResource = "classpath:tool-schemas/cmm/claim-search-resource-output-schema.json",
readOnlyHint = true,
idempotentHint = true
)

View File

@@ -69,6 +69,14 @@ class ClaimSearchRequestSchemaTest {
assertTrue(validator.validateValue(schema, response).isEmpty());
}
@Test
void sampleResponseConformsToAutomaticallyGeneratedOutputSchema() throws Exception {
Map<String, Object> schema = JsonSchemaGenerator.generateSchema(ClaimSearchResponse.class);
ClaimSearchResponse response = new ClaimSearchSchemaSampleUseCaseImpl().search(new ClaimSearchRequest());
ToolArgumentSchemaValidator validator = new ToolArgumentSchemaValidator(new ObjectMapper());
assertTrue(validator.validateValue(schema, response).isEmpty());
}
@SuppressWarnings("unchecked")
private Map<String, Map<String, Object>> properties(Map<String, Object> schema) {
return (Map<String, Map<String, Object>>) schema.get("properties");