using ModelContextProtocol.Server; using Microsoft.Extensions.Options; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection; /// /// Provides extension methods for configuring MCP servers with dependency injection. /// public static class McpServerServiceCollectionExtensions { /// /// Adds the Model Context Protocol (MCP) server to the service collection with default options. /// /// The to add the server to. /// Optional callback to configure the . /// An that can be used to further configure the MCP server. public static IMcpServerBuilder AddMcpServer(this IServiceCollection services, Action? configureOptions = null) { services.AddOptions(); services.TryAddEnumerable(ServiceDescriptor.Transient, McpServerOptionsSetup>()); if (configureOptions is not null) { services.Configure(configureOptions); } return new DefaultMcpServerBuilder(services); } }