csharp-sdk
The official C# SDK for Model Context Protocol servers and clients. Maintained in collaboration with Microsoft.
claude mcp add --transport stdio modelcontextprotocol-csharp-sdk dotnet run --project path/to/csharp-sdk
How to use
The MCP C# SDK provides a set of libraries for building clients, servers, and tools that conform to the Model Context Protocol (MCP). It includes core functionality for interacting with MCP-compliant services, hosting and dependency injection extensions, and an ASP.NET Core integration for HTTP-based MCP servers. Typical usage involves choosing the appropriate package (Core for low-level access, ModelContextProtocol for hosting/DI, or ModelContextProtocol.AspNetCore for HTTP servers) and wiring MCP services into your .NET application. You can explore the samples and API docs to understand how to create MCP contexts, register MCP handlers, and perform protocol negotiations with LLMs and data sources. The SDK emphasizes integration with .NET ecosystems, enabling secure and structured communication through MCP primitives such as contexts, tools, and data sources.
How to install
Prerequisites:
- Install .NET 6.0+ SDK/Runtime (or a compatible version used by your project).
- Have a compatible IDE or editor (Visual Studio, VS Code with C# extension).
- Optional: NuGet capability for package management in your project.
Installation steps:
-
Create or open your .NET project.
-
Install the MCP packages via NuGet. For example:
dotnet add package ModelContextProtocol.Core dotnet add package ModelContextProtocol dotnet add package ModelContextProtocol.AspNetCore
-
If you are building an ASP.NET Core MCP server, reference the AspNetCore package and configure DI and HTTP endpoints per the API docs.
-
Restore and build:
dotnet restore dotnet build
-
Explore the Getting Started guide and samples for concrete code patterns (clients, servers, and tools) specific to MCP.
Additional notes
Notes and tips:
- The SDK is organized into three packages: Core (low-level client/server APIs), ModelContextProtocol (hosting/DI extensions), and ModelContextProtocol.AspNetCore (HTTP-based MCP servers).
- Use the Getting Started guide and samples in the repository to understand the recommended project structure and usage patterns.
- When hosting MCP servers with ASP.NET Core, ensure proper DI configuration and implement the MCP handlers according to the protocol specification.
- Keep an eye on NuGet package versions to ensure compatibility across Core, main, and ASP.NET Core packages.
- If you run into environment-related issues, verify that the .NET SDK version matches the project’s target framework and that dependencies are restored correctly.
- For runtime configuration, refer to the MCP API documentation to understand available contexts, tools, and data sources you can integrate within your application.
Related MCP Servers
mssql
MSSQL Server MCP implementation written in C#
McpDotNet.Extensions.SemanticKernel
Microsoft SemanticKernel integration for the Model Context Protocol (MCP). Enables seamless use of MCP tools as AI functions.
DatabaseMcpServer
MCP server from ttcc666/DatabaseMcpServer
mcp-dataverse
MCP Server for querying Dataverse using SQL
xperience-community
ASP.NET Core MCP server for Xperience by Kentico projects
console-to-http
Example of converting a stdio MCP server to HTTP using ModelContextProtocol.AspNetCore