Solon v3.5.0

v3.5.0 solon-ai-mcp 更新与兼容说明

</> markdown

1、更新说明

  • 新增 solon-ai-mcp MCP_2025-03-26 版本协议支持
  • 调整 solon-ai-mcp channel 取消默认值(之前为 sse),且为必填(为兼容过度,有明确的开发时、启动时提醒)
    • 如果默认值仍为 sse ,升级后可能忘了修改了升级
    • 如果默认值改为 streamable,升级后会造成不兼容
public interface McpChannel {
    String STDIO = "stdio";
    String SSE = "sse";               //MCP官方已标为弃用
    String STREAMABLE = "streamable"; //新增(MCP_2025-03-26 版本新增)
}

2、兼容说明

  • channel 取消默认值(之前为 sse),且为必填

提醒:SSE 与 STREAMABLE 不能互通(升级时,要注意这点)

3、应用示例

for server (如果 channel 不加,默认为 streamable。之前默认为 sse)

@McpServerEndpoint(channel=McpChannel.STREAMABLE, mcpEndpoint = "/mcp") 
public class McpServerTool {
    @ToolMapping(description = "查询天气预报")
    public String getWeather(@Param(description = "城市位置") String location) {
        return "晴,14度";
    }
}

client (如果 channel 不加,默认为 streamable。之前默认为 sse)

McpClientProvider mcpClient = McpClientProvider.builder()
            .channel(McpChannel.STREAMABLE)
            .apiUrl("http://localhost:8081/mcp")
            .build();

//测试
String resp = mcpClient.callToolAsText("getWeather", Utils.asMap("location", "杭州")).getContent();
System.out.println(resp);


//对接 LLM
ChatModel chatModel = ChatModel.of(apiUrl).provider(...).model(...)
                .defaultToolsAdd(mcpClient) //绑定 mcp 工具
                .build();

ChatResponse resp = chatModel
        .prompt("今天杭州的天气情况?")
        .call();