Skip to content

Commit 5140ed0

Browse files
Copilotjeffhandley
andcommitted
Introduce distinct MCPEXP002 diagnostic for subclassing McpClient/McpServer
Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
1 parent ff5e1dc commit 5140ed0

8 files changed

Lines changed: 27 additions & 11 deletions

File tree

docs/list-of-diagnostics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ If you use experimental APIs, you will get one of the diagnostics shown below. T
2323

2424
| Diagnostic ID | Description |
2525
| :------------ | :---------- |
26-
| `MCPEXP001` | MCP experimental APIs including Tasks and Extensions. Tasks provide a mechanism for asynchronous long-running operations that can be polled for status and results (see [MCP Tasks specification](https://modelcontextprotocol.io/specification/draft/basic/utilities/tasks)). Extensions provide a framework for extending the Model Context Protocol while maintaining interoperability (see [SEP-2133](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2133)). |
26+
| `MCPEXP001` | MCP experimental APIs including Tasks and Extensions. Tasks provide a mechanism for asynchronous long-running operations that can be polled for status and results (see [MCP Tasks specification](https://modelcontextprotocol.io/specification/draft/basic/utilities/tasks)). Extensions provide a framework for extending the Model Context Protocol while maintaining interoperability (see [SEP-2133](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2133)). |
27+
| `MCPEXP002` | Subclassing `McpClient` and `McpServer` is experimental and subject to change (see [#1363](https://github.com/modelcontextprotocol/csharp-sdk/pull/1363)). |

src/Common/Experimentals.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,19 @@ internal static class Experimentals
5656
/// URL for the experimental MCP Extensions feature.
5757
/// </summary>
5858
public const string Extensions_Url = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp001";
59+
60+
/// <summary>
61+
/// Diagnostic ID for experimental subclassing of McpClient and McpServer.
62+
/// </summary>
63+
public const string Subclassing_DiagnosticId = "MCPEXP002";
64+
65+
/// <summary>
66+
/// Message for experimental subclassing of McpClient and McpServer.
67+
/// </summary>
68+
public const string Subclassing_Message = "Subclassing McpClient and McpServer is experimental and subject to change.";
69+
70+
/// <summary>
71+
/// URL for experimental subclassing of McpClient and McpServer.
72+
/// </summary>
73+
public const string Subclassing_Url = "https://github.com/modelcontextprotocol/csharp-sdk/pull/1363";
5974
}

src/ModelContextProtocol.Core/Client/McpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract partial class McpClient : McpSession
1111
/// <summary>
1212
/// Initializes a new instance of the <see cref="McpClient"/> class.
1313
/// </summary>
14-
[Experimental(Experimentals.Tasks_DiagnosticId, UrlFormat = Experimentals.Tasks_Url)]
14+
[Experimental(Experimentals.Subclassing_DiagnosticId, UrlFormat = Experimentals.Subclassing_Url)]
1515
protected McpClient()
1616
{
1717
}

src/ModelContextProtocol.Core/Client/McpClientImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
namespace ModelContextProtocol.Client;
77

88
/// <inheritdoc/>
9-
#pragma warning disable MCPEXP001
9+
#pragma warning disable MCPEXP002
1010
internal sealed partial class McpClientImpl : McpClient
1111
{
12-
#pragma warning restore MCPEXP001
1312
private static Implementation DefaultImplementation { get; } = new()
1413
{
1514
Name = AssemblyNameHelper.DefaultAssemblyName.Name ?? nameof(McpClient),
@@ -39,6 +38,7 @@ internal sealed partial class McpClientImpl : McpClient
3938
/// <param name="options">Options for the client, defining protocol version and capabilities.</param>
4039
/// <param name="loggerFactory">The logger factory.</param>
4140
internal McpClientImpl(ITransport transport, string endpointName, McpClientOptions? options, ILoggerFactory? loggerFactory)
41+
#pragma warning restore MCPEXP002
4242
{
4343
options ??= new();
4444

src/ModelContextProtocol.Core/Server/DestinationBoundMcpServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace ModelContextProtocol.Server;
55

6-
#pragma warning disable MCPEXP001
6+
#pragma warning disable MCPEXP002
77
internal sealed class DestinationBoundMcpServer(McpServerImpl server, ITransport? transport) : McpServer
8-
#pragma warning restore MCPEXP001
8+
#pragma warning restore MCPEXP002
99
{
1010
public override string? SessionId => transport?.SessionId ?? server.SessionId;
1111
public override string? NegotiatedProtocolVersion => server.NegotiatedProtocolVersion;

src/ModelContextProtocol.Core/Server/McpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract partial class McpServer : McpSession
1111
/// <summary>
1212
/// Initializes a new instance of the <see cref="McpServer"/> class.
1313
/// </summary>
14-
[Experimental(Experimentals.Tasks_DiagnosticId, UrlFormat = Experimentals.Tasks_Url)]
14+
[Experimental(Experimentals.Subclassing_DiagnosticId, UrlFormat = Experimentals.Subclassing_Url)]
1515
protected McpServer()
1616
{
1717
}

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
namespace ModelContextProtocol.Server;
1010

1111
/// <inheritdoc />
12-
#pragma warning disable MCPEXP001
12+
#pragma warning disable MCPEXP002
1313
internal sealed partial class McpServerImpl : McpServer
1414
{
15-
#pragma warning restore MCPEXP001
1615
internal static Implementation DefaultImplementation { get; } = new()
1716
{
1817
Name = AssemblyNameHelper.DefaultAssemblyName.Name ?? nameof(McpServer),
@@ -56,6 +55,7 @@ internal sealed partial class McpServerImpl : McpServer
5655
/// <param name="serviceProvider">Optional service provider to use for dependency injection</param>
5756
/// <exception cref="McpException">The server was incorrectly configured.</exception>
5857
public McpServerImpl(ITransport transport, McpServerOptions options, ILoggerFactory? loggerFactory, IServiceProvider? serviceProvider)
58+
#pragma warning restore MCPEXP002
5959
{
6060
Throw.IfNull(transport);
6161
Throw.IfNull(options);

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,9 @@ private static async Task InitializeServerAsync(TestServerTransport transport, C
943943
await tcs.Task.WaitAsync(TestConstants.DefaultTimeout, cancellationToken);
944944
}
945945

946-
#pragma warning disable MCPEXP001
946+
#pragma warning disable MCPEXP002
947947
private sealed class TestServerForIChatClient(bool supportsSampling) : McpServer
948-
#pragma warning restore MCPEXP001
948+
#pragma warning restore MCPEXP002
949949
{
950950
public override ClientCapabilities? ClientCapabilities =>
951951
supportsSampling ? new ClientCapabilities { Sampling = new SamplingCapability() } :

0 commit comments

Comments
 (0)