Implement MCP task support (SEP-1686) (#1170)

Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
Eirik Tsarpalis 2026-01-28 05:21:02 +02:00 • committed by GitHub
commit 10e4f5b20f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,47 @@
namespace ModelContextProtocol.Server;
/// <summary>
/// Represents the execution context for a task being executed by the server.
/// This context flows with async execution and enables automatic task status updates.
/// </summary>
internal sealed class TaskExecutionContext
{
/// <summary>
/// Gets the AsyncLocal instance used to track the current task execution context.
/// </summary>
private static readonly AsyncLocal<TaskExecutionContext?> s_current = new();
/// <summary>
/// Gets or sets the current task execution context for the executing async flow.
/// </summary>
public static TaskExecutionContext? Current
{
get => s_current.Value;
set => s_current.Value = value;
}
/// <summary>
/// Gets the task ID of the currently executing task.
/// </summary>
public required string TaskId { get; init; }
/// <summary>
/// Gets the session ID associated with the task.
/// </summary>
public string? SessionId { get; init; }
/// <summary>
/// Gets the task store used to persist task state.
/// </summary>
public required IMcpTaskStore TaskStore { get; init; }
/// <summary>
/// Gets whether task status notifications should be sent.
/// </summary>
public bool SendNotifications { get; init; }
/// <summary>
/// Gets or sets the function to call when sending a task status notification.
/// </summary>
public Func<Protocol.McpTask, CancellationToken, Task>? NotifyTaskStatusFunc { get; init; }
}