csharp-sdk/samples/TestServerWithHosting/Program.cs
Stephen Halter 90dfc35fbd
Add AspNetCoreSseServer sample (#81)
* Add AspNetCoreSseMcpTransport sample

* Fix build errors after rebase

* React to McpServerFactory changes

* Make Utf8JsonWriter non thread static

* Fix test errors caused by not rebasing the HttpLister changes on factory overhaul commit
2025-03-18 12:56:44 +02:00

37 lines
No EOL
1 KiB
C#

using McpDotNet;
using Microsoft.Extensions.Hosting;
using Serilog;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose() // Capture all log levels
.WriteTo.File(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "TestServer_.log"),
rollingInterval: RollingInterval.Day,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Debug()
.WriteTo.Console(standardErrorFromLevel: Serilog.Events.LogEventLevel.Verbose)
.CreateLogger();
try
{
Log.Information("Starting server...");
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSerilog();
builder.Services.AddMcpServer()
.WithStdioServerTransport()
.WithTools();
var app = builder.Build();
await app.RunAsync();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
await Log.CloseAndFlushAsync();
}