McpFramework 1.1.0
dotnet add package McpFramework --version 1.1.0
NuGet\Install-Package McpFramework -Version 1.1.0
<PackageReference Include="McpFramework" Version="1.1.0" />
<PackageVersion Include="McpFramework" Version="1.1.0" />
<PackageReference Include="McpFramework" />
paket add McpFramework --version 1.1.0
#r "nuget: McpFramework, 1.1.0"
#:package McpFramework@1.1.0
#addin nuget:?package=McpFramework&version=1.1.0
#tool nuget:?package=McpFramework&version=1.1.0
McpFramework
通用 MCP(Model Context Protocol)框架。引用本包,把方法标成 [McpServerTool],一行 McpHost.StartAsync 即可把任意 .NET 程序(Console / Web / WinForms / WPF)开放为 MCP 工具,供 Agent 控制。
基于 Microsoft 官方 ModelContextProtocol SDK,支持三种传输:Stdio、Streamable HTTP、遗留 SSE。
安装
dotnet add package McpFramework
目标框架与能力矩阵
包同时提供 netstandard2.0 与 net8.0 两个目标,NuGet 按消费方框架自动选择:
| 消费方目标框架 | 实际选用的资产 | 可用传输 |
|---|---|---|
| net8.0 / net9.0 / net10.0 | net8.0 |
Stdio + Streamable HTTP + 遗留 SSE |
| .NET Framework 4.6.2+(含 4.8) | netstandard2.0 |
仅 Stdio |
| .NET Core 2.x / 3.x、.NET 5 / 6 / 7 | netstandard2.0 |
仅 Stdio |
netstandard2.0 下调用 McpTransport.Http 会抛 PlatformNotSupportedException,消息里写明原因与替代方案——Http/SSE 依赖官方 ModelContextProtocol.AspNetCore,该包不提供 netstandard2.0 资产,这条下限无法通过封装绕过。
因此选型很直接:老 .NET 程序做 Stdio(由 Agent 拉起子进程)即可接入;需要常驻 HTTP 端点再升到 net8.0。
net8.0 目标的 nuspec 里声明了 Microsoft.AspNetCore.App 框架引用,消费端自动带上,无需手写 <FrameworkReference>;netstandard2.0 目标不声明该引用,.NET Framework 项目不会因此报错。
三步接入
using System.ComponentModel;
using McpFramework;
using ModelContextProtocol.Server;
// 1) 把方法标成工具
[McpServerToolType]
public static class MyTools
{
[McpServerTool, Description("设置设备状态文本")]
public static string SetStatus([Description("新文本")] string text)
{
// 改你的运行时状态
return "ok";
}
}
// 2) 一行启动
await McpHost.StartAsync(new McpFrameworkOptions
{
Transport = McpTransport.Http, // 或 McpTransport.Stdio
HttpPort = 5200,
ServerName = "MyApp",
Version = "1.0.0",
EnableLegacySse = true // 需要兼容 SSE 客户端时打开
});
入口类叫
McpHost而不是McpServer,是为了避开官方ModelContextProtocol.Server.McpServer。同一文件里同时using McpFramework;和using ModelContextProtocol.Server;时不会产生 CS0104 二义性。
传输与端点
| 传输 | 端点 | 说明 |
|---|---|---|
| Stdio | 进程 stdout | CLI / 子进程,由 Agent 拉起 |
| Streamable HTTP | /mcp |
常驻服务、Web、GUI |
| 遗留 SSE | /mcp/sse + /mcp/message |
兼容旧版 SSE 客户端(需 EnableLegacySse = true) |
配置(mcp.json)
{
"mcpServers": {
"myapp": { "url": "http://localhost:5200/mcp" },
"myapp-sse": { "url": "http://localhost:5200/mcp/sse" },
"console": { "command": "dotnet", "args": ["path/to/MyApp.dll"] }
}
}
许可证
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Hosting (>= 8.0.1)
- ModelContextProtocol (>= 2.3.0)
-
net8.0
- Microsoft.Extensions.Hosting (>= 10.0.13)
- ModelContextProtocol (>= 2.3.0)
- ModelContextProtocol.AspNetCore (>= 2.3.0)
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.1.0 | 49 | 10/26/2026 |
1.1.0:新增 netstandard2.0 目标——Stdio 传输可在 .NET Framework 4.6.2+、.NET Core 2.x+、.NET 5/6/7 上使用(net48 与 net6.0 已实测握手与工具调用);Http / SSE 仍要求 net8.0,因为官方 ModelContextProtocol.AspNetCore 不提供 netstandard2.0 资产,在旧目标上调用会抛 PlatformNotSupportedException 并给出明确提示。netstandard2.0 目标的 Microsoft.Extensions.Hosting 钉在 8.0.1,避免把 10.x 的传递依赖压给旧框架。同时修复 1.0.0 的两个问题:入口类 McpServer→McpHost(避开与官方 ModelContextProtocol.Server.McpServer 的 CS0104 二义性);ServerName / Version 现在真正写入 serverInfo。