Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 782b5bad-4046-49ec-93a6-72768b5b7521 Copilot-Session: 4b938335-418c-4ee7-8287-6c70d9148b89
44 lines
No EOL
1.4 KiB
C#
44 lines
No EOL
1.4 KiB
C#
using System.ComponentModel;
|
|
using ModelContextProtocol;
|
|
using ModelContextProtocol.Protocol;
|
|
using ModelContextProtocol.Server;
|
|
|
|
namespace Progress.Tools;
|
|
|
|
[McpServerToolType]
|
|
public class LongRunningTools
|
|
{
|
|
[McpServerTool, Description("Demonstrates a long running tool with progress updates")]
|
|
public static async Task<string> LongRunningTool(
|
|
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; i++)
|
|
{
|
|
await Task.Delay(stepDuration * 1000);
|
|
|
|
// <snippet_SendProgress>
|
|
if (progressToken is not null)
|
|
{
|
|
await server.SendNotificationAsync("notifications/progress", new ProgressNotificationParams
|
|
{
|
|
ProgressToken = progressToken.Value,
|
|
Progress = new ProgressNotificationValue
|
|
{
|
|
Progress = i,
|
|
Total = steps,
|
|
Message = $"Step {i} of {steps} completed.",
|
|
},
|
|
});
|
|
}
|
|
// </snippet_SendProgress>
|
|
}
|
|
|
|
return $"Long running tool completed. Duration: {duration} seconds. Steps: {steps}.";
|
|
}
|
|
} |