Get the FREE Ultimate OpenClaw Setup Guide →

csharp-sdk

The official C# SDK for Model Context Protocol servers and clients. Maintained in collaboration with Microsoft.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Create or open your .NET project.

  2. Install the MCP packages via NuGet. For example:

    dotnet add package ModelContextProtocol.Core dotnet add package ModelContextProtocol dotnet add package ModelContextProtocol.AspNetCore

  3. If you are building an ASP.NET Core MCP server, reference the AspNetCore package and configure DI and HTTP endpoints per the API docs.

  4. Restore and build:

    dotnet restore dotnet build

  5. 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

Sponsor this space

Reach thousands of developers