Refactor transports to help enable graceful shutdown (#142)
- This also paves the way for better multi-session support - We should definitely rethink names for the transport API - For now, I kept the names similar as possible, so we can focus on the API shape Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
parent
d47c834fa9
commit
2ab9db0878
1 changed files with 2015 additions and 1847 deletions
16
src/ModelContextProtocol/Shared/NotificationHandlers.cs
Normal file
16
src/ModelContextProtocol/Shared/NotificationHandlers.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using ModelContextProtocol.Protocol.Messages;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ModelContextProtocol.Shared;
|
||||
|
||||
internal sealed class NotificationHandlers : ConcurrentDictionary<string, List<Func<JsonRpcNotification, Task>>>
|
||||
{
|
||||
public void Add(string method, Func<JsonRpcNotification, Task> handler)
|
||||
{
|
||||
var handlers = GetOrAdd(method, _ => []);
|
||||
lock (handlers)
|
||||
{
|
||||
handlers.Add(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue