Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ModelContextProtocol.Core/Client/McpClientImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ private void RegisterHandlers(McpClientOptions options, NotificationHandlers not
notificationHandlers.RegisterRange(notificationHandlersFromOptions);
}

requestHandlers.Set(
RequestMethods.Ping,
(request, _, cancellationToken) => new ValueTask<PingResult>(new PingResult()),
McpJsonUtilities.JsonContext.Default.JsonNode,
McpJsonUtilities.JsonContext.Default.PingResult);

if (taskStatusHandler is not null)
{
notificationHandlers.Register(
Expand Down
12 changes: 12 additions & 0 deletions tests/ModelContextProtocol.Tests/Client/McpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,16 @@ public async Task SetLoggingLevelAsync_WithRequestParams_NullThrows()
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);
}
}