<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom" -->

---
title: MCP Servers in C#: How They Work and How to Build One
description: MCP servers expose tools, data and prompt templates to AI assistants like Claude, GitHub Copilot and ChatGPT through a single open protocol instead of custom...
canonical: https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: MCP Servers in C#: How They Work and How to Build One | daily.dev
og:description: MCP servers expose tools, data and prompt templates to AI assistants like Claude, GitHub Copilot and ChatGPT through a single open protocol instead of custom...
og:url: https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom
og:image: https://api.daily.dev/og/posts/Ltzs2RIoM.png
og:image:alt: MCP Servers in C#: How They Work and How to Build One
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.

# MCP Servers in C#: How They Work and How to Build One

**[C\# Corner](https://daily.dev/sources/csharpcorner)** · 15 min read · 0 upvotes · 0 comments

## Summary

MCP servers expose tools, data and prompt templates to AI assistants like Claude, GitHub Copilot and ChatGPT through a single open protocol instead of custom integrations. The current spec, 2026-07-28, removes the initialize handshake and protocol sessions, making servers stateless. The official C# SDK, now at NuGet version 2.3.0, splits into ModelContextProtocol for stdio hosting, ModelContextProtocol.AspNetCore for Streamable HTTP, and ModelContextProtocol.Core for low-level APIs. The guide walks through building a stdio and HTTP server in C#, equivalent examples in TypeScript and Python, connecting to Claude Code, VS Code and ChatGPT, and securing servers with OAuth 2.1, least privilege and defenses against prompt injection.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.c-sharpcorner.com/article/mcp-servers-in-c-sharp-how-they-work-and-how-to-build-one>

## Questions this post answers

### What changed in the MCP 2026-07-28 specification compared to earlier versions?

The 2026-07-28 revision removes the initialize/notifications-initialized handshake and protocol-level sessions, including the Mcp-Session-Id header; servers now mint their own state handles passed as tool arguments. It adds a required server/discover method, replaces server-initiated requests with an input_required retry pattern, moves long-running tasks into a tasks extension, and requires Mcp-Method and Mcp-Name headers on Streamable HTTP POSTs.

_Keep up with fast-moving MCP spec changes before they break your integration, with daily.dev._

### Which NuGet packages do I need to build an MCP server in C#?

Use ModelContextProtocol for hosting and dependency injection in stdio servers, ModelContextProtocol.AspNetCore to add Streamable HTTP support on ASP.NET Core, and ModelContextProtocol.Core for low-level client and server APIs with minimal dependencies. The official SDK, maintained with Microsoft, is at NuGet version 2.3.0.

_daily.dev helps .NET developers track SDK releases when picking packages for new AI tooling._

### Why does my stdio-based MCP server crash with invalid JSON errors?

Something is writing to stdout, which carries the protocol's JSON-RPC messages, so any stray Console.WriteLine or print() call corrupts the stream. The fix is to route all logging to stderr instead, such as configuring builder.Logging.AddConsole with LogToStandardErrorThreshold set to Trace in a C# stdio server.

_Debugging stdio protocol issues gets easier when daily.dev surfaces fixes other developers already found._

## Similar posts on daily.dev

- [Build Your First MCP Server in C\# with the Official SDK](https://daily.dev/posts/build-your-first-mcp-server-in-c-with-the-official-sdk-gfvr6bvsh) · Code with Mukesh · 17 upvotes · 2 comments
- [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
- [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: [#ai-agents](https://daily.dev/tags/ai-agents), [#github](https://daily.dev/tags/github), [#mcp](https://daily.dev/tags/mcp), [#claude](https://daily.dev/tags/claude), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom)

```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":"MCP Servers in C#: How They Work and How to Build One","url":"https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom"},"datePublished":"2026-10-31T13:06:57.293Z","dateModified":"2026-10-31T13:07:25.574Z","description":"MCP servers expose tools, data and prompt templates to AI assistants like Claude, GitHub Copilot and ChatGPT through a single open protocol instead of custom...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2f0863edc7a614d66eacf2cbdee557fc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2f0863edc7a614d66eacf2cbdee557fc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"C# Corner","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":"Organization","name":"C# Corner","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/ada2d584df6241748fc4e71878dc70a3","url":"https://daily.dev/sources/csharpcorner"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,github,mcp,claude,c#","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"C# Corner","item":"https://daily.dev/sources/csharpcorner"},{"@type":"ListItem","position":3,"name":"MCP Servers in C#: How They Work and How to Build One"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/mcp-servers-in-c-how-they-work-and-how-to-build-one-ltzs2riom#faq","mainEntity":[{"@type":"Question","name":"What changed in the MCP 2026-07-28 specification compared to earlier versions?","acceptedAnswer":{"@type":"Answer","text":"The 2026-07-28 revision removes the initialize/notifications-initialized handshake and protocol-level sessions, including the Mcp-Session-Id header; servers now mint their own state handles passed as tool arguments. It adds a required server/discover method, replaces server-initiated requests with an input_required retry pattern, moves long-running tasks into a tasks extension, and requires Mcp-Method and Mcp-Name headers on Streamable HTTP POSTs. Keep up with fast-moving MCP spec changes before they break your integration, with daily.dev."}},{"@type":"Question","name":"Which NuGet packages do I need to build an MCP server in C#?","acceptedAnswer":{"@type":"Answer","text":"Use ModelContextProtocol for hosting and dependency injection in stdio servers, ModelContextProtocol.AspNetCore to add Streamable HTTP support on ASP.NET Core, and ModelContextProtocol.Core for low-level client and server APIs with minimal dependencies. The official SDK, maintained with Microsoft, is at NuGet version 2.3.0. daily.dev helps .NET developers track SDK releases when picking packages for new AI tooling."}},{"@type":"Question","name":"Why does my stdio-based MCP server crash with invalid JSON errors?","acceptedAnswer":{"@type":"Answer","text":"Something is writing to stdout, which carries the protocol's JSON-RPC messages, so any stray Console.WriteLine or print() call corrupts the stream. The fix is to route all logging to stderr instead, such as configuring builder.Logging.AddConsole with LogToStandardErrorThreshold set to Trace in a C# stdio server. Debugging stdio protocol issues gets easier when daily.dev surfaces fixes other developers already found."}}]}
```

