Bug description
While input schema generation includes Jackson annotations like @JsonPropertyDescription
, output schema generation does not. The root cause of this is JsonSchemaGenerator.internalGenerateFromClass
creating its schema generator config from scratch instead of using TYPE_SCHEMA_GENERATOR
or at least including the Jackson module manually.
Environment Spring AI 1.1.0-M2, reactive mode, Java 24.
Steps to reproduce
Use a @McpTool
method with a return type that uses Jackson description annotations.
Expected behavior The Jackson annotations are included in the schema generation.
Minimal Complete Reproducible example
@SpringBootApplication
class Application {
companion object {
@JvmStatic
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
}
data class Input(@JsonPropertyDescription("Test Input") val value: String)
data class Output(@JsonPropertyDescription("Test Output") val value: String)
@McpTool
fun test(@McpToolParam(description = "input") input: Input): Output {
return Output(input.value)
}
}
Tool listing response:
{
"name": "test",
"title": "test",
"description": "",
"inputSchema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"value": {
"type": "string",
"description": "Test Input"
}
},
"required": [
"value"
],
"description": "input"
}
},
"required": [
"input"
]
},
"outputSchema": {
"type": "object",
"properties": {
"value": {
"type": "string"
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
},
"annotations": {
"title": "",
"readOnlyHint": false,
"destructiveHint": true,
"idempotentHint": false,
"openWorldHint": true
}
}
Comment From: rnett
This is even worse than I thought, since optionality and nullability come from Jackson. A nullable type in your output schema will cause validation errors on the response, since the nullability isn't recorded in the schema.