MCP C# Server Development
Overview
Build Model Context Protocol (MCP) servers using C# and .NET. This skill orchestrates your complete development workflow, from project creation to cloud deployment.
🎯 Quick Start
What do you need help with?
| If you want to... | Phase | Action |
|---|---|---|
| Create a new MCP server | Create | Load mcp-csharp-create |
| Run or debug your server | Debug | Load mcp-csharp-debug |
| Write tests or evaluations | Test | Load mcp-csharp-test |
| Publish to NuGet, Docker, or Azure | Publish | Load mcp-csharp-publish |
🚀 Complete Workflow
Phase 1: Create Your Server
When: Starting a new MCP server project
# Install the template (.NET 10+ required)
dotnet new install Microsoft.McpServer.ProjectTemplates
# Create stdio server (local/CLI)
dotnet new mcpserver -n MyMcpServer
# Or create HTTP server (remote/web)
dotnet new mcpserver -n MyMcpServer --transport http
Then: Add your tools using [McpServerToolType] and [McpServerTool] attributes.
📖 Full guide: Load mcp-csharp-create
Phase 2: Debug Your Server
When: Your server is created and you need to run/test it locally
Key steps:
- Configure VS Code (
.vscode/mcp.json) or Visual Studio - Run with
dotnet run - Test with MCP Inspector or GitHub Copilot Agent Mode
- Set breakpoints and debug
📖 Full guide: Load mcp-csharp-debug
Phase 3: Test Your Server
When: Your server works and needs automated tests
Key steps:
- Create xUnit test project
- Write unit tests for individual tools
- Write integration tests with MCP client
- Create evaluations to measure LLM effectiveness
📖 Full guide: Load mcp-csharp-test
Phase 4: Publish Your Server
When: Ready to distribute your server
| Transport | Publish To | Users Run With |
|---|---|---|
| stdio | NuGet.org | dnx YourPackage@1.0.0 |
| HTTP | Docker/Azure | Container URL |
📖 Full guide: Load mcp-csharp-publish
📋 Phase Detection
I'll help you figure out what phase you're in:
You're in Create phase if:
- You don't have a project yet
- You need to add new tools, prompts, or resources
- You're setting up transport (stdio or HTTP)
You're in Debug phase if:
- Your server won't start
- Tools aren't appearing in Copilot
- You need to step through code
- You're getting protocol errors
You're in Test phase if:
- Server works manually but needs automated tests
- You want to verify tool behavior
- You need to create LLM evaluations
You're in Publish phase if:
- Server is tested and ready for users
- You need to package for NuGet
- You need to containerize with Docker
- You want to deploy to Azure
🔧 Common Scenarios
Scenario: "I want to build an MCP server for [Service X]"
- Load: mcp-csharp-create
- Create project with
dotnet new mcpserver -n ServiceXMcpServer - Study the Service X API documentation
- Implement tools for key API operations
- Test with MCP Inspector
Scenario: "My MCP server isn't working"
- Load: mcp-csharp-debug
- Check common issues:
- stdio servers logging to stdout (should be stderr)
- Missing
[McpServerToolType]attribute - Tool not registered with
.WithToolsFromAssembly()
- Use MCP Inspector to test protocol
- Set breakpoints and debug
Scenario: "I need to deploy my server to production"
- Determine transport:
- stdio → NuGet publishing
- HTTP → Docker + Azure
- Load: mcp-csharp-publish
- Follow the publishing guide for your transport
📚 Reference
SDK Packages
| Package | Use Case |
|---|---|
ModelContextProtocol |
stdio servers with hosting/DI |
ModelContextProtocol.AspNetCore |
HTTP servers with ASP.NET Core |
ModelContextProtocol.Core |
Low-level client/server APIs |
Key Patterns
Tool Registration
[McpServerToolType]
public static class MyTools
{
[McpServerTool, Description("Does something useful")]
public static string DoSomething(
[Description("Input parameter")] string input) =>
$"Result: {input}";
}
Program.cs (stdio)
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace);
builder.Services.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly();
await builder.Build().RunAsync();
Program.cs (HTTP)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMcpServer()
.WithHttpTransport()
.WithToolsFromAssembly();
var app = builder.Build();
app.MapMcp();
app.Run();
🔗 Sub-Skills
Load these for detailed guidance on each phase:
| Skill | Description |
|---|---|
| mcp-csharp-create | Project scaffolding, tool/prompt/resource implementation |
| mcp-csharp-debug | Running, debugging, MCP Inspector, Copilot testing |
| mcp-csharp-test | Unit tests, integration tests, evaluations |
| mcp-csharp-publish | NuGet, Docker, Azure deployment |
📖 External Resources
- C# SDK:
https://raw.githubusercontent.com/modelcontextprotocol/csharp-sdk/main/README.md - Microsoft Template Guide:
https://learn.microsoft.com/en-us/dotnet/ai/quickstarts/build-mcp-server - MCP Specification:
https://modelcontextprotocol.io/specification/