Spring AI 1.1
I have:
record UserRandomNumber(int number) { }
@McpTool(description = "generate a random number")
public int random(McpSyncRequestContext context) {
Random rand = new Random();
Integer maybeNumber = null;
if (rand.nextBoolean() && context.elicitEnabled()) {
var elicitResult = context.elicit(UserRandomNumber.class);
if (elicitResult.action() == McpSchema.ElicitResult.Action.ACCEPT) {
maybeNumber = elicitResult.structuredContent().number();
}
}
return maybeNumber != null ? maybeNumber : rand.nextInt(100);
}
In MCP Inspector when I provide the elicited value I get:
Validation Error: unknown format "int32" is used in schema at path "#/properties/number"
Comment From: tzolov
This is MCP Elicitation spec limitations. It sports only a subsets of the JSON Schema types: https://modelcontextprotocol.io/specification/2025-11-25/client/elicitation#requested-schema
@jamesward
In this case you need to use Java Number instead of int. e.t. record UserRandomNumber(Number number) { }
Comment From: jamesward
Thanks! Would there be any way to validate at compile time (or less ideally runtime) that the object isn't compatible?