Use TryAddEnumerable for McpServerOptionsSetup (#252)

This commit is contained in:
Stephen Halter 2025-04-09 10:41:34 -07:00 • committed by GitHub
commit b3a5a82544
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,6 @@
using ModelContextProtocol.Server;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection;
@ -17,7 +18,7 @@ public static class McpServerServiceCollectionExtensions
public static IMcpServerBuilder AddMcpServer(this IServiceCollection services, Action<McpServerOptions>? configureOptions = null)
{
services.AddOptions();
services.AddTransient<IConfigureOptions<McpServerOptions>, McpServerOptionsSetup>();
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<McpServerOptions>, McpServerOptionsSetup>());
if (configureOptions is not null)
{
services.Configure(configureOptions);