Add EverythingServer sample (#151)
This commit is contained in:
parent
d21d933876
commit
01410df5ad
1 changed files with 620 additions and 1 deletions
39
samples/EverythingServer/Tools/LongRunningTool.cs
Normal file
39
samples/EverythingServer/Tools/LongRunningTool.cs
Normal 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}.";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue