spring-projects / spring-projects/spring-ai

@McpTool output schema generation ignores Jackson annotations

Open
#4,487 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

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
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with JsonSchemaGenerator.internalGenerateFromClass and compare its configuration with TYPE_SCHEMA_GENERATOR, including how the Jackson module is applied for input schemas. Reproduce the Kotlin example with a @McpTool return type using @JsonPropertyDescription, then verify that the outputSchema includes the annotation description.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.