Skip to content

Commit a467c3d

Browse files
authored
Merge branch 'main' into completiondetails
2 parents 0d60fe2 + 1578e94 commit a467c3d

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

docs/concepts/transports/transports.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ app.MapMcp("/mcp");
137137

138138
When using a custom route, Streamable HTTP clients should connect directly to that route (e.g., `https://host/mcp`), while SSE clients should connect to `{route}/sse` (e.g., `https://host/mcp/sse`).
139139

140-
See the `ModelContextProtocol.AspNetCore` package [README](https://github.com/modelcontextprotocol/csharp-sdk/blob/main/src/ModelContextProtocol.AspNetCore/README.md) for more configuration options.
141-
142140
### SSE transport (legacy)
143141

144142
The [SSE (Server-Sent Events)] transport is a legacy mechanism that uses unidirectional server-to-client streaming with a separate HTTP endpoint for client-to-server messages. New implementations should prefer Streamable HTTP.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ModelContextProtocol.Core/McpSessionHandler.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ public McpSessionHandler(
133133
_outgoingMessageFilter = outgoingMessageFilter ?? (next => next);
134134
_logger = logger;
135135

136+
// Per the MCP spec, ping may be initiated by either party and must always be handled.
137+
_requestHandlers.Set(
138+
RequestMethods.Ping,
139+
(request, _, cancellationToken) => new ValueTask<PingResult>(new PingResult()),
140+
McpJsonUtilities.JsonContext.Default.JsonNode,
141+
McpJsonUtilities.JsonContext.Default.PingResult);
142+
136143
LogSessionCreated(EndpointName, _sessionId, _transportKind);
137144
}
138145

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public McpServerImpl(ITransport transport, McpServerOptions options, ILoggerFact
9191
ConfigureLogging(options);
9292
ConfigureCompletion(options);
9393
ConfigureExperimental(options);
94-
ConfigurePing();
9594

9695
// Register any notification handlers that were provided.
9796
if (options.Handlers.NotificationHandlers is { } notificationHandlers)
@@ -204,14 +203,6 @@ public override async ValueTask DisposeAsync()
204203
await _sessionHandler.DisposeAsync().ConfigureAwait(false);
205204
}
206205

207-
private void ConfigurePing()
208-
{
209-
SetHandler(RequestMethods.Ping,
210-
async (request, _) => new PingResult(),
211-
McpJsonUtilities.JsonContext.Default.JsonNode,
212-
McpJsonUtilities.JsonContext.Default.PingResult);
213-
}
214-
215206
private void ConfigureInitialize(McpServerOptions options)
216207
{
217208
_requestHandlers.Set(RequestMethods.Initialize,

tests/ModelContextProtocol.Tests/Client/McpClientTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,4 +795,16 @@ public async Task Completion_GracefulDisposal_CompletesWithNoException()
795795
var details = await client.Completion;
796796
Assert.Null(details.Exception);
797797
}
798+
799+
[Fact]
800+
public async Task ServerCanPingClient()
801+
{
802+
await using McpClient client = await CreateMcpClientForServer();
803+
804+
var pingRequest = new JsonRpcRequest { Method = RequestMethods.Ping };
805+
var response = await Server.SendRequestAsync(pingRequest, TestContext.Current.CancellationToken);
806+
807+
Assert.NotNull(response);
808+
Assert.NotNull(response.Result);
809+
}
798810
}

0 commit comments

Comments
 (0)