Add explicit [Experimental] protected constructors to McpClient and McpServer (#1363)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
This commit is contained in:
Copilot 2026-02-23 21:37:39 -05:00 • committed by GitHub
commit 124b43b5c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 2 deletions

View file

@ -3,7 +3,9 @@ using System.Diagnostics;
namespace ModelContextProtocol.Server;
#pragma warning disable MCPEXP002
internal sealed class DestinationBoundMcpServer(McpServerImpl server, ITransport? transport) : McpServer
#pragma warning restore MCPEXP002
{
public override string? SessionId => transport?.SessionId ?? server.SessionId;
public override string? NegotiatedProtocolVersion => server.NegotiatedProtocolVersion;

View file

@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using ModelContextProtocol.Protocol;
namespace ModelContextProtocol.Server;
@ -7,6 +8,14 @@ namespace ModelContextProtocol.Server;
/// </summary>
public abstract partial class McpServer : McpSession
{
/// <summary>
/// Initializes a new instance of the <see cref="McpServer"/> class.
/// </summary>
[Experimental(Experimentals.Subclassing_DiagnosticId, UrlFormat = Experimentals.Subclassing_Url)]
protected McpServer()
{
}
/// <summary>
/// Gets the capabilities supported by the client.
/// </summary>

View file

@ -9,6 +9,7 @@ using System.Text.Json.Serialization.Metadata;
namespace ModelContextProtocol.Server;
/// <inheritdoc />
#pragma warning disable MCPEXP002
internal sealed partial class McpServerImpl : McpServer
{
internal static Implementation DefaultImplementation { get; } = new()
@ -54,6 +55,7 @@ internal sealed partial class McpServerImpl : McpServer
/// <param name="serviceProvider">Optional service provider to use for dependency injection</param>
/// <exception cref="McpException">The server was incorrectly configured.</exception>
public McpServerImpl(ITransport transport, McpServerOptions options, ILoggerFactory? loggerFactory, IServiceProvider? serviceProvider)
#pragma warning restore MCPEXP002
{
Throw.IfNull(transport);
Throw.IfNull(options);