Table of Contents

Class McpTask

Namespace
ModelContextProtocol.Protocol
Assembly
ModelContextProtocol.Core.dll

Represents an MCP task, which is a durable state machine carrying information about the underlying execution state of a request.

[Experimental("MCPEXP001", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp001")]
public sealed class McpTask
Inheritance
McpTask
Inherited Members

Remarks

Tasks are useful for representing expensive computations and batch processing requests. Each task is uniquely identifiable by a receiver-generated task ID.

Tasks follow a defined lifecycle through the Status property. They begin in the Working status and may transition through various states before reaching a terminal status (Completed, Failed, or Cancelled).

See the tasks specification for details.

Properties

CreatedAt

Gets or sets the ISO 8601 timestamp when the task was created.

[JsonPropertyName("createdAt")]
public required DateTimeOffset CreatedAt { get; set; }

Property Value

DateTimeOffset

Remarks

Receivers must include this timestamp in all task responses to indicate when the task was created.

LastUpdatedAt

Gets or sets the ISO 8601 timestamp when the task status was last updated.

[JsonPropertyName("lastUpdatedAt")]
public required DateTimeOffset LastUpdatedAt { get; set; }

Property Value

DateTimeOffset

Remarks

Receivers must include this timestamp in all task responses to indicate when the task was last updated.

PollInterval

Gets or sets the suggested time between status checks.

[JsonPropertyName("pollInterval")]
[JsonConverter(typeof(TimeSpanMillisecondsConverter))]
public TimeSpan? PollInterval { get; set; }

Property Value

TimeSpan?

Remarks

Requestors should respect this value when provided to avoid excessive polling. This value is optional and may not be present in all task responses.

Status

Gets or sets the current state of the task execution.

[JsonPropertyName("status")]
public required McpTaskStatus Status { get; set; }

Property Value

McpTaskStatus

StatusMessage

Gets or sets an optional human-readable message describing the current state.

[JsonPropertyName("statusMessage")]
public string? StatusMessage { get; set; }

Property Value

string

Remarks

This message can be present for any status, including error details for failed tasks.

TaskId

Gets or sets the unique identifier for the task.

[JsonPropertyName("taskId")]
public required string TaskId { get; set; }

Property Value

string

Remarks

Task IDs are generated by the receiver when creating a task and must be unique among all tasks controlled by that receiver.

TimeToLive

Gets or sets the time to live (retention duration) from creation before the task may be deleted.

[JsonPropertyName("ttl")]
[JsonConverter(typeof(TimeSpanMillisecondsConverter))]
public TimeSpan? TimeToLive { get; set; }

Property Value

TimeSpan?

Remarks

A null value indicates unlimited lifetime. After a task's TTL lifetime has elapsed, receivers may delete the task and its results, regardless of the task status.

Receivers may override the requested TTL duration and must include the actual TTL duration (or null for unlimited) in task responses.