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:
parent
6787c0cc19
commit
26f60ab7f4
1 changed files with 894 additions and 101 deletions
|
|
@ -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);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue