Move notification handler registrations to capabilities (#207)

* Move notification handler registrations to capabilities

Currently request handlers are set on the capability objects, but notification handlers are set after construction via an AddNotificationHandler method on the IMcpEndpoint interface. This moves handler specification to be at construction as well. This makes it more consistent with request handlers, simplifies the IMcpEndpoint interface to just be about message sending, and avoids a concurrency bug that could occur if someone tried to add a handler while the endpoint was processing notifications.

* Address more feedback and further cleanup
This commit is contained in:
Stephen Toub 2025-04-04 13:11:07 -04:00 • committed by GitHub
commit d21d933876
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -129,13 +129,25 @@ public sealed class StdioClientTransport : IClientTransport
}
internal static void DisposeProcess(
Process? process, bool processStarted, ILogger logger, TimeSpan shutdownTimeout, string endpointName)
Process? process, bool processRunning, ILogger logger, TimeSpan shutdownTimeout, string endpointName)
{
if (process is not null)
{
if (processRunning)
{
try
{
processRunning = !process.HasExited;
}
catch
{
processRunning = false;
}
}
try
{
if (processStarted && !process.HasExited)
if (processRunning)
{
// Wait for the process to exit.
// Kill the while process tree because the process may spawn child processes