TouchSocket.Mcp 4.3.11

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package TouchSocket.Mcp --version 4.3.11
                    
NuGet\Install-Package TouchSocket.Mcp -Version 4.3.11
                    
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="TouchSocket.Mcp" Version="4.3.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TouchSocket.Mcp" Version="4.3.11" />
                    
Directory.Packages.props
<PackageReference Include="TouchSocket.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 TouchSocket.Mcp --version 4.3.11
                    
#r "nuget: TouchSocket.Mcp, 4.3.11"
                    
#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 TouchSocket.Mcp@4.3.11
                    
#: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=TouchSocket.Mcp&version=4.3.11
                    
Install as a Cake Addin
#tool nuget:?package=TouchSocket.Mcp&version=4.3.11
                    
Install as a Cake Tool

TouchSocket.Mcp

这是一个提供 MCP (Model Context Protocol) 服务器和客户端的组件库。

功能

  • 支持 stdio、Streamable HTTP 和命名管道传输协议
  • 支持 Tools、Resources、Prompts 功能
  • 基于特性标注的 API 风格([McpTool]、[McpResource]、[McpPrompt])

命名管道

命名管道两端使用 UTF-8 JSON 消息,每条消息以 \n 结尾,组件自动处理消息分包和粘包。 JSON 序列化选项的 WriteIndented 必须保持为 false(默认值)。 这是 TouchSocket 的自定义 MCP 传输,两端需要使用相同的消息格式。

using TouchSocket.Core;
using TouchSocket.Mcp;
using TouchSocket.NamedPipe;
using TouchSocket.Rpc;
using TouchSocket.Sockets;

using var service = new McpNamedPipeService();
await service.SetupAsync(new TouchSocketConfig()
    .SetPipeName("touchsocket-mcp")
    .SetMcpServerOptions(options => options.ServerInfo.Name = "MyMcpServer")
    .ConfigureContainer(container => container.AddRpcStore(store => store.RegisterServer<MyTools>())));
await service.StartAsync();

using var client = new McpNamedPipeClient();
await client.SetupAsync(new TouchSocketConfig()
    .SetPipeName("touchsocket-mcp")
    .SetMcpClientOptions(options => options.Timeout = TimeSpan.FromSeconds(10)));
await client.ConnectAsync();
await client.InitializeAsync();
var tools = await client.ListAllToolsAsync();
var result = await client.CallToolAsync("Echo", new Dictionary<string, object> { ["text"] = "Hello MCP" });

await client.CloseAsync();
await service.StopAsync();

public class MyTools : SingletonRpcServer
{
    [McpTool]
    public string Echo(string text) => text;
}

服务端工具中可通过 IMcpCallContext.Caller 获取 McpNamedPipeSessionClient。 每个连接有独立的 MCP 会话;客户端断线重连后需再次调用 InitializeAsync()。 请求支持取消,连接关闭时会取消仍在等待响应的请求。

完整示例:SimpleTest 的 12.1 命令。

文档

https://touchsocket.net/

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 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. 
.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 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TouchSocket.Mcp:

Package Downloads
TWebApi

供独立宿主复用的 TouchSocket Web API 统一结果、参数验证与依赖注入桥接。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-beta.11 39 11/14/2026
5.0.0-beta.5 58 11/12/2026
4.3.11 366 10/25/2026
4.3.10 140 10/11/2026
4.3.9 201 9/17/2026
4.3.8 131 9/17/2026
4.3.7 144 9/10/2026
4.3.6 153 9/5/2026
4.3.5 131 9/5/2026
4.3.4 156 8/27/2026
4.3.3 142 8/22/2026
4.3.2 168 8/15/2026
4.3.1 163 8/9/2026
4.3.0 172 8/1/2026
4.2.18 187 7/26/2026
4.2.17 237 7/12/2026
4.2.16 190 7/5/2026
4.2.14 226 6/14/2026
4.2.13 188 6/7/2026
4.2.12 190 5/30/2026
Loading failed