csharp-sdk/samples/EverythingServer/SubscriptionMessageSender.cs
Mike Kistler fb07d666a6
Convert EverythingServer to use Streamable HTTP (#709)
* Convert EverythingServer to use Streamable HTTP

* Apply suggestion from @halter73

Co-authored-by: Stephen Halter <halter73@gmail.com>

---------

Co-authored-by: Stephen Halter <halter73@gmail.com>
2025-10-16 14:39:42 -07:00

23 lines
760 B
C#

using System.Collections.Concurrent;
using ModelContextProtocol;
using ModelContextProtocol.Server;
internal class SubscriptionMessageSender(McpServer server, ConcurrentDictionary<string, byte> subscriptions) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
foreach (var uri in subscriptions.Keys)
{
await server.SendNotificationAsync("notifications/resource/updated",
new
{
Uri = uri,
}, cancellationToken: stoppingToken);
}
await Task.Delay(5000, stoppingToken);
}
}
}