Register ping handler in McpSessionHandler to support server-initiated pings (#1391)

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: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
Copilot 2026-02-26 18:53:20 -05:00 • committed by GitHub
commit 919e8383f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -782,4 +782,16 @@ public class McpClientTests : ClientServerTestBase
await Assert.ThrowsAsync<ArgumentNullException>("requestParams",
() => client.SetLoggingLevelAsync((SetLevelRequestParams)null!, TestContext.Current.CancellationToken));
}
[Fact]
public async Task ServerCanPingClient()
{
await using McpClient client = await CreateMcpClientForServer();
var pingRequest = new JsonRpcRequest { Method = RequestMethods.Ping };
var response = await Server.SendRequestAsync(pingRequest, TestContext.Current.CancellationToken);
Assert.NotNull(response);
Assert.NotNull(response.Result);
}
}