Using org.springframework.ai.tool.annotation.Tool with return of io.modelcontextprotocol.spec.McpSchema.CallToolResult does not work for io.modelcontextprotocol.spec.McpSchema.EmbeddedResource;
Limitation is probably inside org.springframework.ai.mcp.McpToolUtils, which only provides ImageContent and TextContent but not io.modelcontextprotocol.spec.McpSchema.EmbeddedResource;
return new SharedSyncToolSpecification(tool, (exchangeOrContext, request) -> {
try {
String callResult = toolCallback.call(ModelOptionsUtils.toJsonString(request.arguments()),
new ToolContext(Map.of(TOOL_CONTEXT_MCP_EXCHANGE_KEY, exchangeOrContext)));
if (mimeType != null && mimeType.toString().startsWith("image")) {
return new McpSchema.CallToolResult(List
.of(new McpSchema.ImageContent(List.of(Role.ASSISTANT), null, callResult, mimeType.toString())),
false);
}
return new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(callResult)), false);
}
catch (Exception e) {
return new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(e.getMessage())), true);
}
});