Add EverythingServer sample (#151)

This commit is contained in:
Aaron Powell 2025-04-05 05:48:53 +11:00 • committed by GitHub
commit 01410df5ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,39 @@
using ModelContextProtocol;
using ModelContextProtocol.Protocol.Messages;
using ModelContextProtocol.Protocol.Types;
using ModelContextProtocol.Server;
using System.ComponentModel;
namespace EverythingServer.Tools;
[McpServerToolType]
public class LongRunningTool
{
[McpServerTool(Name = "longRunningOperation"), Description("Demonstrates a long running operation with progress updates")]
public static async Task<string> LongRunningOperation(
IMcpServer server,
RequestContext<CallToolRequestParams> context,
int duration = 10,
int steps = 5)
{
var progressToken = context.Params?.Meta?.ProgressToken;
var stepDuration = duration / steps;
for (int i = 1; i <= steps + 1; i++)
{
await Task.Delay(stepDuration * 1000);
if (progressToken is not null)
{
await server.SendNotificationAsync("notifications/progress", new
{
Progress = i,
Total = steps,
progressToken
});
}
}
return $"Long running operation completed. Duration: {duration} seconds. Steps: {steps}.";
}
}