Align the 2026-07-28 wire with spec PR #3002 and SEP-2575 HTTP statuses (#1752)

Co-authored-by: Stephen Halter <halter73@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: tarekgh <tarek.mahmoud.sayed@gmail.com>
This commit is contained in:
Paul Carleton 2026-07-28 00:08:03 +01:00 • committed by GitHub
commit 26f60ab7f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace ModelContextProtocol.Tests.Client;
@ -52,6 +53,39 @@ public class July2026ProtocolConnectionTests : ClientServerTestBase
Assert.NotEqual(McpProtocolVersions.July2026ProtocolVersion, client.NegotiatedProtocolVersion);
}
[Fact]
public async Task Client_AllowsDiscoverResultWithoutServerInfo()
{
ConfigureDiscoverServerInfo(meta => meta.Remove(MetaKeys.ServerInfo));
StartServer();
var options = new McpClientOptions { ProtocolVersion = McpProtocolVersions.July2026ProtocolVersion };
await using var client = await CreateMcpClientForServer(options);
Assert.Equal(McpProtocolVersions.July2026ProtocolVersion, client.NegotiatedProtocolVersion);
Assert.Throws<InvalidOperationException>(() => _ = client.ServerInfo);
}
[Fact]
public async Task Client_RejectsMalformedDiscoverServerInfo()
{
ConfigureDiscoverServerInfo(meta => meta[MetaKeys.ServerInfo] = "invalid");
StartServer();
var options = new McpClientOptions { ProtocolVersion = McpProtocolVersions.July2026ProtocolVersion };
await Assert.ThrowsAsync<JsonException>(() => CreateMcpClientForServer(options));
}
[Fact]
public async Task Client_RejectsNullDiscoverServerInfo()
{
ConfigureDiscoverServerInfo(meta => meta[MetaKeys.ServerInfo] = null);
StartServer();
var options = new McpClientOptions { ProtocolVersion = McpProtocolVersions.July2026ProtocolVersion };
await Assert.ThrowsAsync<JsonException>(() => CreateMcpClientForServer(options));
}
[Fact]
public async Task InitializeHandshakeClient_CannotCallServerDiscover()
{
@ -86,4 +120,19 @@ public class July2026ProtocolConnectionTests : ClientServerTestBase
Assert.Equal("complete", discoverResult.ResultType);
Assert.Equal([McpProtocolVersions.July2026ProtocolVersion], discoverResult.SupportedVersions);
}
private void ConfigureDiscoverServerInfo(Action<JsonObject> configure)
{
McpServerBuilder.WithMessageFilters(filters => filters.AddOutgoingFilter(next => async (context, cancellationToken) =>
{
if (context.JsonRpcMessage is JsonRpcResponse { Result: JsonObject result } &&
result["supportedVersions"] is not null &&
result["_meta"] is JsonObject meta)
{
configure(meta);
}
await next(context, cancellationToken);
}));
}
}