mcp - 支持的三种传输方式
MCP 的通讯目前有三种传输方式(或通道):
传输方式(或通道) | 说明 | 备注 |
---|---|---|
stdio | 本地进程内通讯(一般,通过子进程启动) | 现有 |
http sse | 远程 http sse 通讯 | 现有 |
http streamable | 远程 http streamable 通讯 | v3.5.0 后支持 |
业内已有大量的 stdio mcp 服务发布。其中 http 的服务,可支持多个端点。
public interface McpChannel {
String STDIO = "stdio";
String SSE = "sse"; //MCP官方已标为弃用
String STREAMABLE = "streamable"; //新增(MCP_2025-03-26 版本新增)
}
传输方式(或通道)使用提醒:
- 服务端与客户端,须使用相同的传输方式才可通讯
传输方式(或通道)的配置示例:
//服务端
@McpServerEndpoint(channel = McpChannel.STREAMABLE, mcpEndpoint = "/mcp")
public class McpServerTool {
@ToolMapping(description = "查询天气预报")
public String getWeather(@Param(description = "城市位置") String location) {
return "晴,14度";
}
}
//客户端
McpClientProvider clientProvider = McpClientProvider.builder()
.channel(McpChannel.STREAMABLE)
.apiUrl("http://localhost:8080/mcp")
.build();