ModelContextProtocol.NET is a C# SDK implementation of the Model Context Protocol (MCP). The project is hosted on GitHub and is currently under active development.
Purpose: To provide .NET/C# developers with infrastructure for implementing MCP servers, making it easy to integrate tools into the MCP protocol as handlers.
Main capabilities:
- Standard input/output (stdio) communication is supported.
- The tool integration framework is supported; tools are implemented as handlers. For Native AOT compatibility, parameter types must provide JsonTypeInfo.
- Native AOT compatible.
- Provides a calculator example (src/ModelContextProtocol.NET.Demo.Calculator) covering tool handler implementation, request/response handling, and error management.
- The project structure is divided into a core library, server components, server hosting (integration into the .NET Generic Host), and examples.
Usage:
- Install the server package; if hosting integration is needed, add the server hosting package.
- You can choose between not using hosting or using hosting.
- Logging configuration: McpServerBuilder uses Microsoft.Extensions.Logging.ILogger; when using stdio transport, logs cannot be output to the console, so you need to configure a logging provider that writes to another target; if no logging provider is configured, an empty logger is used and no logs are written. The Generic Host adds console logging by default, and AddMcpServer removes them by default; if you need to retain them, set keepDefaultLogging to true in AddMcpServer.
- When implementing tools, you can write handler classes to use capabilities such as dependency injection, or provide functions directly.
Applicable scenarios: Developers who need to build MCP servers in a .NET environment, expose capabilities in the form of tool handlers, and care about Native AOT compatibility.
Limitations and status: WebSocket support, resource management, and the prompt system are still under development; more documentation and implementation guides are not yet available.