The basic sample (03-GettingStarted/samples/csharp) is a stdio MCP server that exposes five calculator tools: Add, Subtract, Multiply, Divide, and IsPrime.
using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;var builder = Host.CreateApplicationBuilder(args);builder.Logging.AddConsole(consoleLogOptions =>{ // Configure all logs to go to stderr consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;});builder.Services .AddMcpServer() .WithStdioServerTransport() .WithToolsFromAssembly();await builder.Build().RunAsync();
Tools are discovered automatically via WithToolsFromAssembly(). Any static method decorated with [McpServerTool] is registered as an MCP tool — no manual registration needed.
The advanced sample (04-PracticalImplementation/samples/csharp) adds HTTP transport via ModelContextProtocol.AspNetCore, integrates .NET Aspire for local observability, and includes an azd configuration for one-command Azure deployment.
1
Navigate to the advanced sample
cd 04-PracticalImplementation/samples/csharp
2
Start with .NET Aspire
dotnet watch run --project ./src/AppHost
The Aspire dashboard opens in your browser. Note the http://localhost:XXXX/ URL shown for the calculator service.