<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh" -->

---
title: Build Your First MCP Server in C# with the Official SDK
description: A hands-on walkthrough builds an MCP server in C# using the official ModelContextProtocol SDK 2.1.0 on .NET 10, covering tool creation with attributes, stdio...
canonical: https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Build Your First MCP Server in C# with the Official SDK | daily.dev
og:description: A hands-on walkthrough builds an MCP server in C# using the official ModelContextProtocol SDK 2.1.0 on .NET 10, covering tool creation with attributes, stdio...
og:url: https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh
og:image: https://api.daily.dev/og/posts/gFVR6BVSh.png
og:image:alt: Build Your First MCP Server in C# with the Official SDK
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build Your First MCP Server in C# with the Official SDK

**[Code with Mukesh](https://daily.dev/sources/codewithmukesh)** · [@iammukeshm](https://daily.dev/iammukeshm) · 17 min read · 17 upvotes · 2 comments

## Summary

A hands-on walkthrough builds an MCP server in C# using the official ModelContextProtocol SDK 2.1.0 on .NET 10, covering tool creation with attributes, stdio and streamable HTTP transports, dependency injection, and testing with MCP Inspector. It highlights that SDK 2.0 (released 28 July 2026) changed key defaults from 1.x: HTTP transport is now stateless by default, the initialize handshake was replaced by discovery-first negotiation, Roots/Sampling/Logging were deprecated, Tasks moved to a separate package, and Tool.inputSchema became required. A practical example builds a NuGet version-lookup tool to stop coding agents from hallucinating package versions, plus guidance on when an MCP server is worth building versus just exposing a REST API.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://codewithmukesh.com/blog/build-mcp-server-csharp>

## Questions this post answers

### What changed in the MCP C# SDK version 2.0?

Version 2.0.0 aligned the SDK with MCP specification revision 2026-07-28, making HTTP transport stateless by default (no Mcp-Session-Id header), replacing the initialize handshake with discovery-first negotiation, deprecating Roots, Sampling, and Logging (warning MCP9005), moving Tasks to a separate wire-incompatible package, and making Tool.inputSchema required, throwing a JsonException if missing.

_Teams upgrading MCP servers can track SDK breaking changes like these on daily.dev before they hit production._

### Which ModelContextProtocol NuGet package should I install to build an MCP server in C#

Install the ModelContextProtocol package, which is the default choice for stdio servers, hosting, dependency injection, and attribute-based tool discovery, and it automatically pulls in ModelContextProtocol.Core. Add ModelContextProtocol.AspNetCore only if the server needs to be reached over HTTP. Two more packages, Extensions.Tasks and Extensions.Apps, cover long-running tools and experimental UI.

_Developers choosing among MCP-related nuget packages can compare options like these through daily.dev._

### Why does my MCP server disconnect immediately after the client connects?

The client is receiving polluted stdout instead of clean JSON-RPC, most commonly caused by a Console.WriteLine, a startup banner, or a logger that writes to stdout instead of stderr. In stdio mode, stdout is the protocol channel itself, so any stray output corrupts it; setting LogToStandardErrorThreshold routes logs to stderr and fixes the issue.

_Anyone debugging a broken MCP server setup can find troubleshooting steps like this on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@f4nt0** · 0 upvotes

> I like your content, here a simple reward as gratitute for your work

**@pdfopsdev** · 0 upvotes

> the stdout gotcha isn't C# specific fwiw, hit the exact same thing with a node stdio MCP server once, one stray console.log two dependencies deep and the whole json-rpc stream corrupts silently. wish more SDKs just hijacked global stdout at startup instead of leaving it to convention.

## Similar posts on daily.dev

- [Build Your First MCP Server in C\#: A Step-by-Step Quickstart](https://daily.dev/posts/build-your-first-mcp-server-in-c-a-step-by-step-quickstart-pt500c6tu) · We Are .NET · 4 upvotes · 0 comments
- [Building an MCP Server in .NET Without Buying the Hype — Daily DevOps & .NET](https://daily.dev/posts/building-an-mcp-server-in-net-without-buying-the-hype-daily-devops-net-f3pfe3wik) · Daily DevOps & .NET · 1 upvotes · 0 comments
- [Building our first MCP Resources enabled MCP Server with C\#](https://daily.dev/posts/building-our-first-mcp-resources-enabled-mcp-server-with-c--6i1z3fqjr) · The Art of Simplicity · 1 upvotes · 0 comments
- [Your first MCP server with ASP.NET](https://daily.dev/posts/your-first-mcp-server-with-asp-net-0kwwmyuuj) · Tim Deschryver · 20 upvotes · 3 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#mcp](https://daily.dev/tags/mcp), [#c#](https://daily.dev/tags/c#), [#claude-code](https://daily.dev/tags/claude-code), [#aspnetcore](https://daily.dev/tags/aspnetcore)

[View this post on daily.dev](https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Build Your First MCP Server in C# with the Official SDK","url":"https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh"},"datePublished":"2026-08-16T17:37:23.724Z","dateModified":"2026-09-14T08:00:22.831Z","description":"A hands-on walkthrough builds an MCP server in C# using the official ModelContextProtocol SDK 2.1.0 on .NET 10, covering tool creation with attributes, stdio...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cc7f41777b0dff2f708698ac9c7c92e2?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cc7f41777b0dff2f708698ac9c7c92e2?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code with Mukesh","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Person","name":"Mukesh Murugan","url":"https://daily.dev/iammukeshm","image":"https://lh3.googleusercontent.com/a-/AFdZucr2UBIpOeVTWohK8XKuXPOutNG6hgyQMz7CYj7LEA=s100","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":790}},"commentCount":2,"discussionUrl":"https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":17},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":".net,mcp,c#,claude-code,aspnetcore","timeRequired":"PT17M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code with Mukesh","item":"https://daily.dev/sources/codewithmukesh"},{"@type":"ListItem","position":3,"name":"Build Your First MCP Server in C# with the Official SDK"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh","comment":[{"@type":"Comment","text":"I like your content, here a simple reward as gratitute for your work","datePublished":"2026-09-30T18:55:28.158Z","url":"https://daily.dev/posts/gFVR6BVSh#c-NQ4xWISWC","author":{"@type":"Person","name":"Gabriel Stundner","url":"https://daily.dev/f4nt0","image":"https://media.daily.dev/image/upload/s--UpSzkOxs--/f_auto/v1753488097/avatars/avatar_whNNg0ajcmne1B7hPHb0U?_a=BAMClqZW0"}},{"@type":"Comment","text":"the stdout gotcha isn’t C# specific fwiw, hit the exact same thing with a node stdio MCP server once, one stray console.log two dependencies deep and the whole json-rpc stream corrupts silently. wish more SDKs just hijacked global stdout at startup instead of leaving it to convention.","datePublished":"2026-08-18T18:04:40.588Z","url":"https://daily.dev/posts/gFVR6BVSh#c-v2eSCBcFr","author":{"@type":"Person","name":"PDFops","url":"https://daily.dev/pdfopsdev","image":"https://media.daily.dev/image/upload/s---8isRBKc--/f_auto/v1782922291/avatars/avatar_orjMeK8QKaaVZwGq7ScPz?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh#faq","mainEntity":[{"@type":"Question","name":"What changed in the MCP C# SDK version 2.0?","acceptedAnswer":{"@type":"Answer","text":"Version 2.0.0 aligned the SDK with MCP specification revision 2026-07-28, making HTTP transport stateless by default (no Mcp-Session-Id header), replacing the initialize handshake with discovery-first negotiation, deprecating Roots, Sampling, and Logging (warning MCP9005), moving Tasks to a separate wire-incompatible package, and making Tool.inputSchema required, throwing a JsonException if missing. Teams upgrading MCP servers can track SDK breaking changes like these on daily.dev before they hit production."}},{"@type":"Question","name":"Which ModelContextProtocol NuGet package should I install to build an MCP server in C#","acceptedAnswer":{"@type":"Answer","text":"Install the ModelContextProtocol package, which is the default choice for stdio servers, hosting, dependency injection, and attribute-based tool discovery, and it automatically pulls in ModelContextProtocol.Core. Add ModelContextProtocol.AspNetCore only if the server needs to be reached over HTTP. Two more packages, Extensions.Tasks and Extensions.Apps, cover long-running tools and experimental UI. Developers choosing among MCP-related nuget packages can compare options like these through daily.dev."}},{"@type":"Question","name":"Why does my MCP server disconnect immediately after the client connects?","acceptedAnswer":{"@type":"Answer","text":"The client is receiving polluted stdout instead of clean JSON-RPC, most commonly caused by a Console.WriteLine, a startup banner, or a logger that writes to stdout instead of stderr. In stdio mode, stdout is the protocol channel itself, so any stray output corrupts it; setting LogToStandardErrorThreshold routes logs to stderr and fixes the issue. Anyone debugging a broken MCP server setup can find troubleshooting steps like this on daily.dev."}}]}
```

