Skip to content

refactor: fix the return format of CallToolResult#68

Open
TheEterna wants to merge 4 commits intospring-ai-community:0.5.xfrom
TheEterna:refactor/issue-67-Update-the-AbstractMcpToolMethodCallback.convertValueToCallToolResult
Open

refactor: fix the return format of CallToolResult#68
TheEterna wants to merge 4 commits intospring-ai-community:0.5.xfrom
TheEterna:refactor/issue-67-Update-the-AbstractMcpToolMethodCallback.convertValueToCallToolResult

Conversation

@TheEterna
Copy link
Copy Markdown
Contributor

  • corrected the return format for structured content results, following the MCP protocol.
  • fix variable name

- corrected the return format for structured content results, following the MCP protocol.
- fix variable name
@TheEterna TheEterna force-pushed the refactor/issue-67-Update-the-AbstractMcpToolMethodCallback.convertValueToCallToolResult branch from 2ab3ee2 to 5dbad11 Compare October 4, 2025 15:35
import io.modelcontextprotocol.spec.McpSchema.CallToolRequest;
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
import io.modelcontextprotocol.spec.McpSchema.*;
import io.modelcontextprotocol.spec.McpSchema.CallToolResult.*;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid wildcards

if (this.returnMode == ReturnMode.STRUCTURED) {
String jsonOutput = JsonParser.toJson(result);
Object structuredOutput = JsonParser.fromJson(jsonOutput, Object.class);
callToolResultBuilder.structuredContent(structuredOutput);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structured content is available only to JSON so you can do that :

return CallToolResult.builder().structuredContent(structuredOutput).addTextContent(jsonOutput).build();

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants