github/awesome-copilot / skills/dotnet-mcp-builder
dotnet-mcp-builder
VerifiedBuild Model Context Protocol (MCP) servers in C#/.NET against the current ModelContextProtocol 2.x NuGet packages. Helps with cases the model gets wrong without guidance — stale versions (0.x preview or 1.x-era defaults), the v2 stateless-by-default HTTP flip, the 2026-07-28 spec deprecations (roots/sampling/logging), MCP Apps and Tasks extension packages, elicitation URL mode, per-session HTTP wiring, OAuth and reverse-proxy deploy specifics, and debugging MapMcp / STDIO / Streamable-HTTP errors. Also covers STDIO and Streamable HTTP transports (SSE is deprecated), tools, prompts, resources, completions, 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.4 KB |
| references/client.md | markdown | 6.2 KB |
| references/elicitation.md | markdown | 7.8 KB |
| references/mcp-apps.md | markdown | 9.8 KB |
| references/packages.md | markdown | 5.2 KB |
| references/prompt-primitive.md | markdown | 5.0 KB |
| references/resource-primitive.md | markdown | 6.1 KB |
| references/roots.md | markdown | 4.0 KB |
| references/sampling.md | markdown | 5.4 KB |
| references/server-features.md | markdown | 6.6 KB |
| references/testing.md | markdown | 6.1 KB |
| references/tool-primitive.md | markdown | 8.4 KB |
| references/transport-http.md | markdown | 8.4 KB |
| references/transport-stdio.md | markdown | 5.1 KB |
references/roots.md
View on GitHub# Roots
> **Deprecated in the 2026-07-28 spec.** SDK 2.x marks the roots APIs `[Obsolete]` (build warning `MCP9005`). They stay wire-compatible with down-level clients during the transition, but for new designs prefer having the client pass in-scope paths as tool arguments, or ask via elicitation / the multi-round-trip `input_required` pattern. Keep this page for maintaining existing 1.x-era servers.
Roots are filesystem (or URI) locations the **client** advertises to the server, scoping what the server is allowed to look at. Think "open workspace folders" in an IDE — the user has implicitly approved the server reading from these places. The server pulls the list when it needs it.
## When you'd use roots
- Building a tool that scans/edits the user's project. Use roots to know which directories are in scope.
- Resolving relative paths in a way that respects the user's open workspace.
- Restricting file access to the advertised roots (defence in depth).
## Prerequisite
Same as sampling/elicitation: server-to-client request → needs STDIO or stateful HTTP. Plus the client must advertise the `roots` capability.
## Reading roots from a tool
```csharp
using System.ComponentModel;
using System.Text;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
[McpServerToolType]
public class WorkspaceTools
{
[McpServerTool, Description("Lists the user's project roots.")]
public static async Task<string> ListProjectRoots(
IMcpServer server,
CancellationToken cancellationToken)
{
if (server.ClientCapabilities?.Roots is null)
return "Client does not support roots.";
var result = await server.RequestRootsAsync(
new ListRootsRequestParams(),
cancellationToken);
var sb = new StringBuilder();
foreach (var root in result.Roots)
sb.AppendLine($"- {root.Name ?? root.Uri}: {root.Uri}");
return sb.ToString();
}
}
```
`Root` has `Uri` (string, often a `file://...`) and optional `Name` (display label).
## Reacting to root changes
Clients send `notifications/roots/list_changed` when the user opens or closes a workspace folder. Subscribe:
```csharp
builder.Services.Configure<McpServerOptions>(options =>
{
options.Capabilities ??= new();
// The client tells us its roots changed; refresh whatever cache we have.
options.Capabilities.NotificationHandlers ??= [];
options.Capabilities.NotificationHandlers[NotificationMethods.RootsListChangedNotification] =
async (notification, ct) =>
{
// Trigger your refresh — typically pull RequestRootsAsync again.
};
});
```
## A useful pattern: cache + refresh
Roots don't change often, but refetching on every tool call is wasteful. Cache them per session and refresh on `roots/list_changed`:
```csharp
public class RootsCache
{
private IReadOnlyList<Root> _roots = Array.Empty<Root>();
public IReadOnlyList<Root> Current => _roots;
public async Task RefreshAsync(IMcpServer server, CancellationToken ct)
{
if (server.ClientCapabilities?.Roots is null) return;
var result = await server.RequestRootsAsync(new ListRootsRequestParams(), ct);
_roots = result.Roots;
}
}
```
Register as singleton (per-session in stateful HTTP, naturally singleton in STDIO).
## Validating paths against roots
Defence in depth: even if a tool argument *looks* like a path under a root, validate.
```csharp
public static bool IsUnderAnyRoot(string absolutePath, IReadOnlyList<Root> roots)
{
foreach (var root in roots)
{
if (!Uri.TryCreate(root.Uri, UriKind.Absolute, out var uri)) continue;
if (!uri.IsFile) continue;
var rootPath = Path.GetFullPath(uri.LocalPath);
if (absolutePath.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase))
return true;
}
return false;
}
```
If a tool receives a path outside the advertised roots, refuse with a clear message — don't silently expand scope.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |