-
Notifications
You must be signed in to change notification settings - Fork 681
Expand file tree
/
Copy pathLongRunningTool.cs
More file actions
38 lines (33 loc) · 1.17 KB
/
LongRunningTool.cs
File metadata and controls
38 lines (33 loc) · 1.17 KB
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;
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(
McpServer server,
RequestContext<CallToolRequestParams> context,
int duration = 10,
int steps = 5)
{
var progressToken = context.Params.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}.";
}
}