spring-projects / spring-projects/spring-ai

In the output parameters of the tool, properties annotated with @McpToolParam cannot be null

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

For tools annotated with @McpTool, if the output is a custom class, then any properties within that class annotated with @McpToolParam must not be null, otherwise errors will occur:Validation failed: structuredContent does not match tool outputSchema. Validation errors: [$.current: 已找到 null,必须是 object]

How can I return a null value? Thank you.

Environment
mcp-annotations: 0.6.0
spring-ai: 1.1.0-M4
protocol: stateless

Minimal Complete Reproducible example

@Service
public class TestService {
    @McpTool
    public TestResponse test() {
        return new TestResponse();
    }

    public static class TestResponse {
        @McpToolParam(description = "test", required = false)
        private String text;

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }
    }
}

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 @McpTool and @McpToolParam processing shown by the TestService and TestResponse reproduction, then reproduce the structuredContent validation error with the optional text property left null. Done means a custom tool output with an @McpToolParam(required = false) null property is accepted without the reported schema-validation failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.