docs: add McpServerOptionsSetup code comment (#77)

This commit is contained in:
ConanYao 2025-03-24 10:30:39 +08:00 • committed by GitHub
commit 1a5732b158
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,19 +6,31 @@ using ModelContextProtocol.Utils;
namespace ModelContextProtocol.Configuration; namespace ModelContextProtocol.Configuration;
/// <summary>
/// Configures the McpServerOptions using provided server handlers.
/// </summary>
/// <param name="serverHandlers">The server handlers configuration options.</param>
internal sealed class McpServerOptionsSetup(IOptions<McpServerHandlers> serverHandlers) : IConfigureOptions<McpServerOptions> internal sealed class McpServerOptionsSetup(IOptions<McpServerHandlers> serverHandlers) : IConfigureOptions<McpServerOptions>
{ {
/// <summary>
/// Configures the given McpServerOptions instance by setting server information
/// and applying custom server handlers.
/// </summary>
/// <param name="options">The options instance to be configured.</param>
public void Configure(McpServerOptions options) public void Configure(McpServerOptions options)
{ {
Throw.IfNull(options); Throw.IfNull(options);
var assemblyName = Assembly.GetEntryAssembly()?.GetName(); var assemblyName = Assembly.GetEntryAssembly()?.GetName();
// Set server information based on the entry assembly
options.ServerInfo = new Implementation options.ServerInfo = new Implementation
{ {
Name = assemblyName?.Name ?? "McpServer", Name = assemblyName?.Name ?? "McpServer",
Version = assemblyName?.Version?.ToString() ?? "1.0.0", Version = assemblyName?.Version?.ToString() ?? "1.0.0",
}; };
// Apply custom server handlers
serverHandlers.Value.OverwriteWithSetHandlers(options); serverHandlers.Value.OverwriteWithSetHandlers(options);
} }
} }