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
This commit is contained in:
Stephen Halter 2025-03-31 19:23:49 -07:00 • committed by GitHub
commit 8dc1f5d096
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -83,13 +83,24 @@ It includes a simple echo tool as an example (this is included in the same file
the employed overload of `WithTools` examines the current assembly for classes with the `McpServerToolType` attribute, and registers all methods with the
`McpTool` attribute as tools.)
```
dotnet add package ModelContextProtocol --prerelease
dotnet add package Microsoft.Extensions.Hosting
```
```csharp
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using System.ComponentModel;
var builder = Host.CreateEmptyApplicationBuilder(settings: null);
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole(consoleLogOptions =>
{
// Configure all logs to go to stderr
consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});
builder.Services
.AddMcpServer()
.WithStdioServerTransport()