Add EverythingServer sample (#151)
This commit is contained in:
parent
d21d933876
commit
01410df5ad
1 changed files with 620 additions and 1 deletions
23
samples/EverythingServer/SubscriptionMessageSender.cs
Normal file
23
samples/EverythingServer/SubscriptionMessageSender.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using Microsoft.Extensions.Hosting;
|
||||
using ModelContextProtocol;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
internal class SubscriptionMessageSender(IMcpServer server, HashSet<string> subscriptions) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
foreach (var uri in subscriptions)
|
||||
{
|
||||
await server.SendNotificationAsync("notifications/resource/updated",
|
||||
new
|
||||
{
|
||||
Uri = uri,
|
||||
}, cancellationToken: stoppingToken);
|
||||
}
|
||||
|
||||
await Task.Delay(5000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue