mcp-dotnet-samples
Copilot instructions198 starsChanged 15 months agoMITView on GitHub
Purpose: Make agents instantly productive. Follow ONLY patterns proven in this repo; don’t invent abstractions.
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this copilot-instructions.md into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Always preserve argument delimiter: dotnet run … -- --http <other-switches>.
- Distinctive: line 22
Keep Dockerfiles minimal; expose port 8080 internally.
- Very specific: line 25
Create public class or method with [McpServerTool] (and [Description] for method + parameters).
- Very specific: line 31
When touching awesome-copilot metadata handling, avoid O(n) reload loops—stream or cache.
- Very specific: line 42
Run HTTP: append -- --http (plus sample switches after that).
- Very specific: line 49
Add Dockerfile.<name> + .vscode/mcp.*.json variants.
- Distinctive: line 50
Update root README table with install badges.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Instructions (Concise) – MCP .NET Samples
Purpose: Make agents instantly productive. Follow ONLY patterns proven in this repo; don’t invent abstractions.
Architecture & Runtime
- Mono-repo of independent Hybrid MCP servers:
awesome-copilot/,markdown-to-html/,todo-list/,outlook-email/+ shared libshared/McpSamples.Shared/. - Hybrid pattern: same
Program.cscan run STDIO (default) or stateless HTTP when-- http(or envUseHttp=true). Selection viaAppSettings.UseStreamableHttp(...); final wiring throughBuildApp(useStreamableHttp). - Discovery: Tools / Prompts / Resources auto-registered by assembly scan (
With*FromAssembly). New public attributed types in the entry assembly just work—avoid manual registration. - HTTP mode: single POST
/mcp; some samples add dual OpenAPI docs (swagger 2.0 + openapi 3.0) viaMcpDocumentTransformer<T>.
Sample-Specific Nuance
- awesome-copilot: Large
metadata.json; reuseIMetadataService(don’t repeatedly load whole file). Tools: search & load instructions. - markdown-to-html: Extra switches
-tc,-p,--tagsonly parsed AFTER--delimiter. - todo-list: In‑memory SQLite kept alive by one singleton
SqliteConnection; use EF Core set-based ops (ExecuteUpdateAsync/ExecuteDeleteAsync). - outlook-email: Supports auth parameters (
--tenant-id/-t,--client-id/-c,--client-secret/-s) or user secrets; can also host via Azure Functions (see sample README). Only add auth handling inside this sample—do not leak to shared.
Core Conventions
- Target: .NET 9; nullable + implicit usings enabled globally.
- Entry project path pattern:
./<sample>/src/<PascalName>.HybridApp/. - Always preserve argument delimiter:
dotnet run … -- --http <other-switches>. - JSON camelCase & case-insensitive (match existing config); prefer
System.Text.Json. - Keep Dockerfiles minimal; expose port 8080 internally; local HTTP dev ports: ac=5250, todo=5240, html=5280, outlook=5260.
Adding / Modifying Tools
- Create public class or method with
[McpServerTool](and[Description]for method + parameters). Return lightweight DTO / primitives; let host format. - For prompts use
[McpServerPrompt]. No manual DI registration unless you need extra services—then add viabuilder.ServicesbeforeBuildApp.
Safe Editing Rules
- Don’t change signatures of shared extension methods (
AddAppSettings<T>,BuildApp) unless updating EVERY sample in one PR. - Don’t introduce persistence in other samples without isolating it; never move sample-only concerns into
sharedcasually. - When touching
awesome-copilotmetadata handling, avoid O(n) reload loops—stream or cache.
Frequent Pitfalls (avoid silently breaking)
- Missing
--causes custom flags ignored. - Forgetting singleton SQLite => empty todo DB each request.
- Adding OpenAPI without mapping json endpoints or
AddHttpContextAccessor()=> docs missing. - Wrong
mcp.*.jsoncopied (name/port mismatch) => VS Code cannot start server. - Re-loading
metadata.jsonrepeatedly => performance hit.
Minimal Workflows
- Run STDIO:
dotnet run --project ./markdown-to-html/src/McpSamples.MarkdownToHtml.HybridApp - Run HTTP: append
-- --http(plus sample switches after that). - Container:
docker build -f Dockerfile.todo-list -t todo-list:latest .thendocker run -i --rm -p 8080:8080 todo-list:latest [--http]. - Deploy (per sample):
azd auth loginthenazd upinside sample folder, then read FQDN viaazd env get-value AZURE_RESOURCE_<...>_FQDN.
Adding a New Sample (Checklist)
- Copy structure from an existing sample; reference
McpSamples.Shared. - Implement
Program.cswith same pattern (parse settings -> add services ->BuildApp). - Add
Dockerfile.<name>+.vscode/mcp.*.jsonvariants; expose 8080. - Update root README table with install badges.
PR Expectations (Essentials)
- Build passes (.NET 9). Tools/prompts discoverable. No hardcoded secrets. Sample-specific behavior isolated. Conventional commits.
Questions / unclear? Compare with the most similar existing sample before inventing new structure.
Feedback welcome: open a docs PR if a recurring pattern isn’t captured here.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

