$npx -y skills add managedcode/dotnet-skills --skill mcpBuild or consume Model Context Protocol (MCP) servers and clients in .NET using the official MCP C# SDK, including stdio, Streamable HTTP, tools, prompts, resources, and capability negotiation. USE FOR: .NET MCP servers or clients; stdio versus HTTP transport choices; tools, reso
| 1 | # MCP C# SDK for .NET |
| 2 | |
| 3 | ## Trigger On |
| 4 | |
| 5 | - building or consuming MCP servers from a .NET application or library |
| 6 | - choosing between stdio and HTTP transport for MCP |
| 7 | - exposing tools, resources, prompts, completions, or logging to an MCP host |
| 8 | - connecting a .NET app to an existing MCP server and passing discovered tools into `IChatClient` |
| 9 | - bootstrapping a minimal MCP client/server from the `.NET AI` quickstarts or publishing a server to the MCP Registry |
| 10 | - implementing capability-aware flows such as roots, sampling, elicitation, subscriptions, session resumption, or enterprise managed authorization |
| 11 | |
| 12 | ## Use This Skill Instead Of |
| 13 | |
| 14 | - Use `mcp` when **protocol interoperability** is the requirement. |
| 15 | - Use `microsoft-extensions-ai` when you only need model/provider abstraction or local tool orchestration without the MCP wire protocol. |
| 16 | - Use `microsoft-agent-framework` when the main problem is agent orchestration; combine it with `mcp` only when those agents must consume or expose MCP endpoints. |
| 17 | - Use the `.NET AI` quickstarts for the very first vertical slice, then come back here to harden transport, capability negotiation, publishing, and host interoperability. |
| 18 | |
| 19 | ## Documentation |
| 20 | |
| 21 | - [MCP C# SDK overview](https://csharp.sdk.modelcontextprotocol.io/) |
| 22 | - [Getting Started](https://csharp.sdk.modelcontextprotocol.io/concepts/getting-started.html) |
| 23 | - [API reference](https://csharp.sdk.modelcontextprotocol.io/api/ModelContextProtocol.html) |
| 24 | - [Conceptual docs](https://csharp.sdk.modelcontextprotocol.io/concepts/index.html) |
| 25 | - [Versioning policy](https://csharp.sdk.modelcontextprotocol.io/versioning.html) |
| 26 | - [Experimental APIs](https://csharp.sdk.modelcontextprotocol.io/experimental.html) |
| 27 | - [MCP C# SDK repository](https://github.com/modelcontextprotocol/csharp-sdk) |
| 28 | - [Model Context Protocol specification](https://modelcontextprotocol.io/specification/) |
| 29 | |
| 30 | ## References |
| 31 | |
| 32 | Load only what the task needs: |
| 33 | |
| 34 | - [references/patterns.md](references/patterns.md) - current server/client patterns, transports, capabilities, filters, and chat-client integration |
| 35 | - [references/security.md](references/security.md) - safe error handling, auth boundaries, stdio logging hygiene, and defensive tool/resource patterns |
| 36 | |
| 37 | ## Package Selection |
| 38 | |
| 39 | | Package | Choose when | |
| 40 | |---------|-------------| |
| 41 | | `ModelContextProtocol.Core` | You only need a client or low-level server APIs and want the smallest dependency set. | |
| 42 | | `ModelContextProtocol` | You want the main SDK package with hosting, DI, attribute discovery, and stdio server support. Start here for most projects. | |
| 43 | | `ModelContextProtocol.AspNetCore` | You are hosting a remote MCP server in ASP.NET Core over HTTP. This includes the main package. | |
| 44 | |
| 45 | ## Transport Selection |
| 46 | |
| 47 | | Transport | Use when | Notes | |
| 48 | |-----------|----------|-------| |
| 49 | | `StdioClientTransport` / `WithStdioServerTransport()` | The MCP server should run as a local child process. | Best for local tooling and editor/agent integrations. | |
| 50 | | `HttpClientTransport` + `HttpTransportMode.StreamableHttp` | The server is remote or should be reachable over HTTP. | Recommended HTTP transport; supports streaming and session resumption. | |
| 51 | | `HttpTransportMode.Sse` | You must connect to an older SSE-only server. | Legacy compatibility only; do not choose this for new servers. | |
| 52 | |
| 53 | ## Current v1.4 Notes |
| 54 | |
| 55 | - The July 2026 `.NET AI` MCP documentation now separates a getting-started hub, client and server quickstarts, MCP Registry publishing, and a server-resource index. Use those pages to bootstrap a vertical slice, then return to the C# SDK docs here for exact transport, capability, authorization, and lifecycle behavior. |
| 56 | - Upgrade HTTP/SSE servers to at least `v1.4.1`: it releases the `StreamableHttpServerTransport` SSE response reference when a GET ends, preventing disconnected long-lived clients from retaining Kestrel connections and their memory-pool buffers until session disposal. |
| 57 | - Enterprise managed authorization now has an SDK surface through `IdentityAssertionGrantProvider` for the Identity Assertion Authorization Grant flow. Use it only when the enterprise SSO and MCP authorization-server contract is part of the actual scenario. |
| 58 | - `StdioClientTransportOptions.Inhe |