csharp-sdk/samples/QuickstartWeatherServer/Program.cs
Stephen Halter 8dc1f5d096
Configure hosted stdio servers to log to stderr (#173)
* Configure hosted stdio servers to log to stderr

* Fix newline

* Use CreateApplicationBuilder where possible

* Address PR feedback
2025-03-31 22:23:49 -04:00

24 lines
684 B
C#

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly();
builder.Logging.AddConsole(options =>
{
options.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Services.AddSingleton(_ =>
{
var client = new HttpClient() { BaseAddress = new Uri("https://api.weather.gov") };
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("weather-tool", "1.0"));
return client;
});
await builder.Build().RunAsync();