Currently when using Elicitation the schema needs to be manually created:
@McpTool(description = "generate a random number")
fun random(exchange: McpSyncServerExchange): Int {
// sometimes additional data is needed
val maybeNumber = if (Random.nextBoolean()) {
val schema = mapOf("type" to "object", "properties" to mapOf("number" to mapOf("type" to "integer")), "required" to listOf("number"))
val userInput = exchange.createElicitation(McpSchema.ElicitRequest("what is your favorite number?", schema))
(userInput.content["number"] as? String)?.toIntOrNull().takeIf { userInput.action == McpSchema.ElicitResult.Action.ACCEPT }
} else null
return maybeNumber ?: Random.nextInt(100)
}
It'd be nice if McpSchema.ElicitRequest
supported passing a class that'd enable generating the schema automatically.
Note that the MCP Spec seems to constrain the schema of Elicitation to an object (no list or primitives).