csharp-sdk

This repository contains the official C# SDK for the Model Context Protocol, enabling .NET applications to implement and interact with MCP clients and servers. It facilitates secure integration between LLMs

1,791
101

MCP C# SDK

NuGet preview version

This is the official C# SDK for the Model Context Protocol (MCP), enabling .NET applications to interact with MCP clients and servers. Refer to the API documentation for details.

[!NOTE]
This project is in preview; breaking changes can be introduced without prior notice.

About MCP

MCP standardizes how applications provide context to Large Language Models (LLMs), enabling secure integration between LLMs and data sources.

Installation

Install the package from NuGet: dotnet add package ModelContextProtocol --prerelease

Getting Started (Client)

Use McpClientFactory.CreateAsync to instantiate and connect an IMcpClient. Interact with it to enumerate tools and invoke them. The SDK supports connecting to any MCP server. Tools can be exposed as AIFunction instances for use with IChatClients.

Getting Started (Server)

Create an MCP server and register tools using AddMcpServer, WithStdioServerTransport, and WithToolsFromAssembly. Tools can inject IMcpServer and other dependencies. Fine-grained control over server configuration is available.

Acknowledgements

This library builds upon the mcpdotnet project.

License

This project is licensed under the MIT License.

Repository

MO
modelcontextprotocol

modelcontextprotocol/csharp-sdk

Created

March 10, 2025

Updated

March 28, 2025

Language

C#

Category

Developer Tools