MCP Deep Dive, Part 12: Building MCP Servers in C# and .NET 9 — The SDK, DI, and Native AOT A developer building MCP servers in C# and .NET 9 details how the MCP C# SDK simplifies protocol handling, schema generation, and dependency injection. The SDK automatically generates JSON Schema from attributed methods and supports Native AOT for cold-start optimization, making it a high-leverage tool for .NET backends. We've built servers, clients, tools, auth, and governance across this series — all in C , without ever slowing down to look at howthe .NET tooling makes it pleasant. This part does. If your backend is already .NET, an MCP server turns out to be one of the highest-leverage things you can build: a thin, attributed, DI-native surface over the domain services you already own. This is Part 12 of a 15-part deep dive on Model Context Protocol MCP . Part 3 built a production server treating C as the vehicle; this part is about the vehicle itself — the MCP C SDK , the attribute-to-schema model, dependency injection, the two hosting models, testing, and Native AOT. | Concern | Hand-rolled before | MCP C SDK after | |---|---|---| | Protocol | parse JSON-RPC by hand | AddMcpServer owns it | | Tool schema | hand-written JSON Schema | auto from the McpServerTool method | | Dependencies | new-up / statics | constructor DI, scoped per call | | Transport | locked | stdio host or ASP.NET Core, same tools | | Testing | run the whole agent | unit-test methods + in-memory transport | | Cold start | fat JIT | trimming / Native AOT | Quick honesty first: the Python and TypeScript SDKs are the most mature MCP ecosystems, and if your stack is Python/TS, use those. The reason to build MCP servers in .NET is singular but decisive — your domain already lives there. An MCP server should sit next to the data and logic it exposes and reuse them; rewriting a C domain in Python just to speak MCP is pure waste. YOU WRITE THE SDK DOES --------- ----------- Program.cs AddMcpServer, - JSON-RPC framing + initialize + negotiation transport, WithTools... tools/list, resources/list with pagination McpServerToolType classes - reflect method signatures - JSON Schema McpServerTool methods - dispatch tools/call - resolve tool from DI - invoke DI registrations your domain - scoped instance per call, CancellationToken threaded Add two NuGet packages and let the SDK own JSON-RPC, initialize , capability negotiation, and schema generation.