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/resource-primitive.md
View on GitHub# Resources
Resources are server-exposed "things" identified by a URI. Hosts list them so the user can pick which ones to attach to the conversation; tools and prompts can also reference them via `EmbeddedResourceBlock`. Think files, database rows, API objects, settings — anything addressable.
Two flavours:
- **Static resource** — a fixed URI (`config://app/settings`). Useful for singletons.
- **Resource template** — a URI with placeholders (`docs://articles/{id}`). The host (or LLM) substitutes parameters; your method receives them.
## Static resource
```csharp
using System.ComponentModel;
using System.Text.Json;
using ModelContextProtocol.Server;
[McpServerResourceType]
public class AppResources
{
[McpServerResource(
UriTemplate = "config://app/settings",
Name = "App Settings",
MimeType = "application/json")]
[Description("Returns application configuration settings.")]
public static string GetSettings() =>
JsonSerializer.Serialize(new { theme = "dark", language = "en" });
}
```
Register:
```csharp
.WithResources<AppResources>()
// or
.WithResourcesFromAssembly()
```
## Templated resource
The placeholders in `UriTemplate` map by name to method parameters. Anything not a placeholder follows the same DI rules as tools (`IMcpServer`, `CancellationToken`, services).
```csharp
[McpServerResourceType]
public class DocumentResources
{
[McpServerResource(
UriTemplate = "docs://articles/{id}",
Name = "Article",
MimeType = "text/markdown")]
[Description("Returns an article by its ID.")]
public static ResourceContents GetArticle(string id)
{
string? content = LoadArticle(id);
if (content is null)
throw new McpException($"Article not found: {id}");
return new TextResourceContents
{
Uri = $"docs://articles/{id}",
MimeType = "text/markdown",
Text = content
};
}
}
```
## Return types
| Return | Result |
|---|---|
| `string` | Wrapped in `TextResourceContents` with the URI from the template and the declared `MimeType`. |
| `byte[]` | Wrapped in `BlobResourceContents`. |
| `TextResourceContents` | Returned as-is — set `Uri`, `MimeType`, `Text`. |
| `BlobResourceContents` | Returned as-is — use `BlobResourceContents.FromBytes(...)`. |
| `IEnumerable<ResourceContents>` | Multi-part resource. |
### Binary resource
```csharp
[McpServerResource(
UriTemplate = "images://photos/{id}",
Name = "Photo",
MimeType = "image/png")]
public static BlobResourceContents GetPhoto(int id)
{
byte[] data = LoadPhoto(id);
return BlobResourceContents.FromBytes(data, $"images://photos/{id}", "image/png");
}
```
### Pointing at the file system
A common pattern is exposing files from disk. Be careful about path traversal — never trust the URI verbatim.
```csharp
[McpServerResource(
UriTemplate = "file://workspace/{*relativePath}",
Name = "Workspace file")]
public static TextResourceContents ReadFile(string relativePath, IOptions<WorkspaceOptions> opts)
{
var root = opts.Value.RootPath;
var fullPath = Path.GetFullPath(Path.Combine(root, relativePath));
if (!fullPath.StartsWith(root, StringComparison.Ordinal))
throw new McpException("Path traversal blocked.");
return new TextResourceContents
{
Uri = $"file://workspace/{relativePath.Replace("\\", "/")}",
MimeType = "text/plain",
Text = File.ReadAllText(fullPath)
};
}
```
## Listing dynamic resources
Attribute-based discovery covers the common case (one method per template). When you need to **enumerate** resources that don't fit a template — say, "list every file in the workspace" — implement a low-level handler in `McpServerOptions.Capabilities.Resources`:
```csharp
builder.Services.Configure<McpServerOptions>(options =>
{
options.Capabilities ??= new();
options.Capabilities.Resources ??= new();
options.Capabilities.Resources.ListResourcesHandler = (ctx, ct) =>
{
var resources = Directory
.EnumerateFiles(WorkspaceRoot, "*.*", SearchOption.AllDirectories)
.Select(path => new Resource
{
Uri = "file://workspace/" + Path.GetRelativePath(WorkspaceRoot, path).Replace('\\', '/'),
Name = Path.GetFileName(path),
MimeType = "text/plain"
})
.ToList();
return ValueTask.FromResult(new ListResourcesResult { Resources = resources });
};
});
```
You can mix attribute-based and handler-based — the SDK merges both.
## Resource subscriptions (server-pushed updates)
If a client subscribes to a resource and it changes, push a notification:
```csharp
await server.SendNotificationAsync(
NotificationMethods.ResourceUpdatedNotification,
new ResourceUpdatedNotificationParams { Uri = "docs://articles/42" },
cancellationToken);
```
For wholesale list changes:
```csharp
await server.SendNotificationAsync(
NotificationMethods.ResourceListChangedNotification,
new ResourceListChangedNotificationParams(),
cancellationToken);
```
Both require a stateful transport.
## Reading resources from a client
```csharp
ReadResourceResult result = await client.ReadResourceAsync("config://app/settings");
foreach (var content in result.Contents)
{
if (content is TextResourceContents text)
Console.WriteLine($"[{text.MimeType}] {text.Text}");
else if (content is BlobResourceContents blob)
File.WriteAllBytes("out.bin", blob.DecodedData.ToArray());
}
```
## Resources vs. tools — when to pick which
- **Resource:** the user (or LLM) wants to *attach context* to the conversation. Read-only, addressable, listable. The host controls when/whether to load it. Ideal for documents, configs, schemas.
- **Tool:** the LLM wants to *do something* (which may include reading data). Side-effects, actions, parameters that don't fit a URI.
If you have something the LLM might want to *search* over, expose both: a `search_articles` tool and `docs://articles/{id}` resource template. The tool returns a list of URIs; the host fetches the content via the resource.
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 |