Skip to content

Commit aaafd7f

Browse files
committed
feat(skills): add dotnet-mcp-builder, deprecate csharp-mcp-server-generator
Adds a comprehensive skill for building MCP (Model Context Protocol) servers in C#/.NET against the official ModelContextProtocol 1.x NuGet packages. Covers both transports (STDIO, Streamable HTTP — SSE is deprecated) and every primitive in the current MCP spec (2025-11-25): tools, prompts, resources, elicitation (form + URL mode), sampling, roots, completions, logging, and MCP Apps. Includes a thin .NET MCP client reference and testing guidance (MCP Inspector + in-memory transport for unit tests). Steers the model toward the current stable 1.x packages instead of the 0.x previews it tends to pin by default, and enforces the STDIO stdout/stderr trap. Also deprecates the existing csharp-mcp-server-generator skill, which predates ModelContextProtocol 1.0 and only covered a subset of the current spec. Its SKILL.md now redirects users to dotnet-mcp-builder so existing install URLs keep working without surprises.
1 parent 9aa4f61 commit aaafd7f

16 files changed

Lines changed: 2288 additions & 51 deletions

File tree

docs/README.skills.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ See [CONTRIBUTING.md](../CONTRIBUTING.md#adding-skills) for guidelines on how to
121121
| [creating-oracle-to-postgres-migration-integration-tests](../skills/creating-oracle-to-postgres-migration-integration-tests/SKILL.md)<br />`gh skills install github/awesome-copilot creating-oracle-to-postgres-migration-integration-tests` | Creates integration test cases for .NET data access artifacts during Oracle-to-PostgreSQL database migrations. Generates DB-agnostic xUnit tests with deterministic seed data that validate behavior consistency across both database systems. Use when creating integration tests for a migrated project, generating test coverage for data access layers, or writing Oracle-to-PostgreSQL migration validation tests. | None |
122122
| [csharp-async](../skills/csharp-async/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-async` | Get best practices for C# async programming | None |
123123
| [csharp-docs](../skills/csharp-docs/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-docs` | Ensure that C# types are documented with XML comments and follow best practices for documentation. | None |
124-
| [csharp-mcp-server-generator](../skills/csharp-mcp-server-generator/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-mcp-server-generator` | Generate a complete MCP server project in C# with tools, prompts, and proper configuration | None |
124+
| [csharp-mcp-server-generator](../skills/csharp-mcp-server-generator/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-mcp-server-generator` | Deprecated: superseded by dotnet-mcp-builder, which targets the current stable ModelContextProtocol 1.x packages and covers every MCP primitive (tools, prompts, resources, elicitation, sampling, roots, MCP Apps) plus both transports (STDIO and Streamable HTTP). Install dotnet-mcp-builder instead. | None |
125125
| [csharp-mstest](../skills/csharp-mstest/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-mstest` | Get best practices for MSTest 3.x/4.x unit testing, including modern assertion APIs and data-driven tests | None |
126126
| [csharp-nunit](../skills/csharp-nunit/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-nunit` | Get best practices for NUnit unit testing, including data-driven tests | None |
127127
| [csharp-tunit](../skills/csharp-tunit/SKILL.md)<br />`gh skills install github/awesome-copilot csharp-tunit` | Get best practices for TUnit unit testing, including data-driven tests | None |
@@ -141,6 +141,7 @@ See [CONTRIBUTING.md](../CONTRIBUTING.md#adding-skills) for guidelines on how to
141141
| [documentation-writer](../skills/documentation-writer/SKILL.md)<br />`gh skills install github/awesome-copilot documentation-writer` | Diátaxis Documentation Expert. An expert technical writer specializing in creating high-quality software documentation, guided by the principles and structure of the Diátaxis technical documentation authoring framework. | None |
142142
| [dotnet-best-practices](../skills/dotnet-best-practices/SKILL.md)<br />`gh skills install github/awesome-copilot dotnet-best-practices` | Ensure .NET/C# code meets best practices for the solution/project. | None |
143143
| [dotnet-design-pattern-review](../skills/dotnet-design-pattern-review/SKILL.md)<br />`gh skills install github/awesome-copilot dotnet-design-pattern-review` | Review the C#/.NET code for design pattern implementation and suggest improvements. | None |
144+
| [dotnet-mcp-builder](../skills/dotnet-mcp-builder/SKILL.md)<br />`gh skills install github/awesome-copilot 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. | `references/client.md`<br />`references/elicitation.md`<br />`references/mcp-apps.md`<br />`references/packages.md`<br />`references/prompt-primitive.md`<br />`references/resource-primitive.md`<br />`references/roots.md`<br />`references/sampling.md`<br />`references/server-features.md`<br />`references/testing.md`<br />`references/tool-primitive.md`<br />`references/transport-http.md`<br />`references/transport-stdio.md` |
144145
| [dotnet-timezone](../skills/dotnet-timezone/SKILL.md)<br />`gh skills install github/awesome-copilot dotnet-timezone` | .NET timezone handling guidance for C# applications. Use when working with TimeZoneInfo, DateTimeOffset, NodaTime, UTC conversion, daylight saving time, scheduling across timezones, cross-platform Windows/IANA timezone IDs, or when a .NET user needs the timezone for a city, address, region, or country and copy-paste-ready C# code. | `references/code-patterns.md`<br />`references/timezone-index.md` |
145146
| [dotnet-upgrade](../skills/dotnet-upgrade/SKILL.md)<br />`gh skills install github/awesome-copilot dotnet-upgrade` | Ready-to-use prompts for comprehensive .NET framework upgrade analysis and execution | None |
146147
| [doublecheck](../skills/doublecheck/SKILL.md)<br />`gh skills install github/awesome-copilot doublecheck` | Three-layer verification pipeline for AI output. Extracts verifiable claims, finds supporting or contradicting sources via web search, runs adversarial review for hallucination patterns, and produces a structured verification report with source links for human review. | `assets/verification-report-template.md` |
Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,24 @@
11
---
22
name: csharp-mcp-server-generator
3-
description: 'Generate a complete MCP server project in C# with tools, prompts, and proper configuration'
3+
description: 'Deprecated: superseded by dotnet-mcp-builder, which targets the current stable ModelContextProtocol 1.x packages and covers every MCP primitive (tools, prompts, resources, elicitation, sampling, roots, MCP Apps) plus both transports (STDIO and Streamable HTTP). Install dotnet-mcp-builder instead.'
44
---
55

6-
# Generate C# MCP Server
6+
# csharp-mcp-server-generator (deprecated)
77

8-
Create a complete Model Context Protocol (MCP) server in C# with the following specifications:
8+
This skill has been superseded by **`dotnet-mcp-builder`**.
99

10-
## Requirements
10+
`dotnet-mcp-builder` is a strict superset: it targets the current stable `ModelContextProtocol` 1.x NuGet packages (this skill predated 1.0 and referenced the prerelease line, which has breaking API differences), covers both transports (STDIO and Streamable HTTP — the legacy HTTP+SSE transport is deprecated upstream), and covers every primitive in the current MCP spec (2025-11-25): tools, prompts, resources, elicitation (form + URL mode), sampling, roots, completions, logging, and MCP Apps. It also includes a basic .NET MCP client and testing reference, and steers the model away from common pitfalls — STDIO stdout/stderr trap, stateless-vs-stateful HTTP wiring, OAuth and reverse-proxy specifics for remote deployments.
1111

12-
1. **Project Structure**: Create a new C# console application with proper directory structure
13-
2. **NuGet Packages**: Include ModelContextProtocol (prerelease) and Microsoft.Extensions.Hosting
14-
3. **Logging Configuration**: Configure all logs to stderr to avoid interfering with stdio transport
15-
4. **Server Setup**: Use the Host builder pattern with proper DI configuration
16-
5. **Tools**: Create at least one useful tool with proper attributes and descriptions
17-
6. **Error Handling**: Include proper error handling and validation
12+
## Migration steps
1813

19-
## Implementation Details
14+
1. Install the replacement skill:
15+
```
16+
gh skills install github/awesome-copilot dotnet-mcp-builder
17+
```
18+
2. (Optional) Uninstall this skill so the deprecation notice no longer appears in your skill list:
19+
```
20+
gh skills uninstall github/awesome-copilot csharp-mcp-server-generator
21+
```
22+
3. Re-run your existing prompts. The new skill triggers on the same .NET MCP server intents and on a broader set (HTTP transport, prompts/resources, elicitation, MCP Apps, debugging).
2023

21-
### Basic Project Setup
22-
- Use .NET 8.0 or later
23-
- Create a console application
24-
- Add necessary NuGet packages with --prerelease flag
25-
- Configure logging to stderr
26-
27-
### Server Configuration
28-
- Use `Host.CreateApplicationBuilder` for DI and lifecycle management
29-
- Configure `AddMcpServer()` with stdio transport
30-
- Use `WithToolsFromAssembly()` for automatic tool discovery
31-
- Ensure the server runs with `RunAsync()`
32-
33-
### Tool Implementation
34-
- Use `[McpServerToolType]` attribute on tool classes
35-
- Use `[McpServerTool]` attribute on tool methods
36-
- Add `[Description]` attributes to tools and parameters
37-
- Support async operations where appropriate
38-
- Include proper parameter validation
39-
40-
### Code Quality
41-
- Follow C# naming conventions
42-
- Include XML documentation comments
43-
- Use nullable reference types
44-
- Implement proper error handling with McpProtocolException
45-
- Use structured logging for debugging
46-
47-
## Example Tool Types to Consider
48-
- File operations (read, write, search)
49-
- Data processing (transform, validate, analyze)
50-
- External API integrations (HTTP requests)
51-
- System operations (execute commands, check status)
52-
- Database operations (query, update)
53-
54-
## Testing Guidance
55-
- Explain how to run the server
56-
- Provide example commands to test with MCP clients
57-
- Include troubleshooting tips
58-
59-
Generate a complete, production-ready MCP server with comprehensive documentation and error handling.
24+
The replacement skill lives under `skills/dotnet-mcp-builder/` in this repository.

skills/dotnet-mcp-builder/SKILL.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: dotnet-mcp-builder
3+
description: '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.'
4+
---
5+
6+
# Building MCP servers in .NET
7+
8+
This skill helps you write production-quality MCP servers and basic clients in C#/.NET against the **official** [`ModelContextProtocol`](https://www.nuget.org/profiles/ModelContextProtocol) NuGet packages, maintained by Microsoft and the MCP project. It targets the **stable 1.x** line and the current spec (2025-11-25).
9+
10+
## When this skill earns its keep
11+
12+
The .NET MCP SDK had years of preview packages (`0.x-preview`) before reaching `1.0`. Without help, the model tends to:
13+
- Pin a stale preview version that won't compile against current samples.
14+
- Miss recent spec features (elicitation URL mode, MCP Apps, structured content blocks).
15+
- Get HTTP transport details wrong (stateful/stateless, proxy buffering, OAuth wiring).
16+
- Forget the STDIO stdout/stderr trap.
17+
18+
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.
19+
20+
## Mental model in 30 seconds
21+
22+
A .NET MCP server is an ordinary `Microsoft.Extensions.Hosting` (or `WebApplication`) app that wires an MCP server through DI:
23+
24+
```csharp
25+
builder.Services
26+
.AddMcpServer()
27+
.WithStdioServerTransport() // OR .WithHttpTransport(...)
28+
.WithToolsFromAssembly() // discover [McpServerToolType] classes
29+
.WithPrompts<MyPrompts>() // optional
30+
.WithResources<MyResources>(); // optional
31+
```
32+
33+
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.
34+
35+
Server-to-client features (sampling, elicitation, roots, log/progress notifications) are methods on the injected `IMcpServer`.
36+
37+
## Decision tree → which references to load
38+
39+
Always load `references/packages.md` if you're creating a new project or unsure of the current package version.
40+
41+
| Task | Load |
42+
|---|---|
43+
| New STDIO server | `references/transport-stdio.md` |
44+
| New HTTP (Streamable) server | `references/transport-http.md` |
45+
| Add/modify a tool | `references/tool-primitive.md` |
46+
| Add/modify a prompt | `references/prompt-primitive.md` |
47+
| Add/modify a resource | `references/resource-primitive.md` |
48+
| Ask the user a question mid-tool | `references/elicitation.md` |
49+
| Call the client's LLM from a tool | `references/sampling.md` |
50+
| Read the user's project roots | `references/roots.md` |
51+
| Return an interactive UI | `references/mcp-apps.md` |
52+
| Argument completions, log/progress notifications, filters, server instructions | `references/server-features.md` |
53+
| Write a .NET program that **consumes** an MCP server | `references/client.md` |
54+
| MCP Inspector, in-memory tests, mocks, CI | `references/testing.md` |
55+
56+
For multi-primitive tasks, load several at once. For trivial edits in an existing file, you usually don't need any.
57+
58+
## Cardinal rules (apply always; these prevent the highest-frequency breakages)
59+
60+
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.
61+
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.
62+
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.
63+
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.
64+
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.
65+
6. **Show the registration line every time you add a primitive.** A new `[McpServerPromptType]` class without `.WithPrompts<...>()` (or `.WithPromptsFromAssembly()`) is invisible.
66+
7. **Don't invent APIs.** If you're unsure a method exists, say so and check the [API reference](https://csharp.sdk.modelcontextprotocol.io/api/ModelContextProtocol.html) — wrong method names cause silent failures.
67+
68+
## Working style
69+
70+
- **Make minimal, additive changes.** Add a method to the existing tool class rather than restructuring the project.
71+
- **For non-trivial setups, run `dotnet build`.** Catches missing usings, attribute typos, and TFM mismatches before the user sees them.
72+
- **Confirm transport + .NET version + primitives before scaffolding** if context doesn't already make them obvious. Default to **.NET 10** for new projects.
73+
74+
## When the user is stuck
75+
76+
Walk this checklist before guessing:
77+
1. **STDIO:** something is writing to stdout (logger sink, `Console.WriteLine`, library banner).
78+
2. **HTTP 404:** path mismatch — `app.MapMcp()` is root, `app.MapMcp("/mcp")` puts it under `/mcp`.
79+
3. **Tool not appearing:** missing `[McpServerToolType]` on the class, or no `.WithToolsFromAssembly()` / `.WithTools<T>()` registered.
80+
4. **Args not bound:** parameter names must match the JSON-RPC `arguments` keys; complex types bind via `System.Text.Json`.
81+
5. **Sampling/elicitation/roots failing:** transport is stateless HTTP, or the client doesn't advertise the capability.
82+
83+
Still stuck? Point the user at the [`EverythingServer`](https://github.com/modelcontextprotocol/csharp-sdk/tree/main/samples/EverythingServer) sample — it exercises every feature.

0 commit comments

Comments
 (0)