Catalog
github/dotnet-mcp-builder

github

dotnet-mcp-builder

Build Model Context Protocol (MCP) servers in C#/.NET against the current ModelContextProtocol 1.x NuGet packages. Especially helps with cases the model often gets wrong without guidance — stale preview versions (it tends to pick 0.3 or 0.4 preview), MCP Apps (interactive UI rendered in the host), elicitation URL mode, per-session HTTP wiring, OAuth and reverse-proxy deploy specifics, and debugging concrete MapMcp / STDIO / Streamable-HTTP errors. Also covers the routine work — STDIO and Streamable HTTP transports (SSE is deprecated), tools, prompts, resources, sampling, roots, completions, logging — and a basic .NET MCP client. Trigger when the user says or implies any .NET MCP server work: ModelContextProtocol, McpServerTool, MapMcp, WithStdioServerTransport, "MCP server in C#", "MCP tool in dotnet", "expose this as MCP", or names a primitive (prompt/resource/elicitation/MCP App) in a .NET context. Skip for MCP work in other languages.

v1.0Latest
New~1.7kUpdated Jun 26, 2026

Building MCP servers in .NET

This skill helps you write production-quality MCP servers and basic clients in C#/.NET against the official ModelContextProtocol NuGet packages, maintained by Microsoft and the MCP project. It targets the stable 1.x line and the current spec (2025-11-25).

When this skill earns its keep

The .NET MCP SDK had years of preview packages (0.x-preview) before reaching 1.0. Without help, the model tends to:

  • Pin a stale preview version that won't compile against current samples.
  • Miss recent spec features (elicitation URL mode, MCP Apps, structured content blocks).
  • Get HTTP transport details wrong (stateful/stateless, proxy buffering, OAuth wiring).
  • Forget the STDIO stdout/stderr trap.

If the task is one of those, load the matching reference and follow it. If it's truly trivial (e.g. "rename this tool method"), you don't need to read everything — the cardinal rules below are the minimum.

Mental model in 30 seconds

A .NET MCP server is an ordinary Microsoft.Extensions.Hosting (or WebApplication) app that wires an MCP server through DI:

builder.Services
    .AddMcpServer()
    .WithStdioServerTransport()      // OR .WithHttpTransport(...)
    .WithToolsFromAssembly()         // discover [McpServerToolType] classes
    .WithPrompts<MyPrompts>()        // optional
    .WithResources<MyResources>();   // optional

Primitives are plain C# methods on classes marked with attributes ([McpServerToolType] + [McpServerTool], [McpServerPromptType] + [McpServerPrompt], [McpServerResourceType] + [McpServerResource]). Parameters bind from JSON-RPC; the SDK builds the JSON Schema from the signature plus [Description] attributes.

Server-to-client features (sampling, elicitation, roots, log/progress notifications) are methods on the injected IMcpServer.

Decision tree → which references to load

Always load references/packages.md if you're creating a new project or unsure of the current package version.

Task Load
New STDIO server references/transport-stdio.md
New HTTP (Streamable) server references/transport-http.md
Add/modify a tool references/tool-primitive.md
Add/modify a prompt references/prompt-primitive.md
Add/modify a resource references/resource-primitive.md
Ask the user a question mid-tool references/elicitation.md
Call the client's LLM from a tool references/sampling.md
Read the user's project roots references/roots.md
Return an interactive UI references/mcp-apps.md
Argument completions, log/progress notifications, filters, server instructions references/server-features.md
Write a .NET program that consumes an MCP server references/client.md
MCP Inspector, in-memory tests, mocks, CI references/testing.md

For multi-primitive tasks, load several at once. For trivial edits in an existing file, you usually don't need any.

Cardinal rules (apply always; these prevent the highest-frequency breakages)

  1. Pin the current stable package, not a preview. Use ModelContextProtocol / ModelContextProtocol.AspNetCore / ModelContextProtocol.Core at the latest 1.x. If you find yourself writing 0.3-preview or 0.4-preview, stop and check NuGet — preview APIs have breaking differences.
  2. STDIO servers must not write to stdout. Stdout is the JSON-RPC channel. Configure LogToStandardErrorThreshold = LogLevel.Trace before anything else and never Console.WriteLine from a tool.
  3. HTTP defaults to stateful. For horizontally-scaled deployments without server-initiated traffic, set options.Stateless = true. Server-to-client features (sampling, elicitation, roots, unsolicited notifications) require stateful HTTP or STDIO — Stateless = true will break them at runtime.
  4. SSE-only is deprecated. Use Streamable HTTP. Only enable legacy SSE (EnableLegacySse = true) for an old client you must support, and call it out.
  5. Always [Description] tools and parameters. This is what the LLM sees when picking and shaping calls. Vague descriptions are the #1 reason tools don't get used.
  6. Show the registration line every time you add a primitive. A new [McpServerPromptType] class without .WithPrompts<...>() (or .WithPromptsFromAssembly()) is invisible.
  7. Don't invent APIs. If you're unsure a method exists, say so and check the API reference — wrong method names cause silent failures.

