🚀 Build powerful Model Context Protocol servers and clients in C# with .NET 9
Featuring stdio, HTTP, and SSE transport protocols • Enhanced console UI • Production-ready
| 🖥️ StdioServer | 🌐 HttpServer | 🎯 Client |
|---|---|---|
| Local Development | Remote Deployment | Universal Testing |
| Claude Desktop Ready | Scalable & Cloud-Native | Beautiful Console UI |
| Zero Configuration | Docker Compatible | Multi-Transport |
- 🎯 StdioServer Project: Standard I/O MCP server with example tools (
DateTool,EchoTool,PingPongTool) - 🌐 HttpServer Project: Modern HTTP server with Streamable HTTP and SSE fallback support
- 🎨 Client Project: Universal client with enhanced Spectre.Console interface supporting all transports
- 🔧 Extensibility: Add new tools effortlessly - they appear in both servers automatically
- 📦 Production Ready: Built on official Microsoft ModelContextProtocol packages
- 🚀 Multiple Transports: stdio, Streamable HTTP, and legacy SSE support
- 🔗 MCP C# Template
- StdioServer Project: A standard input/output MCP server that includes three example tools (
DateTool,EchoTool, andPingPongTool) automatically exposed via stdio transport. - HttpServer Project: A modern HTTP-based MCP server with streamable HTTP and Server-Sent Events (SSE) fallback support for remote deployment scenarios.
- Client Project: A versatile MCP client that connects to any MCP server (not limited to .NET) using multiple transport protocols (stdio, HTTP, SSE) with an enhanced console interface.
- Extensibility: Easily add new tools to either server or extend the client's capabilities.
The template includes four main projects:
- StdioServer: Standard I/O transport server for local development and integration
- HttpServer: HTTP/SSE transport server for remote deployment and web scenarios
- Client: Universal client supporting all transport types with command-line interface
- Core: Shared library containing common tools and utilities
- .NET 9 SDK installed on your machine
- A code editor like Visual Studio 2022 or Visual Studio Code
The StdioServer project exposes tools via standard input/output, ideal for local development and AI client integration.
- Navigate to the
src/StdioServerdirectory - Run:
npx @modelcontextprotocol/inspector dotnet run
Starting MCP inspector...
⚙️ Proxy server listening on port 6277
🔍 MCP Inspector is up and running at http://127.0.0.1:6274 🚀
- Open your browser to the URL shown (e.g., http://127.0.0.1:6274)
- Click "Connect" → "List Tools" → Select and run tools
The HttpServer project provides HTTP-based MCP with SSE streaming support for remote deployment scenarios.
- Navigate to the
src/HttpServerdirectory - Run:
dotnet run - Server will start on
http://localhost:5000with MCP endpoint ready
The HttpServer supports:
- Streamable HTTP: Modern HTTP POST/GET with optional SSE streaming
- Legacy SSE: Full Server-Sent Events transport for older clients
- Auto-detection: Automatically handles both transport modes
- Launch the MCP Inspector
- Select
Streamable HTTPas the Transport Type - Enter the URL:
http://localhost:5000 - Click "Connect" → "List Tools" → Select and run tools
You can view the server logs in the console output where the HttpServer is running. It will display incoming requests, tool execution results, and any errors encountered.
# Some output omitted for clarity and brevity
[2025-06-10 17::58:09] info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5000
[2025-06-10 17::58:09] info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
[2025-06-10 17::58:09] info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production
[2025-06-10 17::58:09] info: Microsoft.Hosting.Lifetime[0] Content root path: C:\krk\mcp\mcp-csharp-template\src\HttpServer
[2025-06-10 17::58:45] info: McpServer => method 'initialize' request handler called.
[2025-06-10 17::58:45] info: McpServer => Client (mcp-inspector) method 'initialize' request handler completed.
[2025-06-10 17::58:56] info: McpServer => Client (mcp-inspector) method 'tools/list' request handler called.
[2025-06-10 17::58:56] info: McpServer => Client (mcp-inspector) method 'tools/list' request handler completed.
[2025-06-10 17::58:58] info: McpServer => Client (mcp-inspector) method 'tools/call' request handler called.
[2025-06-10 17::58:58] info: McpServer => Client (mcp-inspector) method 'tools/call' request handler completed.
The Client project features a modern console interface with Spectre.Console and supports multiple transport protocols.
Navigate to src/Client and use predefined profiles:
# Connect to StdioServer
dotnet run --launch-profile dotnet-stdio
# Connect to HttpServer (modern HTTP)
dotnet run --launch-profile http-modern
# Connect to HttpServer (legacy SSE)
dotnet run --launch-profile sse-legacyThe client supports various transport types through command-line arguments:
# .NET stdio server
dotnet run -- dotnet -n StdioServer -p "../StdioServer/StdioServer.csproj"
# HTTP server (modern streamable HTTP)
dotnet run -- http -n HttpServer -u "http://localhost:5000"
# SSE server (legacy compatibility)
dotnet run -- sse -n HttpServer -u "http://localhost:5000"
# NPM package server
dotnet run -- npx -n weather-server -p "@modelcontextprotocol/server-weather"
# Python server with uvx
dotnet run -- uvx -n filesystem -p "mcp-server-filesystem"The client now features:
- Rich UI: Powered by Spectre.Console with colors and styled output
- Tool Selection: Interactive numbered menu with descriptions
- Input Validation: Required vs optional parameter handling
- Response Display: Formatted output panels with proper styling
Example interaction:
The template includes three demonstration tools:
- DateTool: Returns the current date formatted as "dddd MMMM d, yyyy"
- EchoTool: Echoes back any input provided by the user
- PingPongTool: Responds with "pong" when "ping" is sent, otherwise returns "clearly you are not a ping pong master"
Add to your VS Code settings.json:
{
"mcp": {
"mcpCSharpTemplateStdio": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"C:\\path\\to\\mcp-csharp-template\\src\\StdioServer\\StdioServer.csproj"
]
}
}
}{
"mcp": {
"mcpCSharpTemplateHttp": {
"type": "http",
"url": "http://localhost:5000",
"headers": {
"VERSION": "1.0"
}
}
}
}{
"mcpServers": {
"mcpCSharpTemplate": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--no-build",
"--project",
"C:\\path\\to\\mcp-csharp-template\\src\\StdioServer"
]
}
}
}Since Claude Desktop doesn't natively support HTTP/SSE, use a proxy:
{
"mcpServers": {
"mcpCSharpHttp": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:5000"
]
}
}
}├── src/
│ ├── Core/ # Shared tools and utilities
│ ├── StdioServer/ # Standard I/O MCP server
│ ├── HttpServer/ # HTTP/SSE MCP server
│ └── Client/ # Universal MCP client
├── test/
│ └── Unit/ # Unit tests for tools
└── Directory.Build.props # Shared build configuration
- Create your tool in the
src/Core/Tools/directory:
[McpServerToolType]
public static class MyTool
{
[McpServerTool]
[Description("Description of what your tool does")]
public static string MyMethod(string parameter) => $"Result: {parameter}";
}- Tools are automatically discovered and exposed by both servers
The template supports multiple MCP transport protocols:
- Stdio: Standard input/output for local integration
- Streamable HTTP: Modern HTTP POST/GET with optional SSE streaming (MCP spec 2025-03-26)
- Legacy SSE: Full Server-Sent Events transport for backward compatibility
- Best for local development and AI client integration
- No network configuration required
- Ideal for Claude Desktop, VS Code, and development tools
- Deploy to cloud platforms (Azure App Service, AWS, etc.)
- Supports remote MCP scenarios
- Can be containerized with Docker
- Scales horizontally for multiple client connections
The template uses the official Microsoft ModelContextProtocol packages:
ModelContextProtocol- Main package with hosting and dependency injection extensionsModelContextProtocol.AspNetCore- Library for HTTP-based MCP servers
This project is in preview; breaking changes can be introduced without prior notice.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to fork the repository and submit a pull request.
Repository: https://github.com/krk-architect/mcp-csharp-template
- Microsoft's collaboration with Anthropic to create the official C# SDK for Model Context Protocol
- Model Context Protocol - The open protocol specification
- The .NET community for their support and resources


