Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Feat: add McpToolBody which Annotates tool method parameter which is a business object#93

Open
24kpure wants to merge 1 commit intospring-ai-community:mainfrom
24kpure:feature_add_mcpToolBody
Open

Feat: add McpToolBody which Annotates tool method parameter which is a business object#93
24kpure wants to merge 1 commit intospring-ai-community:mainfrom
24kpure:feature_add_mcpToolBody

Conversation

@24kpure
Copy link
Copy Markdown

@24kpure 24kpure commented Dec 10, 2025

design

During the development of MCP tools, when a method requires multiple parameters, using the @McpToolParam annotation may reduce code readability. To address this, inspired by the @RequestBody(org.springframework.web.bind.annotation.RequestBody) annotation in the Spring framework, I have added the @McpToolBody annotation. This allows parameters to be passed as a structured business object, thereby improving code clarity and maintainability.

example

    // use  @McpToolParam
    @McpTool(name = "calculate-area", 
             description = "Calculate the area of a rectangle")
    public AreaResult calculateRectangleArea(
            @McpToolParam(description = "Width of the rectangle", required = true) double width,
            @McpToolParam(description = "Height of the rectangle", required = true) double height) {
        double area = width * height;
        return new AreaResult(area, "square units");
    }

   // use  @McpToolBody
   @McpTool(name = "calculate-area", 
             description = "Calculate the area of a rectangle")
    public AreaResult calculateRectangleArea(
            @McpToolBody CalculateAreaRequest toolBody) {
        double area = request.getWidth() * request.getHeight();
        return new AreaResult(area, "square units");
    }

    public static class CalculateAreaRequest {
        @McpToolParam(description = "Width of the rectangle", required = true)
        private double width;
        @McpToolParam(description = "Height of the rectangle", required = true) 
        private double height;

        public double getWidth() {
            return width;
        }

        public void setWidth(double width) {
            this.width = width;
        }

        public double getHeight() {
            return height;
        }

        public void setHeight(double height) {
            this.height = height;
        }
    }

changelist

  • add file McpToolBody
  • correct the syntax errors in the comments of file `McpProgress
  • correct the syntax errors in the comments of file `McpPrompt
  • add McpToolBody input support in org.springaicommunity.mcp.method.tool.utils.JsonSchemaGenerator#internalGenerateFromMethodArguments
  • Add McpToolBody parameter conversion support in org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback#buildMethodArguments
  • add McpToolBody example in readme

@24kpure
Copy link
Copy Markdown
Author

24kpure commented Dec 25, 2025

@tzolov CC,please

@24kpure
Copy link
Copy Markdown
Author

24kpure commented Jan 5, 2026

@tzolov happy new year!

@24kpure
Copy link
Copy Markdown
Author

24kpure commented Mar 5, 2026

@tzolov CC,please

@24kpure
Copy link
Copy Markdown
Author

24kpure commented Apr 10, 2026

@tzolov
maybe you need more member help you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant