What problem does it solve?
This guide captures best practices and concrete guidance for creating reliable C# MCP (Model Context Protocol) servers so developers can avoid integration pitfalls, incorrect transports, and logging issues that break tool communication.
Core Features & Use Cases
- Deployment Modes: Explains when to use STDIO console mode for local integrations and when to use Streamable HTTP mode for containerized or networked deployments.
- Project Structure & Dependencies: Recommends project templates and the required ModelContextProtocol SDK libraries for both STDIO and ASP.NET Core transports.
- Logging and Stability: Describes how to route logging to stderr in STDIO mode to avoid corrupting JSON-RPC streams and how to implement try-catch guards to prevent tool failures from crashing the server.
- Tool Exposure Pattern: Advises on XML comments, McpServerTool attributes, and Description annotations to make tool methods discoverable and reliable for LLM-driven tool invocation.
- Use Case: Create a containerized .NET 10 web service that mounts an /mcp endpoint to expose typed tools for model-driven operations while preserving robust error handling.
Quick Start
Scaffold a .NET 10 project, add the ModelContextProtocol SDK, implement tool classes with McpServerTool attributes and Description annotations, and run in STDIO or HTTP mode with STDIO logging redirected to stderr.