ModelContextProtocol.Core 0.2.0-preview.3

Prefix Reserved
This is a prerelease version of ModelContextProtocol.Core.
dotnet add package ModelContextProtocol.Core --version 0.2.0-preview.3
                    
NuGet\Install-Package ModelContextProtocol.Core -Version 0.2.0-preview.3
                    
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="ModelContextProtocol.Core" Version="0.2.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ModelContextProtocol.Core" Version="0.2.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="ModelContextProtocol.Core" />
                    
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 ModelContextProtocol.Core --version 0.2.0-preview.3
                    
#r "nuget: ModelContextProtocol.Core, 0.2.0-preview.3"
                    
#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.
#addin nuget:?package=ModelContextProtocol.Core&version=0.2.0-preview.3&prerelease
                    
Install ModelContextProtocol.Core as a Cake Addin
#tool nuget:?package=ModelContextProtocol.Core&version=0.2.0-preview.3&prerelease
                    
Install ModelContextProtocol.Core as a Cake Tool

MCP C# SDK Core

NuGet preview version

Core .NET SDK for the Model Context Protocol, enabling .NET applications, services, and libraries to implement and interact with MCP clients and servers. Please visit our API documentation for more details on available functionality.

This project is in preview; breaking changes can be introduced without prior notice.

About MCP

The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). It enables secure integration between LLMs and various data sources and tools.

For more information about MCP:

Installation

To get started, install the core package from NuGet

dotnet add package ModelContextProtocol.Core --prerelease

Getting Started (Client)

To get started writing a client, the McpClientFactory.CreateAsync method is used to instantiate and connect an IMcpClient to a server. Once you have an IMcpClient, you can interact with it, such as to enumerate all available tools and invoke tools.

var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
{
    Name = "Everything",
    Command = "npx",
    Arguments = ["-y", "@modelcontextprotocol/server-everything"],
});

var client = await McpClientFactory.CreateAsync(clientTransport);

// Print the list of tools available from the server.
foreach (var tool in await client.ListToolsAsync())
{
    Console.WriteLine($"{tool.Name} ({tool.Description})");
}

// Execute a tool (this would normally be driven by LLM tool invocations).
var result = await client.CallToolAsync(
    "echo",
    new Dictionary<string, object?>() { ["message"] = "Hello MCP!" },
    cancellationToken:CancellationToken.None);

// echo always returns one and only one text content object
Console.WriteLine(result.Content.First(c => c.Type == "text").Text);

Clients can connect to any MCP server, not just ones created using this library. The protocol is designed to be server-agnostic, so you can use this library to connect to any compliant server.

Tools can be easily exposed for immediate use by IChatClients, because McpClientTool inherits from AIFunction.

// Get available functions.
IList<McpClientTool> tools = await client.ListToolsAsync();

// Call the chat client using the tools.
IChatClient chatClient = ...;
var response = await chatClient.GetResponseAsync(
    "your prompt here",
    new() { Tools = [.. tools] },

Getting Started (Server)

The core package provides the basic server functionality. Here's an example of creating a simple MCP server without dependency injection:

using ModelContextProtocol.Server;
using System.ComponentModel;

// Create server options
var serverOptions = new McpServerOptions();

// Add tools directly
serverOptions.Capabilities.Tools = new() 
{
    ListChanged = true,
    ToolCollection = [
        McpServerTool.Create((string message) => $"hello {message}", new()
        {
            Name = "echo", 
            Description = "Echoes the message back to the client."
        })
    ]
};

// Create and run server with stdio transport
var server = new McpServer(serverOptions);
using var stdioTransport = new StdioServerTransport();
await server.RunAsync(stdioTransport, CancellationToken.None);

For more advanced scenarios with dependency injection, hosting, and automatic tool discovery, see the ModelContextProtocol package.

Acknowledgements

The MCP C# SDK builds upon the excellent work from the mcpdotnet project by Liri. We extend our gratitude for providing a foundational implementation that inspired this SDK.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product 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 is compatible.  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. 
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 ModelContextProtocol.Core:

Package Downloads
ModelContextProtocol

.NET SDK for the Model Context Protocol (MCP) with hosting and dependency injection extensions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.0-preview.3 3,339 6/3/2025