spring-projects / spring-projects/spring-ai

Support JsonFormat when using generateOutputSchema

Open
#4,692 2 comments 0 reactions 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 & Expected Behavior

Enable generateOutputSchema to detect and use @JsonFormat.

Without this support, the MCP server is giving the MCP Inspector an error (confirmed gemini cli also breaks so it may be breaking all clients):

Validation failed: structuredContent does not match tool outputSchema. Validation errors: [$.total: string found, number expected]

Steps to reproduce

  1. Define a return response object that contains a BigDecimal that uses the JsonFormat. Example Below.

Minimal Complete Reproducible example

@Data
public class BalancePayload {

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Schema(accessMode = AccessMode.READ_ONLY, requiredMode = RequiredMode.REQUIRED, description = "The total amount of the balance.", example = "100")
    private BigDecimal total;

}

@GetMapping(...)
@Operation(...)
@McpTool(generateOutputSchema = true)
public BalancePayload getBalance(...) {
    return new BalancePayload().setTotal(BigDecimal.ONE);
}

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 the generateOutputSchema handling and the JsonFormat annotation shown in the reproducible example. Reproduce the BigDecimal case with @JsonFormat(shape = JsonFormat.Shape.STRING), then inspect the generated output schema and verify that it represents total as a string so MCP Inspector validation succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend-api-design
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.