3.6MCP 消息内容

SetMcpContent 是专门为 MCP(Model Context Protocol)2.0 协议设计的扩展方法,用于快速构建符合 JSON‑RPC 2.0 格式的请求,并自动附加必需的 MCP 请求头。它支持发送请求(需要响应)和通知(无需响应)两种消息类型。

SetMcpContent 是专门为 MCPModel Context Protocol)2.0 协议设计的扩展方法,用于快速构建符合 JSON‑RPC 2.0 格式的请求,并自动附加必需的 MCP 请求头。它支持发送请求(需要响应)和通知(无需响应)两种消息类型。

cs
HttpRequestBuilder.Post("https://mcp.example.com/mcp")    .SetMcpContent("MyClient", "tools/list");// 携带参数HttpRequestBuilder.Post("https://mcp.example.com/mcp")    .SetMcpContent("MyClient", "tools/list", new { name = "get_weather" });// 自定义 IDHttpRequestBuilder.Post("https://mcp.example.com/mcp")    .SetMcpContent("MyClient", new McpMessageData("tools/list")    {        Id = "custom-001"    });// 与 Server Sent Events 流式响应结合使用HttpRequestBuilder.ServerSentEvents("https://mcp.example.com/mcp")    .SetMcpContent("MyClient", "tools/call", new { name = "get_weather" });