Working style

  • Make minimal, additive changes. Add a method to the existing tool class rather than restructuring the project.
  • For non-trivial setups, run dotnet build. Catches missing usings, attribute typos, and TFM mismatches before the user sees them.
  • Confirm transport + .NET version + primitives before scaffolding if context doesn't already make them obvious. Default to .NET 10 for new projects.

When the user is stuck

Walk this checklist before guessing:

  1. STDIO: something is writing to stdout (logger sink, Console.WriteLine, library banner).
  2. HTTP 404: path mismatch — app.MapMcp() is root, app.MapMcp("/mcp") puts it under /mcp.
  3. Tool not appearing: missing [McpServerToolType] on the class, or no .WithToolsFromAssembly() / .WithTools<T>() registered.
  4. Args not bound: parameter names must match the JSON-RPC arguments keys; complex types bind via System.Text.Json.
  5. Sampling/elicitation/roots failing: transport is stateless HTTP, or the client doesn't advertise the capability.

Still stuck? Point the user at the EverythingServer sample — it exercises every feature.

Files14
14 files · 76.8 KB

Select a file to preview

Overall Score

88/100

Grade

A

Excellent

Safety

88

Quality

90

Clarity

87

Completeness

83

Summary

This skill guides developers to build production-quality Model Context Protocol (MCP) servers and clients in C#/.NET using the official stable 1.x NuGet packages. It provides a modular reference system that maps common MCP tasks to focused guides, comprehensive mental models, cardinal rules to avoid frequent breakages, and troubleshooting workflows. The skill excels at context-aware guidance, preventing common pitfalls (stale preview versions, STDIO stdout leakage, stateless HTTP limitations), and structuring complex topics (sampling, elicitation, MCP Apps) into digestible, implementation-ready patterns.

Detected Capabilities

file writecode generationgit operationsprocess execution (dotnet build/run)environment variable readshttp requestsjson parsing and serializationassembly introspection

Trigger Keywords

Phrases that MCP clients use to match this skill to user intent.

mcp server in c#model context protocol dotnetexpose tool as mcpstdio mcp serverhttp mcp servermcp client dotnetmcp elicitationmcp sampling

Risk Signals

INFO

Guidance to read environment variables for API keys in STDIO server context

references/transport-stdio.md: 'string apiKey = Environment.GetEnvironmentVariable("MY_API_KEY")'
INFO

Reference to external NuGet repository and package installation

references/packages.md and multiple setup commands
INFO

Instruction to configure logging to stderr to avoid corrupting STDIO JSON-RPC

references/transport-stdio.md: 'LogToStandardErrorThreshold = LogLevel.Trace'
INFO

HTTP transport with authentication middleware (JWT, API key)

references/transport-http.md: bearer auth and API key examples

Referenced Domains

External domains referenced in skill content, detected by static analysis.

cdn.example.comcsharp.sdk.modelcontextprotocol.ioesm.shgithub.comhostlocalhostmodelcontextprotocol.iomy-host.example.commy-server.example.comwww.nuget.org

Use Cases

  • Build a STDIO MCP server that exposes tools for file operations or system interaction
  • Create an HTTP-deployed MCP server with authentication and horizontal scaling
  • Add interactive UI (MCP Apps) to a tool that returns visualizations or dashboards
  • Implement a tool that calls the client's LLM via sampling without managing keys server-side
  • Write an MCP server that asks users for confirmation or input mid-tool-execution via elicitation
  • Build a .NET client that consumes an MCP server for testing, automation, or agent harnesses
  • Debug MCP server issues (STDIO corruption, tool discovery, stateless HTTP limitations)

Quality Notes

  • Excellent modularity: decision tree clearly routes developers to relevant references by task
  • Mental model section (30 seconds) provides strong conceptual foundation before deep dives
  • Cardinal rules section prevents highest-frequency runtime failures (7 practical guardrails with clear rationale)
  • Troubleshooting checklist includes actionable steps (5-point triage) that address common misconfigurations
  • Comprehensive reference files cover edge cases: path traversal defense, resource templates, stateful/stateless HTTP tradeoffs, legacy SSE compatibility
  • Code examples are production-ready: DI patterns, error handling, type-safe APIs (ChatRole, ChatMessage)
  • Strong emphasis on transport-specific gotchas (STDIO stdout corruption, HTTP session affinity, CSP in MCP Apps)
  • Spec version is explicitly versioned (2025-11-25) and future-proofing notes included
  • Missing some advanced topics: cancellation token handling in complex scenarios, batched sampling, performance tuning for high-scale deployments
  • Testing section includes both interactive (Inspector) and automated (in-memory transport) workflows with working examples
Model: claude-haiku-4-5-20251001Analyzed: Jun 26, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Use github/dotnet-mcp-builder in your dev environment

Command Palette

Search for a command to run...