File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
tests/ModelContextProtocol.TestServer Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -83,13 +83,24 @@ It includes a simple echo tool as an example (this is included in the same file
8383the employed overload of `WithTools ` examines the current assembly for classes with the `McpServerToolType ` attribute , and registers all methods with the
8484`McpTool ` attribute as tools .)
8585
86+ ```
87+ dotnet add package ModelContextProtocol --prerelease
88+ dotnet add package Microsoft .Extensions .Hosting
89+ ```
90+
8691```csharp
8792using Microsoft .Extensions .DependencyInjection ;
8893using Microsoft .Extensions .Hosting ;
94+ using Microsoft .Extensions .Logging ;
8995using ModelContextProtocol .Server ;
9096using System .ComponentModel ;
9197
9298var builder = Host .CreateEmptyApplicationBuilder (settings : null );
99+ builder .Logging .AddConsole (consoleLogOptions =>
100+ {
101+ // Configure all logs to go to stderr
102+ consoleLogOptions .LogToStandardErrorThreshold = LogLevel .Trace ;
103+ });
93104builder .Services
94105 .AddMcpServer ()
95106 .WithStdioServerTransport ()
@@ -101,8 +112,7 @@ public static class EchoTool
101112{
102113 [McpServerTool , Description (" Echoes the message back to the client." )]
103114 public static string Echo (string message ) => $" hello {message }" ;
104- }
105- ```
115+ }```
106116
107117Tools can have the `IMcpServer ` representing the server injected via a parameter to the method , and can use that for interaction with
108118the connected client. Similarly, arguments may be injected via dependency injection. For example, this tool will use the supplied
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ private static ILoggerFactory CreateLoggerFactory()
2424
2525 return LoggerFactory . Create ( builder =>
2626 {
27+ builder . AddConsole ( options =>
28+ {
29+ options . LogToStandardErrorThreshold = LogLevel . Trace ;
30+ } ) ;
2731 builder . AddSerilog ( ) ;
2832 } ) ;
2933 }
You can’t perform that action at this time.
0 commit comments