csharp-sdk/tests/ModelContextProtocol.Tests/Server/McpServerLoggingLevelTests.cs
David Cantú 5f992994c3
Decouple Handlers and Collections from protocol types (#765)
* Decouple Handlers and Collections (e.g. ToolsHandler and ToolsCollection) from Capabilities by promoting them to the options types.

Also, group all handlers in container classes, for server, I decided to move McpServerHandlers down to Mcp.Core and move the NotificationHandlers there too.

Also, Fix ListResourceTemplatesHandler issue.

* Add remarks for empty protocol capability types

* Keep JsonIgnore properties and mark them as Obsolete

* Continue supporting Obsolete members

* Update Obsolete messages to indicate the member will be removed

* Add EditorBrowsable Never to the remaining obsolete members
2025-09-24 09:42:03 -05:00

58 lines
1.8 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using System.Runtime.InteropServices;
namespace ModelContextProtocol.Tests.Server;
public class McpServerLoggingLevelTests
{
public McpServerLoggingLevelTests()
{
#if !NET
Assert.SkipWhen(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "https://github.com/modelcontextprotocol/csharp-sdk/issues/587");
#endif
}
[Fact]
public void CanCreateServerWithLoggingLevelHandler()
{
var services = new ServiceCollection();
services.AddMcpServer()
.WithStdioServerTransport()
.WithSetLoggingLevelHandler(async (ctx, ct) => new EmptyResult());
var provider = services.BuildServiceProvider();
provider.GetRequiredService<McpServer>();
}
[Fact]
public void AddingLoggingLevelHandlerSetsLoggingCapability()
{
var services = new ServiceCollection();
services.AddMcpServer()
.WithStdioServerTransport()
.WithSetLoggingLevelHandler(async (ctx, ct) => new EmptyResult());
var provider = services.BuildServiceProvider();
var server = provider.GetRequiredService<McpServer>();
Assert.NotNull(server.ServerOptions.Capabilities?.Logging);
Assert.NotNull(server.ServerOptions.Handlers.SetLoggingLevelHandler);
}
[Fact]
public void ServerWithoutCallingLoggingLevelHandlerDoesNotSetLoggingCapability()
{
var services = new ServiceCollection();
services.AddMcpServer()
.WithStdioServerTransport();
var provider = services.BuildServiceProvider();
var server = provider.GetRequiredService<McpServer>();
Assert.Null(server.ServerOptions.Capabilities?.Logging);
}
}