spring-projects / spring-projects/spring-ai

Use @Schema when possible

Open
#4,693 0 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

Impact

The LLM thinks the readonly fields are writable, so it wastes tokens trying to figure out default values to pass in.

Bug description & Expected Behavior

I'm using MCP Inspector to view the MCP schema and make calls. The generated input schema from the server is incorrectly mapping the detected @Schema fields. It's rendering "readOnly:true" fields as inputs. Then in the MCP Inspector, it's rendering these as HTML input fields that are not "read only".

The @Schema annotation when using accessMode = AccessMode.READ_ONLY is intended to hint to OpenAPI that these are fields given in the output. Please see the provided example of how the payload is an input and output, and that the accessMode controls the visibility on both sides.

I'm creating this as a Bug an not a Feature Request since @Schema is supported by Spring AI. The annotations are being read for other fields such as `@Schema(description, defaultValue) and both are being populated into the HTML form inputs in MCP Inspector.

Minimal Complete Reproducible example

@PostMapping(...)
@Operation(...)
@McpTool(...)
public ExamplePayload createExample(@RequestBody final ExamplePayload examplePayload) {
    ...
}

@Data
public class ExamplePayload {

    @Schema(accessMode = AccessMode.READ_ONLY, requiredMode = RequiredMode.REQUIRED, description = "An rfc 3339 formatted date: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    private ZonedDateTime created; <------ this is an **output** only field

    @Schema(description = "The chosen locale of the user.", defaultValue = "EN_US", example = "EN_US")
    private Locale locale; <------ this is an **input** and **output** field

    @Schema(accessMode = AccessMode.WRITE_ONLY, ...)
    private String other; <------ this is an **input** only field

}

Please also check if @Schema(requiredMode = RequiredMode...) is handled correctly or not.

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 by tracing Spring AI's generated MCP schema handling for the @Schema annotations in the provided ExamplePayload, using the MCP Inspector reproduction. Verify read-only, write-only, and requiredMode behavior for input and output schemas; done means the generated schema and Inspector fields respect those access and required settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.