Skip to content

Elicitation Schema Improvements #4471

@jamesward

Description

@jamesward

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).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions