forked from modelcontextprotocol/csharp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLongRunningTool.cs
38 lines (33 loc) · 1.18 KB
/
LongRunningTool.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using ModelContextProtocol;
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}.";
}
}