|
| 1 | +using Microsoft.Extensions.DependencyInjection; |
| 2 | +using ModelContextProtocol.Protocol.Types; |
| 3 | +using ModelContextProtocol.Server; |
| 4 | + |
| 5 | +namespace ModelContextProtocol.Tests.Server; |
| 6 | +public class McpServerLoggingLevelTests |
| 7 | +{ |
| 8 | + [Fact] |
| 9 | + public void CanCreateServerWithLoggingLevelHandler() |
| 10 | + { |
| 11 | + var services = new ServiceCollection(); |
| 12 | + |
| 13 | + services.AddMcpServer() |
| 14 | + .WithStdioServerTransport() |
| 15 | + .WithSetLoggingLevelHandler((ctx, ct) => |
| 16 | + { |
| 17 | + return Task.FromResult(new EmptyResult()); |
| 18 | + }); |
| 19 | + |
| 20 | + var provider = services.BuildServiceProvider(); |
| 21 | + |
| 22 | + provider.GetRequiredService<IMcpServer>(); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public void AddingLoggingLevelHandlerSetsLoggingCapability() |
| 27 | + { |
| 28 | + var services = new ServiceCollection(); |
| 29 | + |
| 30 | + services.AddMcpServer() |
| 31 | + .WithStdioServerTransport() |
| 32 | + .WithSetLoggingLevelHandler((ctx, ct) => |
| 33 | + { |
| 34 | + return Task.FromResult(new EmptyResult()); |
| 35 | + }); |
| 36 | + |
| 37 | + var provider = services.BuildServiceProvider(); |
| 38 | + |
| 39 | + var server = provider.GetRequiredService<IMcpServer>(); |
| 40 | + |
| 41 | + Assert.NotNull(server.ServerOptions.Capabilities?.Logging); |
| 42 | + Assert.NotNull(server.ServerOptions.Capabilities.Logging.SetLoggingLevelHandler); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public void ServerWithoutCallingLoggingLevelHandlerDoesNotSetLoggingCapability() |
| 47 | + { |
| 48 | + var services = new ServiceCollection(); |
| 49 | + services.AddMcpServer() |
| 50 | + .WithStdioServerTransport(); |
| 51 | + var provider = services.BuildServiceProvider(); |
| 52 | + var server = provider.GetRequiredService<IMcpServer>(); |
| 53 | + Assert.Null(server.ServerOptions.Capabilities?.Logging); |
| 54 | + } |
| 55 | +} |
0 commit comments