Vane.Mcp 1.0.0-preview.2

This is a prerelease version of Vane.Mcp.
dotnet add package Vane.Mcp --version 1.0.0-preview.2
                    
NuGet\Install-Package Vane.Mcp -Version 1.0.0-preview.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Vane.Mcp" Version="1.0.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Vane.Mcp" Version="1.0.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="Vane.Mcp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Vane.Mcp --version 1.0.0-preview.2
                    
#r "nuget: Vane.Mcp, 1.0.0-preview.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Vane.Mcp@1.0.0-preview.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Vane.Mcp&version=1.0.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Vane.Mcp&version=1.0.0-preview.2&prerelease
                    
Install as a Cake Tool

Vane.Mcp

Model Context Protocol(MCP)服务端协议包。当前实现以 MCP 2025-11-25 legacy(initialize 握手) 为基线,覆盖 JSON-RPC 2.0、tools / resources / prompts、stdio 与 Vane WebSocket 传输。

它是独立包,只引用 Vane.NET,不把 MCP 协议塞进内核,也不依赖 ASP.NET Core。Streamable HTTP 传输不包含在本包内;需要时由 ASP.NET Core 侧承接,再复用 McpServer.HandleAsync。

安装

dotnet add package Vane.Mcp --version 1.0.0-preview.1

net10.0 / net11.0。

stdio:最小服务

using System.Text.Json;
using Vane.Mcp;

McpServer server = new McpServer("demo-server", "1.0.0-preview.1", "2025-11-25")
    .MapTool(
        "add",
        "Add two numbers",
        JsonDocument.Parse("""{"type":"object","properties":{"a":{"type":"number"},"b":{"type":"number"}}}""").RootElement.Clone(),
        (arguments, _) =>
        {
            double a = arguments.GetProperty("a").GetDouble();
            double b = arguments.GetProperty("b").GetDouble();
            return ValueTask.FromResult(McpToolResult.Text((a + b).ToString()));
        });

await McpStdio.RunConsoleAsync(server);

stdio 采用“一行一条 JSON-RPC”:空行忽略,通知不产生输出,非法 JSON 返回 Parse error 但不断流,EOF 正常退出。读取与请求执行解耦,长任务运行期间仍可接收 notifications/cancelled。流由调用方拥有,RunAsync 不关闭输入/输出。

握手与协议版本

Console.WriteLine(McpProtocol.Current);       // 2025-11-25
Console.WriteLine(string.Join(", ", McpProtocol.Supported)); // 2025-06-18, 2025-11-25

initialize 必须携带 protocolVersion、capabilities、clientInfo.name、clientInfo.version;服务端只接受 string/integer 请求 ID,且同一会话内不能重复使用。客户端请求不受支持的版本时,服务端会回应自己的基线版本。

notifications/initialized 只有在完成 initialize 后才生效;重复 initialize 返回 InvalidRequest。除 initialize / ping 外,其他请求在握手完成前返回 -32002 Server not initialized。

WebSocket:挂到 Vane Host

using Vane.Hosting;
using Vane.Mcp;
using Vane.Transports;

Host host = Host.CreateDefault();
host.UseMcpWebSocket(
    new WebSocketEndPoint("http://localhost:9000/mcp"),
    server);

await host.StartAsync(_ => default); // role 已接管连接;参数只是管线兜底

默认要求 WebSocket 子协议 mcp;传 subProtocol: null 可沿用端点已有配置。一条 binary 消息对应一条 JSON-RPC 消息,每个连接持有独立的 McpSessionState。入站帧按顶层 JSON 对象切分,一次读到多个对象时也能逐条处理;坏帧返回 Parse error 后连接继续可用。WebSocket 是 Vane 扩展传输,不是 MCP 标准传输。

资源与提示词

提示词的 arguments 是 PromptArgument 数组,不是 JSON Schema:

server
    .MapResource("mem://config", "Runtime config", "In-memory config", "application/json",
        _ => ValueTask.FromResult(new McpResourceContent("mem://config", "application/json", """{"mode":"demo"}""")))
    .MapPrompt("greet", "Greeting",
        new[] { new McpPromptArgument("name", "User name", Required: true) },
        (arguments, _) =>
        {
            string name = arguments.TryGetProperty("name", out JsonElement value)
                ? value.GetString() ?? "world" : "world";
            return ValueTask.FromResult(new McpPromptResult(
                "greeting",
                new[] { new McpPromptMessage("user", McpContent.FromText($"Hello, {name}")) }));
        });

prompts/get 会校验必填参数;resources/read 的资源不存在返回 -32002 Resource not found,资源/提示词 handler 抛异常统一映射为 -32603 Internal error,不把异常抛到传输层。

内容块

McpContent 覆盖 text、image、audio、resource、resource_link 五种标准类型:

McpToolResult result = new(new[]
{
    McpContent.FromText("done"),
    McpContent.FromImage("base64...", "image/png"),
    McpContent.FromResource(new McpResourceContent("mem://config", "application/json", """{"mode":"demo"}""")),
    McpContent.FromResourceLink("mem://config", "Runtime config", description: "Runtime config", mimeType: "application/json"),
});

McpToolResult 支持 structuredContent、_meta;McpTool 支持 title、outputSchema、annotations、_meta;McpResource / McpPrompt 支持 title、size / annotations 等可选字段。

分页与取消

tools/list、resources/list、prompts/list 支持 cursor / nextCursor,默认每页 50 项,按名称/URI 稳定排序。notifications/cancelled 会取消同会话中正在执行的 tools/call,工具收到取消令牌后应尽快返回。

协议要点

  • 协议版本基线 2025-11-25,支持 2025-06-18;这两个版本都不再使用 JSON-RPC batch,收到数组直接返回 InvalidRequest。
  • 请求 ID 只接受 string 或 integer,null、小数、布尔、对象、数组一律 InvalidRequest。
  • initialize 的 capabilities 只声明真实具备的能力:tools / resources / prompts;不再虚报 logging。
  • logging/setLevel 未实现,调用返回 MethodNotFound;需要日志请由宿主自己的日志管线处理。
  • tools/call 的工具内部异常不泄露堆栈:返回 JSON-RPC 成功信封 + isError: true;未知工具 / 非法参数走 -32602。
  • 注册表在首次处理请求时冻结;之后 MapTool / MapResource / MapPrompt 抛 InvalidOperationException,避免运行期半生效配置。
  • 工具 handler 可能被并发调用;有共享状态时由业务自己同步。

边界

  • 不内置鉴权、TLS、Origin 校验;这些属于宿主/部署层。
  • 不提供 Streamable HTTP 传输;需要时由 ASP.NET Core 侧承接,再复用 McpServer.HandleAsync。
  • 不提供 resource templates、resource subscribe、progress notifications;当前也没有声明这些能力。
  • 不实现 2026-07-28 的 modern per-request _meta 模型;本包是 legacy 服务端,modern 客户端请走 dual-era 适配。
  • 不把 MCP 的 McpServer 暴露成 Vane 内核 API;内核保持零 MCP 依赖。
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.2 67 11/21/2026
1.0.0-preview.1 65 11/19/2026

1.0.0-preview.2 预发布:仅支持 net10.0/net11.0;本版修复帧定界、管道、会话与传输层边界缺陷,公开 API 无变更;完整发布说明见包内 RELEASE_NOTES.md。