Skip to content

Invalid MCP tool output schema when using Jackson @JsonProperty annotation #61

@amonties-mirakl

Description

@amonties-mirakl

Bug description
Jackson annotations on MCP tool return value are not taken into account for output schema generation.

Environment

  • Java version : 21
  • Spring MCP version : 1.1.0-M2

Steps to reproduce

  • Create a tool method annotated with @McpTool and generateOutputSchema to true.
  • Return an object or a record from this method with some @JsonProperty annotations to override default properties names
  • Start the server & call this tool
  • An error occurs due to structured content not matching the tool output schema.
    This is due to an invalid output schema ignoring Jackson properties names override : the schema property name do not match the serialized property name.

Expected behavior
The output schema generation should generate properties names the same way as the output is serialized.

Possible cause
This issue seams to be related to the fact that the SchemaGeneratorConfig used to generate the output schema does not have the Jackson module registered : https://github.com/spring-ai-community/mcp-annotations/blob/main/mcp-annotations/src/main/java/org/springaicommunity/mcp/method/tool/utils/JsonSchemaGenerator.java#L184

Minimal Complete Reproducible example

public record ToolResult(
        @JsonProperty("tool_result_value") String toolResultValue
) {}
@Service
public class ExampleTool {
    @McpTool(
            name = "example_tool",
            generateOutputSchema = true
    )
    public ToolResult exampleTool() {
        return new ToolResult("result");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions